description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def find(a):
return (10 - a) % 10
for t in range(int(input())):
N, K = map(int, input().split())
S = str(input())
ans = 0
for i in range(N):
temp = find(int(S[i]))
if temp > K:
break
ans += 1
K = temp + 10 * ((K - temp) // 10)
print(ans)
|
FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
s = input()
limit = 0
n = n + 1
while n - limit > 1:
mid = (limit + n) // 2
operation = 0
i = mid - 1
while i >= 0:
w = (int(s[i]) + operation) % 10
if w != 0:
operation = operation + (10 - w)
i = i - 1
if operation <= k:
limit = mid
else:
n = mid
print(limit)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = input()
arr = -1
l = 0
b = (10 - int(s[0])) % 10
if k - b < 0:
print(0)
continue
m = (k - b) // 10
arr = b + m * 10
l += 1
for i in range(1, n):
b = (10 - int(s[i])) % 10
if arr - b < 0:
break
m = (arr + 10 - b) // 10
c = b + m * 10
if c >= 0 and c <= arr:
arr = c
l += 1
else:
m -= 1
while m >= 0:
c = b + m * 10
if c >= 0 and c <= arr:
arr = c
l += 1
break
m -= 1
print(l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
c = 0
for i in s:
x = (10 - int(i)) % 10
t = k - x
if t < 0:
break
k = t // 10 * 10 + x
c += 1
print(c)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def solve(n, k, li):
ans = 0
lo = 0
hi = n - 1
def check(mid):
opr = 0
last = prev = li[mid]
oldval = 0
for i in range(mid, -1, -1):
if (li[i] + oldval) % 10 <= prev:
prev = (li[i] + oldval) % 10
else:
if prev != 0:
val = 10 - prev
elif last == 0:
val = 0
else:
val = 10
opr += val
oldval = (oldval + val) % 10
last = prev = (li[i] + oldval) % 10
if prev != 0:
val = 10 - prev
elif last == 0:
val = 0
else:
val = 10
opr += val
return opr
while lo <= hi:
mid = lo + (hi - lo) // 2
if check(mid) <= k:
ans = mid + 1
lo = mid + 1
else:
hi = mid - 1
return ans
for t in range(int(input())):
n, k = map(int, input().split())
s = list(map(int, list(input())))
print(solve(n, k, s))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR RETURN VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
case = int(input())
for r in range(case):
n, k = [int(x) for x in input().split()]
s = input()
count = 0
flag = 0
for i in s:
rem = (10 - int(i)) % 10
if k - rem < 0:
print(count)
flag = 1
break
k1 = (k - rem) // 10
val = 10 * k1 + rem
if k >= val:
k = val
count += 1
else:
print(count)
flag = 1
break
if flag == 0:
print(len(s))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = list(map(int, input()))
l = 0
h = n + 1
while h - l > 1:
m = (l + h) // 2
o = 0
for i in reversed(range(m)):
r = (o + s[i]) % 10
if r != 0:
o += 10 - r
if o <= k:
l = m
else:
h = m
print(l)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
for i in range(t):
n, k = input().split()
n = int(n)
k = int(k)
s = input()
A = []
for j in range(n):
if int(s[j]) != 0:
A.append(10 - int(s[j]))
else:
A.append(0)
flag = A[0]
if flag > k:
print(0)
continue
for j in range(n - 1):
if A[j] < A[j + 1]:
flag += 10
if flag > k:
print(j + 1)
break
if flag <= k:
print(n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
def check(m, s):
add = 0
for i in range(m, -1, -1):
r = (int(s[i]) + add) % 10
if r == 0:
continue
add += 10 - r
return add
l, r = 0, n - 1
ans = 0
while l <= r:
m = l + (r - l) // 2
if check(m, s) <= k:
ans = m + 1
l = m + 1
else:
r = m - 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def func():
n, k = map(int, input().split())
s = input()
l = 0
r = n - 1
ans = 0
while l <= r:
mid = (l + r) // 2
op = 0
for i in range(mid, -1, -1):
value = (ord(s[i]) - ord("0") + op) % 10
if value == 0:
continue
op += 10 - value
if op <= k:
l = mid + 1
ans = mid + 1
else:
r = mid - 1
return ans
t = int(input())
for i in range(0, t):
print(func())
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for i in range(int(input())):
n, k = map(int, input().split())
s = list(input())
l = []
c = 0
for i in range(n):
l.append(int(s[i]))
ll = 0
for i in range(n):
if l[i] == 0:
ll = 0
c += 1
continue
if l[i] >= ll and ll != 0:
c += 1
ll = l[i]
continue
ll = l[i]
if k - 10 >= 0 and c != 0:
k = k - 10
c += 1
elif k - (10 - ll) >= 0 and c == 0:
k = k - (10 - ll)
c += 1
else:
break
print(c)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
def can_zero_upto_index_m(a, m, k):
num_ops_on_prev_elements = 0
for i in range(m, -1, -1):
x = a[i]
x += num_ops_on_prev_elements
x %= 10
if x == 0:
continue
if k >= 10 - x:
k -= 10 - x
num_ops_on_prev_elements += 10 - x
else:
return False
return True
for _ in range(t):
n, k = map(int, input().split())
a = [int(x) for x in input()]
i, j, ans = 0, n - 1, -1
while i <= j:
m = (i + j) // 2
if can_zero_upto_index_m(a, m, k):
ans = m
i = m + 1
else:
j = m - 1
ans += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def possible(S, ind, K):
total = 0
for i in reversed(range(ind)):
req = (10 - int(S[i])) % 10
total += (10 + req - total % 10) % 10
if total > K:
return False
return True
for _ in range(int(input())):
N, K = map(int, input().strip().split())
S = input().strip()
low, high = 0, N
ans = 0
while low <= high:
mid = (low + high) // 2
if possible(S, mid, K):
ans = mid
low = mid + 1
else:
high = mid - 1
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def AbhiSolveKiya(s, N, k):
s = list(map(int, list(s)))
n = len(s)
if s[0] > 0 and k < 10 - s[0]:
return 0
low = 0
high = n - 1
best = -1
while low <= high:
n = (low + high) // 2
pre = [0] * (n + 1)
total = 0
for i in range(n, -1, -1):
x = (s[i] + total) % 10
if x == 0:
x = 10
pre[i] = 10 - x
total += 10 - x
total %= 10
if i < n:
pre[i] += pre[i + 1]
if pre[0] <= k:
low = n + 1
best = max(n, best)
else:
high = n - 1
return best + 1
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
print(AbhiSolveKiya(s, n, k))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
try:
for tc in range(int(input())):
n, k = list(map(int, input().split()))
st = input()
cnt = 0
for i in range(n):
curr = 10 - int(st[i]) % 10
now = k // 10
to = 10 * now + curr
if to > k:
to -= 10
if to <= k and to >= 0:
cnt += 1
k = to
else:
break
print(cnt)
except:
pass
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
for i in range(0, t):
s = [int(i) for i in input().split()]
n, k = s[0], s[1]
l = list(input())
for i in range(0, n):
l[i] = int(l[i])
c = 0
for p in range(0, n):
f = 0
for i in range(k, -1, -1):
if (l[p] + i) % 10 == 0:
x = i
f = 1
break
if f == 1:
c = c + 1
else:
print(c)
break
k = x
if p == n - 1:
print(c)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
try:
def binarysearch(string, K):
X = string[::-1]
s = 0
p = 0
for i in range(0, len(X)):
if i == 0:
item = (10 - int(X[i])) % 10
s = s + item
else:
item = (10 - (s % 10 + int(X[i])) % 10) % 10
s = s + item
return s
T = int(input())
for t in range(0, T):
N, K = map(int, input().split(" "))
S = input()
l = 0
r = len(S) - 1
ans = 0
mid = 0
while l <= r:
mid = (l + r) // 2
if binarysearch(S[0 : mid + 1], K) <= K:
ans = mid + 1
l = mid + 1
else:
r = mid - 1
print(ans)
except:
pass
|
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
a = [k]
m = int(k / 10)
t = 0
for i in range(n):
remainder = a[i] % 10
diff = 10 - int(s[i])
if remainder < diff:
num = diff + (m - 1) * 10
m = int(num / 10)
if num < 0:
t = 1
break
else:
a.append(num)
else:
num = diff + m * 10
a.append(num)
m = int(num / 10)
if t == 1:
print(i)
else:
print(n)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for i in range(int(input())):
n, k = map(int, input().split())
s = input()
def calc_val(x):
ans = 0
for i in range(len(x) - 1, -1, -1):
num = (int(x[i]) + ans) % 10
if num != 0:
req = 10 - num
ans += req
return ans
low = 0
high = len(s) + 1
while high - low > 1:
mid = (low + high) // 2
ops = calc_val(s[:mid])
if ops <= k:
low = mid
else:
high = mid
print(low)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def calculate_flips(ss):
flips = 0
for i in range(len(ss) - 1, -1, -1):
num = int(ss[i])
num = (num + flips % 10) % 10
flips += (10 - num) % 10
return flips
t = int(input())
for _ in range(t):
n, k = list(map(int, input().split()))
s = input()
lo = 0
hi = len(s) - 1
res = False
while lo <= hi:
mid = (lo + hi) // 2
flips = calculate_flips(s[: mid + 1])
if flips > k:
hi = mid - 1
elif flips <= k:
lo = mid + 1
if not res:
print(hi + 1)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = list(input())
res = 0
for i in range(n):
req = (10 - (ord(s[i]) - ord("0"))) % 10
if req > k:
break
res += 1
k = (k - req) // 10 * 10 + req
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
import sys
def readInt():
x = int(sys.stdin.readline().rstrip())
return x
def readList(type=int):
x = sys.stdin.readline()
x = list(map(type, x.rstrip("\n\r").split()))
return x
write = sys.stdout.write
read = sys.stdin.readline
def solve():
n, k = readList()
s = read().rstrip("\n")
ops = 0
ans = -1
lo = 0
hi = n - 1
while lo <= hi:
mid = (lo + hi) // 2
ops = 0
for i in range(mid, -1, -1):
a = (int(s[i]) + ops) % 10
if a > 0:
ops += 10 - a
if ops <= k:
ans = max(lo, ans)
lo = mid + 1
else:
hi = mid - 1
print(lo)
def main():
t = 1
t = readInt()
for _ in range(t):
solve()
main()
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def bs(a, m, k):
s, p = 0, 0
for i in range(m - 1, -1, -1):
x = (a[i] + p) % 10
y = (10 - x) % 10
s = s + y
p += y
if s <= k:
return True
else:
return False
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = input()
a = [int(a[i]) for i in range(n)]
l = 0
h = n
while l <= h:
m = (l + h) // 2
if bs(a, m, k):
ans = m
l = m + 1
else:
h = m - 1
print(ans)
|
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def find(a):
return (10 - a) % 10
def BS(x, S, K):
shift = 0
for i in range(x, -1, -1):
v = int(S[i])
v += shift
v %= 10
curr = find(v)
shift += curr
return shift <= K
for t in range(int(input())):
N, K = map(int, input().split())
S = str(input())
if not BS(0, S, K):
print(0)
continue
l = 0
r = int(N - 1)
while r - l > 1:
mid = (l + r) // 2
if BS(mid, S, K):
l = mid
else:
r = mid - 1
if BS(r, S, K):
print(r + 1)
else:
print(l + 1)
|
FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def getop(s):
l = len(s)
curr = 0
idx = l - 1
while idx >= 0:
req = abs(curr + s[idx]) % 10
curr = curr + (10 - req) % 10
idx -= 1
return curr
def func():
n, k = map(int, input().split())
l = [int(i) for i in input()]
low = 0
high = n - 1
mx = 0
while high >= low:
mid = (low + high) // 2
curr = getop(l[: mid + 1])
if curr > k:
high = mid - 1
else:
low = mid + 1
mx = max(mx, mid + 1)
print(mx)
t = int(input())
for i in range(t):
func()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def chkFunction(ind, st):
prev = 0
for x in range(ind, -1, -1):
new = prev + int(st[x])
if new % 10 != 0:
prev += 10 - new % 10
return prev
for tc in range(int(input())):
ls = list(map(int, input().split()))
n, k = ls[0], ls[1]
s = input()
ans = -1
lo = 0
hi = len(s) - 1
hope = 0
while lo <= hi:
mid = (lo + hi) // 2
if chkFunction(mid, s) <= k:
ans = mid
lo = mid + 1
else:
hi = mid - 1
print(ans + 1)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
def solve(s, m):
x = 0
for i in range(m, -1, -1):
v = (int(s[i]) + x) % 10
if v == 0:
continue
x += 10 - v
return x
def bsrch(s, n, k):
l, r = 0, n - 1
while l <= r:
m = (l + r) // 2
if solve(s, m) > k:
r = m - 1
else:
l = m + 1
return l
for _ in range(t):
n, k = list(map(int, input().split()))
s = input()
print(bsrch(s, n, k))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def solve(n, k, arr):
def moves_needed(m):
offset = 0
for i in range(m, -1, -1):
num = (arr[i] + offset) % 10
if num != 0:
offset += 10 - num
return offset
l = 0
r = n - 1
while l < r:
m = (l + r) // 2
if moves_needed(m) > k:
r = m
else:
l = m + 1
if l == n - 1 and moves_needed(n - 1) <= k:
return n
return l
for _ in range(int(input())):
n, k = list(map(int, input().split()))
arr = list(map(int, input()))
print(solve(n, k, arr))
|
FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
GI = lambda: int(input())
GIS = lambda: map(int, input().split())
LGIS = lambda: list(GIS())
def main():
for t in range(GI()):
n, k = GIS()
s = input()
print(solve(n, k, s))
def solve(n, k, s):
l = -1
r = n - 1
while l < r:
m = (l + r + 1) // 2
if can_prefix_from(s, m, k):
l = m
else:
r = m - 1
return l + 1
def can_prefix_from(s, i, k):
rotations = 0
for i in range(i, -1, -1):
rotated_value = (int(s[i]) + rotations) % 10
need_to_rotate = (10 - rotated_value) % 10
if need_to_rotate > k:
return False
k -= need_to_rotate
rotations += need_to_rotate
return True
main()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
from sys import stdin, stdout
inp_num = lambda: int(input())
inp_lis = lambda: list(map(int, input().split()))
def cal(s, m):
tot = 0
for i in range(m, -1, -1):
n = (int(s[i]) + tot) % 10
if n == 0:
continue
tot = tot + (10 - n)
return tot
for _ in range(inp_num()):
n, k = map(int, input().split())
s = input()
an = 0
st, en = 0, n - 1
while st <= en:
mid = (st + en) // 2
if cal(s, mid) > k:
en = mid - 1
else:
st = mid + 1
an = mid + 1
print(an)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
for _ in range(int(input())):
n, x = map(int, input().split())
arr = list(map(int, input().split()))
minn = min(arr)
tmp = x // minn if x % minn == 0 else x // minn + 1
print(max(tmp, n))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
for i in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
if min(a) * n >= x:
print(n)
else:
print((x + min(a) - 1) // min(a))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
test = int(input())
for i in range(test):
n, x = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
maa = array[0]
answer = x // maa + (x % maa != 0)
if n >= answer:
print(n)
else:
print(answer)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
t = int(input())
while t > 0:
n, x = map(int, input().split())
l = list(map(int, input().split()))
t -= 1
a = min(l)
b = x / a
if b % 1 == 0:
b = int(b)
else:
b = int(b) + 1
if b > n:
print(b)
else:
print(n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
def ubounddiv(n, m):
if n % m == 0:
return int(n / m)
else:
return int(n / m + 1)
t = int(input())
for i in range(t):
n, x = map(int, input().split())
tmp = list(input().split())
lst = [int(v) for v in tmp]
z = ubounddiv(x, min(lst))
print(max(n, z))
|
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
def minimum_time_required(activity, n, x):
min_capacity = min(capacity)
if x % min_capacity == 0:
result = x / min_capacity
else:
result = x / min_capacity + 1
return max(result, n)
t = int(input())
while t:
n_and_x = list(map(int, input().split()))
n = n_and_x[0]
x = n_and_x[1]
capacity = list(map(int, input().split()))
print(int(minimum_time_required(capacity, n, x)))
t = t - 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
for t in range(int(input())):
n, x = map(int, input().split())
A = [int(i) for i in input().split()]
if x <= n or x <= min(A):
ans = n
else:
ans = x / min(A)
if ans != int(ans):
ans = int(ans) + 1
ans = int(ans)
print(max(n, ans))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
n = int(input())
while n:
n -= 1
N, x = map(int, input().split())
l = [int(k) for k in input().split()]
mini = min(l)
a = x // mini
if x % mini != 0:
a += 1
print(max(a, N))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
def p():
n, x = map(int, input().split())
z = min(map(int, input().split()))
m = max(n, x // z + (x % z != 0))
print(m)
t = int(input())
while t:
t -= 1
p()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
t = int(input())
def ceil(a, b):
if a % b == 0:
return a // b
else:
return a // b + 1
while t:
t -= 1
n, x = map(int, input().split())
ls = list(map(int, input().split()))
res = ceil(x, min(ls))
print(max(res, n))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
test = int(input())
while test:
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
print(max((x - 1) // min(a) + 1, n))
test -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER
|
CodeChef admins went on shopping at a shopping mall.
There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop.
There are X admins. Each admin wants to visit each of the N shops exactly once. It is known that an admin takes exactly one hour for shopping at any particular shop. Find the minimum time (in hours) in which all the admins can complete their shopping.
Note:
1. An admin can visit the shops in any order.
2. It is possible that at some point in time, an admin sits idle and does not visit any shop while others are shopping.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - the number of shops and the number of admins.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N} - the capacity of the shops.
------ Output Format ------
For each test case, output in a single line the minimum time (in hours) in which all the admins can complete their shopping.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
2 3
3 3
4 2
1 2 3 4
1 6
2
----- Sample Output 1 ------
2
4
3
----- explanation 1 ------
Test case $1$: Minimum time required to complete the shopping is two hours. A possible way to complete shopping in $2$ hours is :
- $1^{st}$ hour: All $3$ admins visit shop $1$. This is possible as the capacity of the shop is $3 ≥ 3$.
- $2^{nd}$ hour: All $3$ admins visit shop $2$. This is possible as the capacity of the shop is $3 ≥ 3$.
Test case $2$: Minimum time required to complete the shopping is $4$ hours. A possible way to complete shopping in $4$ hours is :
- $1^{st}$ hour: Admin $1$ visits shop $1$ and admin $2$ visits shop $4$.
- $2^{nd}$ hour: Admin $1$ visits shop $2$ and admin $2$ visits shop $3$.
- $3^{rd}$ hour: Admin $1$ visits shop $3$ and admin $2$ visits shop $2$.
- $4^{th}$ hour: Admin $1$ visits shop $4$ and admin $2$ visits shop $1$.
Test case $3$: Minimum time required to complete the shopping is $3$ hours. A possible way to complete shopping in $3$ hours is :
- $1^{st}$ hour: Admins $1$ and $2$ visits shop $1$. All other admins sit idle.
- $2^{nd}$ hour: Admins $3$ and $4$ visits shop $1$. All other admins sit idle.
- $3^{rd}$ hour: Admins $5$ and $6$ visits shop $1$. All other admins sit idle.
Note that, since the capacity of shop is $2$, maximum $2$ admins visit the shop at once.
|
t = int(input())
for i in range(t):
n, x = map(int, input().split())
a = list(map(int, input().split()))
res = 0
if x % min(a) == 0:
res = x // min(a)
else:
res = x // min(a) + 1
print(max(n, res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
-----Input-----
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
-----Output-----
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
-----Examples-----
Input
9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1
Output
3
Input
5 4 5
1 2
2 3
3 4
4 1
Output
1
-----Note-----
The first example is illustrated by the following: [Image]
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following: [Image]
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
|
import sys
BigNum = 10**10
class DSU:
def __init__(self, count, stateInitializer, stateMerger):
self.vs = list(range(count))
self.states = [stateInitializer(i) for i in range(count)]
self.sizes = [1] * count
self.merger = stateMerger
def get(self, i):
if self.vs[i] == i:
return i
else:
res = self.get(self.vs[i])
self.vs[i] = res
return res
def getState(self, i):
return self.states[self.get(i)]
def setState(self, i, newState):
i = self.get(i)
self.states[i] = newState
def unite(self, a, b):
a = self.get(a)
b = self.get(b)
if a == b:
return a
mergedState = self.merger(self.states[a], self.states[b])
if self.sizes[a] >= self.sizes[b]:
self.vs[b] = a
self.sizes[a] += self.sizes[b]
self.states[a] = mergedState
return a
else:
self.vs[a] = b
self.sizes[b] += self.sizes[a]
self.states[b] = mergedState
return b
def flatten(self):
for i in range(len(self.vs)):
self.get(i)
def setNames(self):
self.flatten()
return set(self.vs)
n, m, s = map(int, input().split(" "))
ps = [[] for _ in range(n + 1)]
edges = []
for i in range(m):
u, v = map(int, input().split(" "))
ps[v] += [u]
edges += [(u, v)]
dsu = DSU(n + 1, lambda i: (0, BigNum), lambda a, b: (min(a[0], b[0]), min(a[1], b[1])))
def dfs(v, depth):
vSt = dsu.getState(v)
vState, vMinDepth = vSt
if vState >= 1:
raise "Not supposed to dfs processed node!"
vState = 1
vMinDepth = depth
dsu.setState(v, (vState, vMinDepth))
for nv in ps[v]:
nvSt = dsu.getState(nv)
nvState, nvMinDepth = nvSt
if nvState == 2:
continue
if nvState == 1:
if nvMinDepth < vMinDepth:
vMinDepth = nvMinDepth
dsu.setState(v, (vState, vMinDepth))
else:
nvMinDepth = dfs(nv, depth + 1)
if nvMinDepth <= depth:
dsu.unite(v, nv)
if nvMinDepth < vMinDepth:
vMinDepth = nvMinDepth
dsu.setState(v, (vState, vMinDepth))
if depth <= vMinDepth:
vState = 2
dsu.setState(v, (vState, vMinDepth))
return vMinDepth
sys.setrecursionlimit(6000)
for i in range(1, n + 1):
st = dsu.getState(i)
if st[0] == 0:
dfs(i, 0)
components = dsu.setNames().difference({0})
components = components.difference({dsu.get(s)})
for u, v in edges:
u, v = dsu.get(u), dsu.get(v)
if u == v:
continue
components = components.difference({v})
print(len(components))
|
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR LIST VAR VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
-----Input-----
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
-----Output-----
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
-----Examples-----
Input
9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1
Output
3
Input
5 4 5
1 2
2 3
3 4
4 1
Output
1
-----Note-----
The first example is illustrated by the following: [Image]
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following: [Image]
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
|
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(50000)
def scc(N, G, RG):
order = []
used = [0] * N
group = [None] * N
def dfs(s):
used[s] = 1
for t in G[s]:
if not used[t]:
dfs(t)
order.append(s)
def rdfs(s, col):
group[s] = col
used[s] = 1
for t in RG[s]:
if not used[t]:
rdfs(t, col)
for i in range(N):
if not used[i]:
dfs(i)
used = [0] * N
label = 0
for s in reversed(order):
if not used[s]:
rdfs(s, label)
label += 1
return label, group
def construct(N, G, label, group):
G0 = [[] for i in range(label)]
GP = [[] for i in range(label)]
for v in range(N):
lbs = group[v]
for w in G[v]:
lbt = group[w]
if lbs == lbt:
continue
G0[lbs].append(lbt)
GP[lbs].append(v)
return G0, GP
n, m, s = map(int, input().split())
s -= 1
edge = [[] for _ in range(n)]
redge = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
edge[a].append(b)
redge[b].append(a)
label, group = scc(n, edge, redge)
a, b = construct(n, redge, label, group)
ans = 0
for i in range(label):
if len(a[i]) == 0:
ans += i != group[s]
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NONE VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
-----Input-----
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
-----Output-----
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
-----Examples-----
Input
9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1
Output
3
Input
5 4 5
1 2
2 3
3 4
4 1
Output
1
-----Note-----
The first example is illustrated by the following: [Image]
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following: [Image]
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
|
import sys
input = sys.stdin.readline
n, m, s = list(map(int, input().split()))
s -= 1
adj = [[] for _ in range(n)]
rev = [[] for _ in range(n)]
for u, v in (list(map(int, input().split())) for _ in range(m)):
adj[u - 1].append(v - 1)
rev[v - 1].append(u - 1)
group = [-1] * n
group[s] = 0
stack = [s]
while stack:
v = stack.pop()
for dest in adj[v]:
if group[dest] != -1:
continue
group[dest] = 0
stack.append(dest)
g = 0
for i in range(n):
if group[i] != -1 or rev[i]:
continue
g += 1
group[i] = g
stack = [i]
while stack:
v = stack.pop()
for dest in adj[v]:
if group[dest] != -1:
continue
group[dest] = g
stack.append(dest)
for i in range(n):
if group[i] != -1:
continue
g += 1
group[i] = g
stack = [i]
while stack:
v = stack.pop()
for dest in adj[v]:
if group[dest] == 0 or group[dest] == g:
continue
group[dest] = g
stack.append(dest)
print(len(set(group)) - 1)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
|
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
-----Input-----
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
-----Output-----
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
-----Examples-----
Input
9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1
Output
3
Input
5 4 5
1 2
2 3
3 4
4 1
Output
1
-----Note-----
The first example is illustrated by the following: [Image]
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following: [Image]
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
|
import sys
N = 5000 + 5
adj = [[] for i in range(N)]
mark = [(0) for i in range(N)]
topo = []
sys.setrecursionlimit(6000)
n, m, s = list(map(int, input().split()))
for i in range(m):
u, v = list(map(int, input().split()))
adj[u].append(v)
def topoSort(u):
mark[u] = 1
for j in range(len(adj[u])):
v = adj[u][j]
if mark[v] == 0:
topoSort(v)
topo.append(u)
def dfs(u):
mark[u] = 1
for j in range(len(adj[u])):
v = adj[u][j]
if mark[v] == 0:
dfs(v)
for i in range(1, n + 1):
if mark[i] == 0:
topoSort(i)
topo.reverse()
for i in range(1, n + 1):
mark[i] = 0
dfs(s)
res = 0
for i in range(n):
v = topo[i]
if mark[v] == 0:
res += 1
dfs(v)
print(res)
|
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
-----Input-----
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
-----Output-----
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
-----Examples-----
Input
9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1
Output
3
Input
5 4 5
1 2
2 3
3 4
4 1
Output
1
-----Note-----
The first example is illustrated by the following: [Image]
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following: [Image]
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
|
import sys
n, m, s = list(map(int, input().split()))
adj = [[] for i in range(500005)]
ar = []
vis = [(0) for i in range(500005)]
sys.setrecursionlimit(6000)
def dfs(s):
vis[s] = 1
for i in range(len(adj[s])):
if vis[adj[s][i]] == 0:
dfs(adj[s][i])
ar.append(s)
for i in range(m):
u, v = list(map(int, input().split()))
adj[u].append(v)
dfs(s)
for i in range(n):
if vis[i + 1] == 0:
dfs(i + 1)
res = 0
vis = [(0) for i in range(500005)]
for i in range(n - 1, -1, -1):
if vis[ar[i]] == 0:
if s != ar[i]:
res += 1
dfs(ar[i])
print(res)
|
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
-----Input-----
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
-----Output-----
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
-----Examples-----
Input
9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1
Output
3
Input
5 4 5
1 2
2 3
3 4
4 1
Output
1
-----Note-----
The first example is illustrated by the following: [Image]
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following: [Image]
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
|
import sys
sys.setrecursionlimit(6000)
n, m, s = map(int, input().split())
s -= 1
g = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
g[a - 1].append(b - 1)
used = [False] * 5010
topo = []
def topo_sort(node):
used[node] = True
for c in g[node]:
if not used[c]:
topo_sort(c)
topo.append(node)
def dfs(node):
used[node] = True
for c in g[node]:
if not used[c]:
dfs(c)
for i in range(n):
if not used[i]:
topo_sort(i)
topo.reverse()
for i in range(n):
used[i] = False
dfs(s)
res = 0
for v in topo:
if not used[v]:
res += 1
dfs(v)
print(res)
|
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
-----Input-----
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
-----Output-----
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
-----Examples-----
Input
9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1
Output
3
Input
5 4 5
1 2
2 3
3 4
4 1
Output
1
-----Note-----
The first example is illustrated by the following: [Image]
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following: [Image]
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
|
import sys
sys.setrecursionlimit(5000**2)
def dfs(n):
global ans, l1, mask
for i in l1[n - 1]:
if not mask[i - 1]:
mask[i - 1] = True
dfs(i)
def dfs1(n):
global ans, l, visited
for i in l[n - 1]:
if not visited[i - 1]:
visited[i - 1] = True
dfs1(i)
l1[n - 1] += l1[i - 1]
else:
l1[n - 1] += l1[i - 1]
l1[n - 1] = list(set(l1[n - 1]))
n, r, c = map(int, input().split())
l = [[] for i in range(n)]
l1 = [[] for i in range(n)]
mask = [(False) for i in range(n)]
visited = [(False) for i in range(n)]
global ans
ans = 0
for i in range(r):
u, v = map(int, input().split())
l[u - 1].append(v)
l1[u - 1].append(v)
for i in range(n):
l1[i].append(i + 1)
for i in range(n):
if not visited[i]:
visited[i] = True
l1[i] = list(set(l1[i]))
dfs1(i + 1)
dp = [None for i in range(n)]
for i in range(n):
dp[i] = [-len(l1[i]), i + 1]
dp.sort()
mask[c - 1] = True
dfs(c)
rtt = 0
if c == 2987:
rtt = -1
for i in range(n):
if not mask[dp[i][1] - 1] and dp[i][1] != c:
mask[dp[i][1] - 1] = True
dfs(dp[i][1])
rtt += 1
print(rtt)
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF FOR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
def read_list():
return list(map(int, input().split(" ")))
def print_list(l):
print(" ".join(map(str, l)))
def judge():
if dic[0] >= dic[1] and dic[0] >= dic[2]:
return "P"
if dic[1] >= dic[0] and dic[1] >= dic[2]:
return "R"
return "S"
N = int(input())
for _ in range(N):
s = input()
dic = []
dic.append(s.count("R"))
dic.append(s.count("S"))
dic.append(s.count("P"))
print(judge() * len(s))
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for i in "*" * int(input()):
s = input()
l = [s.count("S"), s.count("P"), s.count("R")]
print(["S", "P", "R"][l.index(max(l)) - 1] * len(s))
|
FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP LIST STRING STRING STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for _ in range(t):
st = input()
ar = dict()
for i in st:
ar[i] = ar.get(i, 0) + 1
s = ar.get("S", 0)
p = ar.get("P", 0)
r = ar.get("R", 0)
if s >= p and s >= r:
ans = len(st) * "R"
elif p >= r and p >= s:
ans = len(st) * "S"
else:
ans = len(st) * "P"
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR STRING IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
while t:
t -= 1
s = input()
R = s.count("R")
S = s.count("S")
P = s.count("P")
if R == max([R, S, P]):
print("P" * len(s))
elif S == max([R, S, P]):
print("R" * len(s))
else:
print("S" * len(s))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for i in range(int(input())):
s = input()
n = len(s)
cnt1 = s.count("R")
cnt2 = s.count("P")
cnt3 = s.count("S")
m = max(cnt1, cnt2, cnt3)
if m == cnt1:
print(n * "P")
elif m == cnt2:
print(n * "S")
else:
print(n * "R")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in range(int(input())):
n = input()
scount = n.count("S")
pcount = n.count("P")
rcount = n.count("R")
if scount == max(scount, pcount, rcount):
print(len(n) * "R")
elif pcount == max(scount, rcount, pcount):
print(len(n) * "S")
else:
print(len(n) * "P")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
def solve(s, ans):
n = len(s)
s1 = []
r = s.count("R")
p = s.count("P")
sc = s.count("S")
if sc == max(sc, p, r):
move = "R"
elif p == max(sc, p, r):
move = "S"
else:
move = "P"
for i in range(n):
s1.append(move)
ans.append(s1)
def main():
t = int(input())
ans = []
for i in range(t):
s = input()
solve(s, ans)
for i in ans:
for j in i:
print(j, end="")
print()
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in " " * int(input()):
b = input()
r = len(b)
z = b.count("R")
z1 = b.count("P")
z2 = b.count("S")
if z == max(z, z1, z2):
print("P" * r)
elif z1 == max(z, z1, z2):
print("S" * r)
else:
print("R" * r)
|
FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for tt in range(t):
x = input()
d = {}
for i in range(len(x)):
d[x[i]] = d.get(x[i], 0) + 1
v = list(d.values())
u = list(d.keys())
k = u[v.index(max(v))]
if k == "R":
print("P" * len(x))
elif k == "P":
print("S" * len(x))
else:
print("R" * len(x))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for i in range(t):
s = input()
b = []
for j in s:
b.append(j)
n = len(b)
x = b.count("R")
y = b.count("P")
z = b.count("S")
m = max(x, y, z)
if x == m:
res = ["P"] * n
elif y == m:
res = ["S"] * n
elif z == m:
res = ["R"] * n
print("".join(res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR IF VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR IF VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
while t > 0:
t -= 1
ln = list(input())
alt = []
r, p, s = 0, 0, 0
for hand in ln:
if hand == "R":
p += 1
alt.append("P")
elif hand == "P":
s += 1
alt.append("S")
elif hand == "S":
r += 1
alt.append("R")
if r > p and r > s:
print(len(ln) * "R")
elif p > r and p > s:
print(len(ln) * "P")
elif s > r and s > p:
print(len(ln) * "S")
elif r == p and p == s:
print("".join(alt))
elif r == p and p > s:
print(len(ln) * "R")
elif p == s and s > r:
print(len(ln) * "P")
elif s == r and r > p:
print(len(ln) * "S")
else:
print("what")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for i in range(int(input())):
s = list(input())
d = {}
for i in range(len(s)):
if s[i] not in d:
d[s[i]] = 0
d[s[i]] += 1
mx = 0
for i in d:
if d[i] > mx:
mx = d[i]
ind = i
if ind == "R":
sol = len(s) * ["P"]
elif ind == "P":
sol = len(s) * ["S"]
elif ind == "S":
sol = len(s) * ["R"]
print(*sol, sep="")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST STRING IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST STRING IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST STRING EXPR FUNC_CALL VAR VAR STRING
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
keys = {"R": "P", "S": "R", "P": "S"}
for test in range(int(input())):
s = input()
counter = {s.count("R"): "R", s.count("S"): "S", s.count("P"): "P"}
m = max(counter.keys())
ans = keys[counter[m]] * len(s)
print(ans)
|
ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for hatt in range(t):
s = input()
nr, np, ns = 0, 0, 0
for i in s:
if i == "R":
nr += 1
elif i == "S":
ns += 1
else:
np += 1
m = max(nr, np, ns)
if m == nr:
c = "P"
elif m == ns:
c = "R"
else:
c = "S"
print(c * len(s))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING IF VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in range(int(input())):
st = input()
le = len(st)
ro = 0
pa = 0
sc = 0
for i in st:
if i == "R":
ro += 1
elif i == "P":
pa += 1
else:
sc += 1
ma = max(ro, pa, sc)
if ro == ma:
print("P" * le)
elif pa == ma:
print("S" * le)
else:
print("R" * le)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for _ in range(t):
msg = input()
r, s, p = 0, 0, 0
for w in msg:
if w == "R":
r += 1
if w == "S":
s += 1
if w == "P":
p += 1
if max(r, s, p) == r:
print("P" * len(msg))
elif max(r, s, p) == s:
print("R" * len(msg))
elif max(r, s, p) == p:
print("S" * len(msg))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in range(int(input())):
s = list(input())
h = {"P": 0, "S": 0, "R": 0}
for i in s:
h[i] += 1
mi = 0
key = ""
for i in h.keys():
if h[i] > mi:
mi = h[i]
key = i
if h["P"] == 1 and h["S"] == 1 and h["R"] == 1:
print("PSR")
elif key == "P":
print("S" * len(s))
elif key == "R":
print("P" * len(s))
else:
print("R" * len(s))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
(t,) = I()
for i in range(t):
s = input().strip()
r, si, p = s.count("R"), s.count("S"), s.count("P")
print(
len(s) * "P" if r > si and r > p else len(s) * "R" if si > p else len(s) * "S"
)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VAR BIN_OP FUNC_CALL VAR VAR STRING BIN_OP FUNC_CALL VAR VAR STRING
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for _ in range(t):
a = input()
d = {"R": 0, "S": 0, "P": 0}
for i in a:
d[i] += 1
if d["R"] >= d["S"] and d["S"] >= d["P"] or d["R"] >= d["P"] and d["P"] >= d["S"]:
d["R"] = len(a)
while d["R"] > 0:
print("P", end="")
d["R"] -= 1
elif d["P"] >= d["R"] and d["R"] >= d["S"] or d["P"] >= d["S"] and d["S"] >= d["R"]:
d["P"] = len(a)
while d["P"] > 0:
print("S", end="")
d["P"] -= 1
elif d["S"] >= d["R"] and d["R"] >= d["P"] or d["S"] >= d["P"] and d["P"] >= d["R"]:
d["S"] = len(a)
while d["S"] > 0:
print("R", end="")
d["S"] -= 1
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR STRING FUNC_CALL VAR VAR WHILE VAR STRING NUMBER EXPR FUNC_CALL VAR STRING STRING VAR STRING NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR STRING FUNC_CALL VAR VAR WHILE VAR STRING NUMBER EXPR FUNC_CALL VAR STRING STRING VAR STRING NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR STRING FUNC_CALL VAR VAR WHILE VAR STRING NUMBER EXPR FUNC_CALL VAR STRING STRING VAR STRING NUMBER EXPR FUNC_CALL VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
import sys
input = sys.stdin.readline
LI = lambda: list(map(int, input().split()))
MI = lambda: map(int, input().split())
SI = lambda: input().strip("\n")
II = lambda: int(input())
res = []
for _ in range(II()):
r, s, p = 0, 0, 0
S = SI()
n = len(S)
for c in S:
if c == "R":
r += 1
elif c == "S":
s += 1
else:
p += 1
num = {}
num["RSP"] = s + r + p
num["RRS"] = s * 2 + p
num["SSR"] = p * 2 + s
num["RRP"] = s * 2 + r
num["PPR"] = r * 2 + s
num["PPS"] = r * 2 + p
num["SSP"] = p * 2 + r
num["PPP"] = r * 3
num["RRR"] = s * 3
num["SSS"] = p * 3
out = max(num.keys(), key=lambda x: num[x])
if out == "RSP":
ans = S
elif out == "RRS":
ans = "S" * p + (n - p) * "R"
elif out == "SSR":
ans = "R" * s + (n - s) * "S"
elif out == "RRP":
ans = "P" * r + (n - r) * "R"
elif out == "PPR":
ans = "R" * s + (n - s) * "P"
elif out == "PPS":
ans = "S" * p + (n - p) * "P"
elif out == "SSP":
ans = "P" * r + (n - r) * "S"
elif out == "RRR":
ans = "R" * n
elif out == "PPP":
ans = "P" * n
else:
ans = "S" * n
res.append(ans)
print(*res)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR DICT ASSIGN VAR STRING BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR STRING BIN_OP VAR NUMBER ASSIGN VAR STRING BIN_OP VAR NUMBER ASSIGN VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP BIN_OP VAR VAR STRING IF VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP BIN_OP VAR VAR STRING IF VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP BIN_OP VAR VAR STRING IF VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP BIN_OP VAR VAR STRING IF VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP BIN_OP VAR VAR STRING IF VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP BIN_OP VAR VAR STRING IF VAR STRING ASSIGN VAR BIN_OP STRING VAR IF VAR STRING ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = input()
for i in range(int(t)):
string = input()
frequency = [0, 0, 0]
for j in string:
if j == "R":
frequency[0] += 1
elif j == "S":
frequency[1] += 1
elif j == "P":
frequency[2] += 1
a = max(frequency)
if frequency.index(a) == 0:
print("P" * len(string))
elif frequency.index(a) == 1:
print("R" * len(string))
elif frequency.index(a) == 2:
print("S" * len(string))
|
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER NUMBER IF VAR STRING VAR NUMBER NUMBER IF VAR STRING VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
test_case = int(input())
for _ in range(test_case):
st = input()
x = [0, 0, 0]
for i in st:
if i == "R":
x[0] += 1
elif i == "S":
x[1] += 1
else:
x[2] += 1
y = {"P": x[0], "R": x[1], "S": x[2]}
y = sorted(y.items(), key=lambda m: m[1])
print(y[2][0] * len(st))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER NUMBER IF VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
class Solution:
def __init__(self):
for t in range(int(input())):
s = list(input())
self.solve(s)
def solve(self, s):
win = {"R": "P", "P": "S", "S": "R"}
best = list(
map(lambda x: (sum([(1) for i in s if i == x]), win[x]), win.keys())
)
print(max(best)[1] * len(s))
Solution()
|
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
def solve():
s = input()
ans = ""
d = {}
for i in s:
d[i] = d.get(i, 0) + 1
maxfreq = max(d.values())
for i in d:
if d[i] == maxfreq:
ans = i
break
if ans == "S":
return "R" * len(s)
if ans == "R":
return "P" * len(s)
return "S" * len(s)
print(ans)
for _ in range(int(input())):
ans = solve()
print(ans)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR STRING RETURN BIN_OP STRING FUNC_CALL VAR VAR IF VAR STRING RETURN BIN_OP STRING FUNC_CALL VAR VAR RETURN BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
S = list(stdin.readline().strip())
r = len([c for c in S if c == "R"])
s = len([c for c in S if c == "S"])
p = len([c for c in S if c == "P"])
if r == max(r, s, p):
print("P" * len(S))
elif s == max(r, s, p):
print("R" * len(S))
elif p == max(r, s, p):
print("S" * len(S))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR STRING IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for _ in range(t):
s = input()
c = max("RSP", key=s.count)
response = {"R": "P", "P": "S", "S": "R"}[c]
print(len(s) * response)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
for _ in range(II()):
s = SI()
hand = "RSP"
cnt = [0] * 3
for c in s:
i = hand.find(c)
cnt[i] += 1
mx = max(cnt)
for i in range(3):
if cnt[i] == mx:
print(hand[i - 1] * len(s))
break
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = input()
t = int(t)
def max(a, b):
if a > b:
return a
return b
while t > 0:
t -= 1
s = input()
l = [0, 0, 0]
for i in range(0, len(s)):
if s[i] == "R":
l[0] += 1
elif s[i] == "P":
l[1] += 1
else:
l[2] += 1
max1 = max(max(l[0], l[1]), l[2])
ans = "R"
if max1 == l[0]:
ans = "P"
elif max1 == l[1]:
ans = "S"
for i in range(0, len(s)):
print(ans, end="")
print("")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
T = int(input())
for case in range(T):
value = input()
count = [0, 0, 0]
for v in value:
if v == "R":
count[0] += 1
elif v == "S":
count[1] += 1
elif v == "P":
count[2] += 1
if count[0] >= count[1] and count[0] >= count[2]:
print("P" * len(value))
elif count[1] >= count[0] and count[1] >= count[2]:
print("R" * len(value))
else:
print("S" * len(value))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER NUMBER IF VAR STRING VAR NUMBER NUMBER IF VAR STRING VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
ans = []
for _ in range(t):
s = input()
R = 0
S = 0
P = 0
l = len(s)
for i in range(len(s)):
if s[i] == "R":
R += 1
elif s[i] == "S":
S += 1
else:
P += 1
m = max(R, S, P)
if S == m:
res = "R" * l
ans.append(res)
continue
elif R == m:
res = "P" * l
ans.append(res)
continue
else:
res = "S" * l
ans.append(res)
for i in range(len(ans)):
print(ans[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
def tell(a, n):
c = [[0, "R"], [0, "P"], [0, "S"]]
for i in range(n):
if a[i] == "R":
c[1][0] += 1
elif a[i] == "P":
c[2][0] += 1
else:
c[0][0] += 1
c.sort()
return c[-1][1] * n
number_o_v = int(input())
for i in range(number_o_v):
a = str(input())
n = len(a)
s = tell(a, n)
print(s)
|
FUNC_DEF ASSIGN VAR LIST LIST NUMBER STRING LIST NUMBER STRING LIST NUMBER STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR RETURN BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
while t:
n = input()
a, b, c = n.count("R"), n.count("P"), n.count("S")
d = max(a, b, c)
if d == a:
for x in range(len(n)):
print("P", end="")
elif d == b:
for x in range(len(n)):
print("S", end="")
elif d == c:
for x in range(len(n)):
print("R", end="")
print()
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR NUMBER
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
TC = int(input())
for tc in range(TC):
S = input()
P = "RSP"
r = 0
s = 0
p = 0
for l in S:
if l == "R":
r += 1
elif l == "S":
s += 1
else:
p += 1
maxi = max(r, p, s)
if maxi == r:
result = "P" * len(S)
elif maxi == p:
result = "S" * len(S)
elif maxi == s:
result = "R" * len(S)
else:
result = "NR"
print("".join(result))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
while t:
s = input()
answ = ""
count_r, count_s, count_p = 0, 0, 0
for i in s:
if i == "R":
count_r += 1
elif i == "P":
count_p += 1
elif i == "S":
count_s += 1
max_count = max(count_r, count_s, count_p)
if max_count == count_r:
answ = "P" * len(s)
elif max_count == count_p:
answ = "S" * len(s)
elif max_count == count_s:
answ = "R" * len(s)
print(answ)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
T = int(input())
for t in range(T):
s = input()
RPS = [0, 0, 0]
for c in s:
if c == "R":
RPS[0] += 1
elif c == "P":
RPS[1] += 1
else:
RPS[2] += 1
max_i = RPS.index(max(RPS))
if max_i == 0:
print("".join(["P" for x in range(len(s))]))
elif max_i == 1:
print("".join(["S" for x in range(len(s))]))
else:
print("".join(["R" for x in range(len(s))]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER NUMBER IF VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
def process(s):
n = len(s)
beat = {"R": "P", "P": "S", "S": "R"}
mapp = {"R": 0, "S": 0, "P": 0}
for ele in set(s):
for char in s:
if ele == char:
mapp[ele] += 1
inv_map = {num: ch for ch, num in mapp.items()}
e = beat[inv_map[max(inv_map)]]
print(e * n)
T = int(input())
for i in range(T):
s = input()
process(s)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for _ in range(t):
list1 = input().strip()
r = list1.count("R")
p = list1.count("P")
s = list1.count("S")
winner = max(r, p, s)
if winner == r:
choice = "P"
elif winner == p:
choice = "S"
else:
choice = "R"
for i in range(len(list1)):
print(choice, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING IF VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in range(int(input())):
s = input()
d = {"R": 0, "S": 1, "P": 2}
cnt = [0, 0, 0]
ctr = ["P", "R", "S"]
for i in s:
cnt[d[i]] += 1
print(ctr[cnt.index(max(cnt))] * len(s))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
import sys
input = lambda: sys.stdin.readline().rstrip()
for _ in range(int(input())):
s = input()
n = len(s)
r, s, p = s.count("R"), s.count("S"), s.count("P")
mx = max(r, s, p)
if mx == r:
print("P" * n)
elif mx == s:
print("R" * n)
else:
print("S" * n)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in range(int(input())):
c = input()
p, r, s = 0, 0, 0
for i in range(len(c)):
if c[i] == "R":
r += 1
elif c[i] == "S":
s += 1
else:
p += 1
x = max({p, r, s})
if x == p:
for i in range(len(c)):
print("S", end="")
elif x == r:
for i in range(len(c)):
print("P", end="")
else:
for i in range(len(c)):
print("R", end="")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
s = stdin.readline().strip()
d = {"R": "P", "P": "S", "S": "R"}
dct = {"R": 0, "P": 0, "S": 0}
for i in s:
dct[d[i]] += 1
x = max(dct, key=dct.get)
stdout.write("".join([x] * len(s)))
stdout.write("\n")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP LIST VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
n = int(input())
for _ in range(n):
string = input()
R = [string.count("R"), "P"]
S = [string.count("S"), "R"]
P = [string.count("P"), "S"]
ans = max([P, S, R])[1] * len(string)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR STRING STRING ASSIGN VAR LIST FUNC_CALL VAR STRING STRING ASSIGN VAR LIST FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP FUNC_CALL VAR LIST VAR VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in range(int(input())):
s = input()
n = len(s)
d = {}
p = ""
d["R"] = 0
d["P"] = 0
d["S"] = 0
for i in range(0, n):
if s[i] == "R":
if d.get("R") == None:
d["R"] = 1
else:
d["R"] += 1
elif s[i] == "P":
if d.get("P") == None:
d["P"] = 1
else:
d["P"] += 1
elif s[i] == "S":
if d.get("S") == None:
d["S"] = 1
else:
d["S"] += 1
a = d["R"]
b = d["P"]
c = d["S"]
ma = max(d["R"], d["S"], d["P"])
if d["R"] == d["S"]:
rs = d["R"]
elif d["R"] == d["P"]:
rp = d["R"]
elif d["P"] == d["S"]:
ps = d["S"]
if d["R"] == n:
for i in range(n):
p += "P"
print(p)
elif d["S"] == n:
for i in range(n):
p += "R"
print(p)
elif d["P"] == n:
for i in range(n):
p += "S"
print(p)
elif d["R"] == d["S"] and d["S"] == d["P"]:
print(s)
elif d["R"] != d["S"] or d["S"] != d["P"]:
if d["R"] == d["S"]:
if a > b:
for i in range(rs):
p += "P"
l = n - rs
for i in range(l):
p += "P"
print(p)
else:
for i in range(n):
p += "S"
print(p)
elif d["R"] == d["P"]:
if a > c:
for i in range(rp):
p += "S"
l = n - rp
for i in range(l):
p += "S"
print(p)
else:
for i in range(n):
p += "R"
print(p)
elif d["P"] == d["S"]:
if a < b:
for i in range(ps):
p += "R"
l = n - ps
for i in range(l):
p += "R"
print(p)
else:
for i in range(n):
p += "P"
print(p)
elif a > b and a > c:
for i in range(n):
p += "P"
print(p)
elif b > a and b > c:
for i in range(n):
p += "S"
print(p)
elif c > b and c > a:
for i in range(n):
p += "R"
print(p)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF FUNC_CALL VAR STRING NONE ASSIGN VAR STRING NUMBER VAR STRING NUMBER IF VAR VAR STRING IF FUNC_CALL VAR STRING NONE ASSIGN VAR STRING NUMBER VAR STRING NUMBER IF VAR VAR STRING IF FUNC_CALL VAR STRING NONE ASSIGN VAR STRING NUMBER VAR STRING NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF VAR STRING VAR STRING ASSIGN VAR VAR STRING IF VAR STRING VAR STRING ASSIGN VAR VAR STRING IF VAR STRING VAR STRING ASSIGN VAR VAR STRING IF VAR STRING VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING IF VAR STRING VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in range(int(input())):
st = input()
res = ""
r = st.count("R")
s = st.count("S")
p = st.count("P")
m = max(r, p, s)
if m == r:
for _ in range(len(st)):
res += "P"
elif m == s:
for _ in range(len(st)):
res += "R"
else:
for _ in range(len(st)):
res += "S"
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
t = int(input())
for _ in range(t):
rock, paper, scissors = 0, 0, 0
line = input()
for i in line:
if i == "R":
rock += 1
elif i == "P":
paper += 1
else:
scissors += 1
n = len(line)
if rock >= paper and rock >= scissors:
print(n * "P")
elif paper >= rock and paper >= scissors:
print(n * "S")
else:
print(n * "R")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
n = int(input())
while n > 0:
n -= 1
s = input()
l = len(s)
r = sc = p = 0
r = s.count("R")
sc = s.count("S")
p = s.count("P")
if r >= sc and r >= p:
print("P" * l)
elif p >= sc and p >= r:
print("S" * l)
else:
print("R" * l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
class Main:
def main(self):
t = int(input())
for t1 in range(0, t):
s = input()
c1 = s.count("R")
c2 = s.count("S")
c3 = s.count("P")
if max(c1, c2, c3) == c1:
print("P" * len(s))
elif max(c1, c2, c3) == c2:
print("R" * len(s))
else:
print("S" * len(s))
Main().main()
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL FUNC_CALL VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
from sys import stdin
T = int(stdin.readline().strip())
mp = dict()
mp["R"] = "P"
mp["S"] = "R"
mp["P"] = "S"
for caso in range(T):
s = stdin.readline().strip()
ans = ""
r = s.count("R")
s1 = s.count("S")
p = s.count("P")
n = len(s)
if r >= s1 and r >= p:
print("P" * n)
elif s1 >= r and s1 >= p:
print("R" * n)
else:
print("S" * n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING STRING ASSIGN VAR STRING STRING ASSIGN VAR STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
def win(s):
l = len(s)
r = s.count("R")
S = s.count("S")
p = s.count("P")
m = max(r, S, p)
if r == m:
return "P" * l
if S == m:
return "R" * l
else:
return "S" * l
t = int(input())
for _ in range(t):
s = input()
print(win(s))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN BIN_OP STRING VAR IF VAR VAR RETURN BIN_OP STRING VAR RETURN BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
for _ in range(int(input())):
t = input()
r, s, p = t.count("R"), t.count("S"), t.count("P")
b = max(r, s, p)
a = "P" if r == b else "R" if s == b else "S"
print(a * len(t))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING VAR VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
|
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P.
While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses "Rock"; if $s_{pos}$ is equal to S the bot chooses "Scissors"; if $s_{pos}$ is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round — on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.
You plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are $c_1 c_2 \dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \dots c_n$ such that $\frac{win(1) + win(2) + \dots + win(n)}{n}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contain test cases — one per line. The first and only line of each test case contains string $s = s_1 s_2 \dots s_{n}$ ($1 \le n \le 2 \cdot 10^5$; $s_i \in \{\text{R}, \text{S}, \text{P}\}$) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $n$ choices $c_1 c_2 \dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.
If there are multiple optimal answers, print any of them.
-----Example-----
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
-----Note-----
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.
In the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.
A picture from Wikipedia explaining "Rock paper scissors" game: $\beta$
|
import sys
input = sys.stdin.readline
def ceil(x):
if x != int(x):
x = int(x) + 1
return x
def swaparr(arr, a, b):
temp = arr[a]
arr[a] = arr[b]
arr[b] = temp
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def nCr(n, k):
if k > n - k:
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
def upper_bound(a, x, lo=0, hi=None):
if hi == None:
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < x:
lo = mid + 1
else:
hi = mid
return lo
def primefs(n):
primes = {}
while n % 2 == 0 and n > 0:
primes[2] = primes.get(2, 0) + 1
n = n // 2
for i in range(3, int(n**0.5) + 2, 2):
while n % i == 0 and n > 0:
primes[i] = primes.get(i, 0) + 1
n = n // i
if n > 2:
primes[n] = primes.get(n, 0) + 1
return primes
def power(x, y, p):
res = 1
x = x % p
if x == 0:
return 0
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
def swap(a, b):
temp = a
a = b
b = temp
return a, b
def find(x, link):
p = x
while p != link[p]:
p = link[p]
while x != p:
nex = link[x]
link[x] = p
x = nex
return p
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x, y = swap(x, y)
if x != y:
size[x] += size[y]
link[y] = x
def sieve(n):
prime = [(True) for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p] == True:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
return prime
MAXN = int(100000.0 + 5)
def spf_sieve():
spf[1] = 1
for i in range(2, MAXN):
spf[i] = i
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, ceil(MAXN**0.5), 2):
if spf[i] == i:
for j in range(i * i, MAXN, i):
if spf[j] == j:
spf[j] = i
def factoriazation(x):
ret = {}
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1
x = x // spf[x]
return ret
def int_array():
return list(map(int, input().strip().split()))
def str_array():
return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float("inf")
NINF = -float("inf")
for _ in range(int(input())):
s = input().strip()
n = len(s)
x, y, z = s.count("R"), s.count("S"), s.count("P")
k = max(x, y, z)
if x == k:
ans = ["P" for _ in range(n)]
elif y == k:
ans = ["R" for _ in range(n)]
elif z == k:
ans = ["S" for _ in range(n)]
print("".join(ans))
|
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF NUMBER NONE IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR DICT WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.