description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | t = int(input())
for i in range(t):
password = list(input())
a = 0
b = 0
c = 0
d = 0
if len(password) > 9:
for i in range(1, len(password) - 1):
if (
password[i] == "@"
or password[i] == "#"
or password[i] == "%"
or password[i] == "&"
or password[i] == "?"
):
a = 1
if 64 < ord(password[i]) < 91:
b = 1
if password[i].isdigit() == True:
c = 1
for i in range(0, len(password)):
if 96 < ord(password[i]) < 123:
d = 1
if a == b == c == d == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | tests = int(input())
for i in range(tests):
string = input()
lower_case = False
upper_case = False
digits = False
special_char = False
if 97 <= ord(string[0]) <= 122 or 97 <= ord(string[-1]) <= 122:
lower_case = True
for j in string[1:-1]:
num = ord(j)
if 97 <= num <= 122:
lower_case = True
elif 65 <= num <= 90:
upper_case = True
elif 48 <= num <= 57:
digits = True
elif j in ["@", "#", "%", "&", "?"]:
special_char = True
if lower_case and upper_case and digits and special_char and len(string) >= 10:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | t = int(input())
for i in range(t):
n = input()
s = ""
for j in n:
if ord(j) <= 122 and ord(j) >= 97:
s = s + "1"
break
for j in range(1, len(n) - 1):
if ord(n[j]) <= 90 and ord(n[j]) >= 65:
s = s + "1"
break
for j in range(1, len(n) - 1):
if (
ord(n[j]) == 64
or ord(n[j]) == 35
or ord(n[j]) == 37
or ord(n[j]) == 38
or ord(n[j]) == 63
):
s = s + "1"
break
for j in range(1, len(n) - 1):
if ord(n[j]) <= 58 and ord(n[j]) >= 48:
s = s + "1"
break
if len(n) >= 10:
s = s + "1"
if s == "11111":
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for _ in range(int(input())):
s = input().strip()
dig, sml, cap, cha = 0, 0, 0, 0
chs = ["@", "#", "%", "&", "?"]
nums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
if len(s) < 10:
print("NO")
else:
for i in range(len(s)):
if s[i].islower():
sml = 1
elif s[i].isupper() and (i != 0 and i != len(s) - 1):
cap = 1
elif s[i].isdigit() and (i != 0 and i != len(s) - 1):
dig = 1
elif s[i] in chs and (i != 0 and i != len(s) - 1):
cha = 1
if dig and sml and cap and cha:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for i in range(int(input())):
s = input()
one = 0
two = 0
three = 0
four = 0
if len(s) >= 10:
for i in range(len(s)):
if s[i].islower():
one += 1
if i != 0 and i != len(s) - 1:
if s[i].isupper():
two += 1
elif s[i].isdigit():
three += 1
elif s[i] in ["@", "#", "%", "&", "?"]:
four += 1
if one == 0 or two == 0 or three == 0 or four == 0:
print("NO")
else:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR LIST STRING STRING STRING STRING STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | T = int(input())
while T > 0:
S = str(input())
l = u = n = sp = 0
if len(S) >= 10:
for i in S:
alpha = "abcdefghijklmnopqrstuvwxyz"
num = "0123456789"
spl = "@#%&?"
if i in alpha:
l = l + 1
elif i in alpha.upper() and 1 <= S.index(i) <= len(S) - 2:
u = u + 1
elif i in num and 1 <= S.index(i) <= len(S) - 2:
n = n + 1
elif i in spl and 1 <= S.index(i) <= len(S) - 2:
sp = sp + 1
if l >= 1 and u >= 1 and n >= 1 and sp >= 1:
print("YES")
else:
print("NO")
else:
print("NO")
T = T - 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | lowerCase = "abcdefghijklmnopqrstuvwxyz"
upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
digitCase = "0123456789"
specialCase = "@#%&?"
T = int(input())
for i in range(T):
lower = 0
upper = 0
digit = 0
special = 0
password = input()
if len(password) < 10:
print("NO")
else:
for i in range(len(password)):
if password[i] in lowerCase:
lower = 1
elif i > 0 and i < len(password) - 1:
if password[i] in upperCase:
upper = 1
elif password[i] in digitCase:
digit = 1
elif password[i] in specialCase:
special = 1
if lower and upper and digit and special:
print("YES")
else:
print("NO") | ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | t = int(input())
for _ in range(t):
a = input()
if len(a) >= 10:
ansa = [a[i] for i in range(len(a)) if a[i].islower()]
if len(ansa) >= 1:
ansb = [a[i] for i in range(1, len(a) - 1) if a[i].isupper()]
if len(ansb) >= 1:
if len([a[i] for i in range(1, len(a) - 1) if a[i].isdigit()]) >= 1:
if (
len(
[
a[i]
for i in range(1, len(a) - 1)
if a[i] in ["@", "#", "%", "&", "?"]
]
)
>= 1
):
print("YES")
else:
print("NO")
else:
print("NO")
else:
print("NO")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR LIST STRING STRING STRING STRING STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for _ in range(int(input())):
i = input()
ans = False
alpha = "abcdefghijklmnopqrstuvwxyz"
num = "0123456789"
spl = "@#%&?"
for val in alpha:
if val in i:
ans = True
break
temp = False
temp2 = False
if len(i) < 10:
ans = False
i = i[1:-1]
for val in alpha:
if val.upper() in i:
temp2 = True
break
if not temp2:
ans = False
for val in range(10):
if str(val) in i:
temp = True
break
if not temp:
ans = False
if "@" not in i and "#" not in i and "%" not in i and "&" not in i and "?" not in i:
ans = False
if ans:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | a = ["@", "#", "%", "&", "?"]
for i in range(int(input())):
s = input()
l = [0]
l.append(len(s) - 1)
b = 0
c = 0
d = 0
e = 0
for i in range(len(s)):
if i not in l and s[i].isupper() == True:
b += 1
elif s[i].islower() == True:
c += 1
elif i not in l and s[i] in a:
d += 1
elif i not in l and s[i].isdigit() == True:
e += 1
if len(s) >= 10 and b >= 1 and c >= 1 and d >= 1 and e >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | alphabet = "abcdefghijklmnopqrstuvwxyz"
Capitals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers = "1234567890"
special = "@#%&?"
for i in range(int(input())):
s = input()
check1 = check2 = check3 = check4 = check5 = False
if len(s) >= 10:
check5 = True
for i in s:
if i in alphabet:
check1 = True
break
for i in s[1:-1]:
if i in Capitals:
check2 = True
break
for i in s[1:-1]:
if i in numbers:
check3 = True
break
for i in s[1:-1]:
if i in special:
check4 = True
break
if check4 and check3 and check2 and check1 and check5:
print("YES")
else:
print("NO") | ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | special_symbols = {"@", "#", "%", "&", "?"}
def check_security(pwd):
flags = [False, False, False, False]
l = len(pwd)
for i in range(l):
if pwd[i].islower():
flags[0] = True
if i != 0 and i != l - 1:
if pwd[i].isupper():
flags[1] = True
if pwd[i].isdigit():
flags[2] = True
if pwd[i] in special_symbols:
flags[3] = True
return flags
for _ in range(int(input())):
pwd = input()
if len(pwd) >= 10:
flags = check_security(pwd)
if flags[0] and flags[1] and flags[2] and flags[3]:
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR STRING STRING STRING STRING STRING FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for _ in range(int(input())):
s = input()
lower_check, upper_check, digit_check, spec_check = 0, 0, 0, 0
if len(s) < 10:
print("NO")
continue
if lower_check == 0:
if s[0].islower() or s[-1].islower():
lower_check = 1
for j in range(1, len(s) - 1):
i = s[j]
if lower_check == 0:
if i.islower():
lower_check = 1
if upper_check == 0:
if i.isupper():
upper_check = 1
if digit_check == 0:
if i.isdigit():
digit_check = 1
if spec_check == 0:
if i in "@#%&?":
spec_check = 1
if lower_check + upper_check + digit_check + spec_check == 4:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for i in range(int(input())):
s = input()
up, low, digit, spec = 0, 0, 0, 0
t = ["@", "#", "%", "&", "?"]
d = [int(x) for x in range(0, 10)]
if len(s) < 10:
print("NO")
else:
for i in range(len(s)):
if s[i].islower():
low += 1
elif i != 0 and i != len(s) - 1 and s[i].isupper():
up += 1
elif i != 0 and i != len(s) - 1 and s[i] in t:
spec += 1
elif i != 0 and i != len(s) - 1 and int(s[i]) in d:
digit += 1
if up > 0 and low > 0 and digit > 0 and spec > 0:
print("YES")
break
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | import sys
input = sys.stdin.readline
r = "QWERTYUIOPASDFGHJKLZXCVBNM"
A = set(list(r))
a = set(list(r.lower()))
n = set(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"])
c = set(["@", "#", "%", "&", "?"])
for i in range(int(input().strip())):
s = list(input().strip())
if len(s) < 10:
print("NO")
continue
aa = False
AA = False
CC = False
NN = False
if s[0] in a or s[-1] in a:
aa = True
for x in range(1, len(s) - 1):
if s[x] in A:
AA = True
elif s[x] in n:
NN = True
elif s[x] in c:
CC = True
elif s[x] in a:
aa = True
if not AA or not CC or not NN or not aa:
print("NO")
continue
print("YES") | IMPORT ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for _ in range(int(input())):
s = input()
check = 0
lower_check, upper_check, digit_check, spec_check = 0, 0, 0, 0
if len(s) > 9:
if lower_check == 0:
if s[0].islower() or s[-1].islower():
lower_check = 1
check += 1
for j in range(1, len(s) - 1):
i = s[j]
if lower_check == 0:
if i.islower():
lower_check = 1
check += 1
if upper_check == 0:
if i.isupper():
upper_check = 1
check += 1
if digit_check == 0:
if i.isdigit():
digit_check = 1
check += 1
if spec_check == 0:
if i in "@#%&?":
spec_check = 1
check += 1
if check == 4:
print("YES")
break
if check != 4:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for i in range(int(input())):
S1 = input()
S2 = S1[1:-1]
c1 = 0
c2 = 0
c3 = 0
c4 = 0
spl = ["@", "#", "%", "&", "?"]
for item in S1:
if item.islower():
c4 += 1
for item in S2:
if item.isupper():
c1 += 1
if item.isdigit():
c2 += 1
if item in spl:
c3 += 1
if c1 * c2 * c3 * c4 > 1 and len(S1) >= 10:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | n = int(input())
for i in range(n):
lc = "qwertyuiopasdfghjklzxcvbnm"
uc = "QWERTYUIOPASDFGHJKLZXCVBNM"
num = "01233456789"
sc = "@#%&?"
l = [0, 0, 0, 0]
st = input()
flag = 0
if len(st) >= 10:
for x in range(0, len(st)):
if min(l) != 0:
flag = 1
break
if st[x] in lc:
l[0] += 1
if x > 0 and x < len(st) - 1:
if st[x] in uc:
l[1] += 1
elif st[x] in num:
l[2] += 1
elif st[x] in sc:
l[3] += 1
if flag == 1:
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | def Solve(s, n):
lower, upper, digit, special = 0, 0, 0, 0
for i in range(n):
o = ord(s[i])
if 65 <= o <= 90 and i > 0 and i < n - 1:
upper += 1
elif 97 <= o <= 122:
lower += 1
elif 48 <= o <= 57 and i > 0 and i < n - 1:
digit += 1
elif s[i] in ["@", "#", "%", "&", "?"] and i > 0 and i < n - 1:
special += 1
if n >= 10 and special > 0 and lower > 0 and upper > 0 and digit > 0:
return "YES"
return "NO"
for _ in range(int(input())):
s = input()
n = len(s)
print(Solve(s, n)) | FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF NUMBER VAR NUMBER VAR NUMBER IF NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR LIST STRING STRING STRING STRING STRING VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for i in range(int(input())):
S1 = input()
S = S1[1:-1]
l = ["@", "#", "%", "&", "?"]
N = [number for number in range(10)]
A = [chr(item) for item in range(65, 91)]
a = [chr(items) for items in range(97, 123)]
counts = 0
for x in range(len(l)):
counts += S.count(l[x])
countA = 0
for alphaA in range(len(A)):
countA += S.count(A[alphaA])
counta = 0
for alpha in range(len(a)):
counta += S1.count(a[alpha])
countn = 0
for num in range(len(N)):
countn += S.count(str(N[num]))
if counta * counts * countA * countn > 1 and len(S1) >= 10:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
return input().strip()
def invr():
return map(int, input().split())
def outp(n):
sys.stdout.write(str(n) + "\n")
def outlt(lst):
sys.stdout.write(" ".join(map(str, lst)) + "\n")
def outplt(lst):
sys.stdout.write("\n".join(map(str, lst)))
def outpltlt(lst):
sys.stdout.write("\n".join(map(str, (" ".join(map(str, a)) for a in lst))))
lower = set([chr(x) for x in range(ord("a"), ord("z") + 1)])
upper = set([chr(x) for x in range(ord("A"), ord("Z") + 1)])
digits = set([x for x in "0123456789"])
special = set([x for x in "@#%&?"])
ans = []
for _ in range(inp()):
S = insr()
ln = len(S)
l, u, d, s = [False] * 4
if ln < 10:
an = "NO"
else:
an = "YES"
for i, ch in enumerate(S):
if not l and ch in lower:
l = True
if i > 0 and i < ln - 1:
if not u and ch in upper:
u = True
if not d and ch in digits:
d = True
if not s and ch in special:
s = True
if l and u and d and s:
break
else:
an = "NO"
ans.append(an)
outplt(ans) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER NUMBER IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | t = int(input())
while t:
s = input()
accept1 = False
accept2 = False
accept3 = False
accept4 = False
accept5 = False
if len(s) >= 10:
accept5 = True
for i in range(1, len(s) - 1):
if s[i].isnumeric():
accept3 = True
if s[i].isupper():
accept2 = True
if s[i] == "@" or s[i] == "#" or s[i] == "%" or s[i] == "&" or s[i] == "?":
accept4 = True
for i in s:
if i.islower():
accept1 = True
if accept1 and accept2 and accept3 and accept4 and accept5:
print("YES")
else:
print("NO")
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | t = int(input())
for _ in range(t):
s = input()
k = len(s)
m = ""
if len(s) > 9:
for i in s:
if i.islower() == True:
m = m + "a"
break
for j in range(1, k - 1):
if s[j].isupper() == True:
m = m + "b"
elif s[j].isdigit() == True:
m = m + "c"
elif s[j] in ["@", "#", "%", "&", "?"]:
m = m + "d"
a = set(m)
l = ""
for x in a:
l = l + x
z = sorted(l)
y = "".join(z)
if y == "abcd":
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | N = int(input())
for i in range(N):
l = input()
condition1 = False
condition2 = False
condition3 = False
condition4 = False
condition5 = False
if len(l) >= 10:
condition5 = True
for i in range(len(l)):
if l[i].islower():
condition1 = True
if i != 0 and i != len(l) - 1:
if l[i].isupper():
condition2 = True
if l[i].isdigit():
condition3 = True
if l[i] == "@" or l[i] == "#" or l[i] == "%" or l[i] == "&" or l[i] == "?":
condition4 = True
if condition1 == condition2 == condition3 == condition4 == condition5 == True:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | t = int(input())
for i in range(t):
a = input()
b, c, d, e = 0, 0, 0, 0
for i in range(len(a)):
if a[i].islower():
b += 1
elif i > 0 and i < len(a) - 1 and a[i].isupper():
c += 1
elif i > 0 and i < len(a) - 1 and a[i].isdigit():
d += 1
elif i > 0 and i < len(a) - 1 and a[i] in "@,&,#,%,?":
e += 1
if len(a) >= 10 and b >= 1 and c >= 1 and d >= 1 and e >= 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | T = int(input())
while T > 0:
str1 = input()
l1 = [
"q",
"w",
"e",
"r",
"t",
"y",
"u",
"i",
"o",
"p",
"a",
"s",
"d",
"f",
"g",
"h",
"j",
"k",
"l",
"z",
"x",
"c",
"v",
"b",
"n",
"m",
]
l2 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
l3 = ["@", "#", "%", "&", "?"]
l4 = [
"Q",
"W",
"E",
"R",
"T",
"Y",
"U",
"I",
"O",
"P",
"A",
"S",
"D",
"F",
"G",
"H",
"J",
"K",
"L",
"Z",
"X",
"C",
"V",
"B",
"N",
"M",
]
l1case, l2case, l3case, l4case = False, False, False, False
if len(str1) < 10:
print("NO")
else:
for i in range(len(str1)):
if str1[i] in l1:
l1case = True
elif str1[i] in l2 and 0 < i < len(str1) - 1:
l2case = True
elif str1[i] in l3 and 0 < i < len(str1) - 1:
l3case = True
elif str1[i] in l4 and 0 < i < len(str1) - 1:
l4case = True
if l1case == True and l2case == True and l3case == True and l4case == True:
print("YES")
else:
print("NO")
T -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | t = int(input())
for i in range(t):
s = input()
flag = None
inside = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#%&?"
if len(s) >= 10:
if (
"a" in s
or "b" in s
or "c" in s
or "d" in s
or "e" in s
or "f" in s
or "g" in s
or "h" in s
or "i" in s
or "j" in s
or "k" in s
or "l" in s
or "m" in s
or "n" in s
or "o" in s
or "p" in s
or "q" in s
or "r" in s
or "s" in s
or "t" in s
or "u" in s
or "v" in s
or "w" in s
or "x" in s
or "y" in s
or "z" in s
):
s = s[1:-1]
if "@" in s or "#" in s or "%" in s or "&" in s or "?" in s:
if (
"0" in s
or "1" in s
or "2" in s
or "3" in s
or "4" in s
or "5" in s
or "6" in s
or "7" in s
or "8" in s
or "9" in s
):
if (
"A" in s
or "B" in s
or "C" in s
or "D" in s
or "E" in s
or "F" in s
or "G" in s
or "H" in s
or "I" in s
or "J" in s
or "K" in s
or "L" in s
or "M" in s
or "N" in s
or "O" in s
or "P" in s
or "Q" in s
or "R" in s
or "S" in s
or "T" in s
or "U" in s
or "V" in s
or "W" in s
or "X" in s
or "Y" in s
or "Z" in s
):
print("YES")
else:
print("NO")
else:
print("NO")
else:
print("NO")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR VAR NUMBER NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for _ in range(int(input())):
s = input()
if len(s) < 10:
print("NO")
else:
small, caps, digit, spec = 0, 0, 0, 0
sett = ["@", "#", "%", "&", "?"]
nums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
for i in range(len(s)):
if s[i] >= "a" and s[i] <= "z":
small = 1
elif s[i] >= "A" and s[i] <= "Z" and (i != 0 and i != len(s) - 1):
caps = 1
elif s[i] in sett and (i != 0 and i != len(s) - 1):
spec = 1
elif s[i] in nums and (i != 0 and i != len(s) - 1):
digit = 1
if small and caps and spec and digit:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for _ in range(int(input())):
st = input()
if len(st) < 10:
print("NO")
continue
p = 0
q = 0
r = 0
s = 0
for i in range(1, len(st) - 1):
if st[i] >= "a" and st[i] <= "z":
p = 1
elif st[i] >= "A" and st[i] <= "Z":
q = 1
elif st[i] >= "0" and st[i] <= "9":
r = 1
else:
s = 1
if (
st[0] >= "a"
and st[0] <= "z"
or st[len(st) - 1] >= "a"
and st[len(st) - 1] <= "z"
):
p = 1
if p == q == r == s == 1:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | for _ in range(int(input())):
s = input()
cnt = 0
check = 0
sp_char = ["@", "#", "%", "&", "?"]
lower_check, upper_check, digit_check, spec_check = 0, 0, 0, 0
if len(s) < 10:
print("NO")
continue
if lower_check == 0:
if s[0].islower() or s[-1].islower():
lower_check = 1
check += 1
while cnt < len(s) - 2 and check != 4:
cnt += 1
i = s[cnt]
if lower_check == 0:
if i.islower():
lower_check = 1
check += 1
if upper_check == 0:
if i.isupper():
upper_check = 1
check += 1
if digit_check == 0:
if i.isdigit():
digit_check = 1
check += 1
if spec_check == 0:
if i in sp_char:
spec_check = 1
check += 1
if check == 4:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | c = "qwertyuiopasdfghjklzxcvbnm"
dig = "0192837465"
def sol(s):
if len(s) < 10:
return False
for ch in s:
if ch in c:
break
else:
return False
for ch in s[1:-1]:
if ch in c.upper():
break
else:
return False
for ch in s[1:-1]:
if ch in dig:
break
else:
return False
for ch in s[1:-1]:
if ch in {"@", "#", "%", "&", "?"}:
break
else:
return False
return True
for _ in range(int(input())):
s = input()
if sol(s):
print("YES")
else:
print("NO") | ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER FOR VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR RETURN NUMBER FOR VAR VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER FOR VAR VAR NUMBER NUMBER IF VAR STRING STRING STRING STRING STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | n = int(input())
for i in range(n):
pa = str(input())
s = 0
c = 0
no = 0
sp = 0
o = 0
l = len(pa)
if l >= 10:
for j in pa:
if 97 <= ord(j) <= 122:
s = 1
elif 65 <= ord(j) <= 90 and o != 0 and o != l - 1:
c = 1
elif j.isdigit() and o != 0 and o != l - 1:
no = 1
elif (
(j == "@" or j == "#" or j == "%" or j == "&" or j == "?")
and o != 0
and o != l - 1
):
sp = 1
o += 1
if s == 0 or c == 0 or no == 0 or sp == 0:
print("NO")
else:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR VAR IF NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | T = int(input())
for i in range(T):
S = input()
letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Pass = "0123456789"
special = "@#%&?"
item, upper, num, special = 0, 0, 0, 0
if len(S) >= 10:
for i in S:
if i in letter.lower():
item = 1
for i in range(1, len(S) - 1):
if S[i] in letter:
upper = 1
for i in range(1, len(S) - 1):
if S[i].isdigit():
num = 1
for i in range(1, len(S) - 1):
if S[i] == "@" or S[i] == "#" or S[i] == "%" or S[i] == "&" or S[i] == "?":
special = 1
if item == 1 and upper == 1 and num == 1 and special == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) Password must contain at least one upper case letter $[A-Z]$ strictly inside, i.e. not as the first or the last character;
3) Password must contain at least one digit $[0-9]$ strictly inside;
4) Password must contain at least one special character from the set $\{$ '@', '\#', '%', '&', '?' $\}$ strictly inside;
5) Password must be at least $10$ characters in length, but it can be longer.
Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.
------ Input ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, string $S$.
------ Output ------
For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.
------ Constraints ------
$1 ≤ |S| ≤ 20$
All the characters in $S$ are one of the following: lower case letters $[a-z]$, upper case letters $[A-Z]$, digits $[0-9]$, special characters from the set $\{$ '@', '\#', '%', '&', '?' $\}$
Sum of length of strings over all tests is atmost $10^{6}$
----- Sample Input 1 ------
3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Example case 1: Condition $3$ is not satisfied, because the only digit is not strictly inside.
Example case 2: All conditions are satisfied.
Example case 3: Condition $5$ is not satisfied, because the length of this string is 8. | t = int(input())
def check(s):
if len(s) < 10:
return False
else:
l = len(s)
sa = 0
la = 0
n = 0
sc = 0
for i in range(l):
if s[i] in "abcdefghijklmnopqrstuvwxyz":
sa += 1
if s[i] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and (i != 0 and i != l - 1):
la += 1
if s[i] in "@#%&?" and (i != 0 and i != l - 1):
sc += 1
if s[i] in "0123456789" and (i != 0 and i != l - 1):
n += 1
if sa >= 1 and la >= 1 and n >= 1 and sc >= 1:
return True
else:
return False
for i in range(t):
s = input()
print("YES" if check(s) else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
flip = 0
count = 0
ans = 0
j = 0
for i in range(n):
if arr[i] == 0:
flip = flip + 1
while flip > m:
if arr[j] == 0:
flip = flip - 1
j = j + 1
if i - j + 1 > ans:
ans = i - j + 1
i = i + 1
return ans | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | import sys
def findZeroes(arr, n, m):
i = 0
j = 0
maxi = -sys.maxsize
numzeroes = 0
while j < n:
if arr[j] == 0:
numzeroes += 1
while numzeroes > m:
if arr[i] == 0:
numzeroes -= 1
i += 1
maxi = max(maxi, j - i + 1)
j += 1
return maxi | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(nums, n, k):
i = 0
j = 0
maxi = 0
count = 0
while j < len(nums):
if nums[j] == 0:
count += 1
if count < k:
maxi = max(maxi, j - i + 1)
j += 1
elif count == k:
maxi = max(maxi, j - i + 1)
j += 1
elif count > k:
while count > k:
if nums[i] == 0:
count -= 1
i += 1
maxi = max(maxi, j - i + 1)
j += 1
return maxi | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
left = right = 0
best_win = 0
zero_count = 0
while right < n:
if zero_count <= m:
if arr[right] == 0:
zero_count += 1
right += 1
if zero_count > m:
if arr[left] == 0:
zero_count -= 1
left += 1
if right - left > best_win:
best_win = right - left
return best_win | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
i, j = 0, 0
ans = 0
cnt = 0
while j < len(arr):
if arr[j] == 0:
cnt += 1
if cnt <= m:
ans = max(ans, j - i + 1)
j += 1
else:
while cnt > m:
if arr[i] == 0:
cnt -= 1
i += 1
j += 1
return ans | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
nums = arr
maxm = 0
i, j = 0, 0
n = len(nums)
while j < n:
if arr[j] == 1:
maxm = max(maxm, j - i + 1)
j += 1
elif arr[j] == 0 and m > 0:
maxm = max(maxm, j - i + 1)
j += 1
m -= 1
else:
if arr[i] == 0:
m += 1
i += 1
return maxm | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
left = 0
zeros = 0
max_cons_ones = 0
for right in range(n):
if arr[right] == 0:
zeros += 1
while zeros > m:
if arr[left] == 0:
zeros -= 1
left += 1
max_cons_ones = max(max_cons_ones, right - left + 1)
return max_cons_ones | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
i = j = result = 0
max_ones = 0
while j < n:
if arr[j] == 1:
max_ones += 1
if j - i + 1 - max_ones > m:
if arr[i] == 1:
max_ones -= 1
i += 1
else:
result = max(result, j - i + 1)
j += 1
return result | FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
j = 0
count = 0
maxCount = 0
for i in range(n):
if arr[i] == 1:
count = count + 1
elif m > 0:
count = count + 1
m = m - 1
else:
while arr[j] != 0 and j < n:
j = j + 1
j = j + 1
count = i - j + 1
if count > maxCount:
maxCount = count
return maxCount | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
left = right = s_idx = 0
maxlen = -1000000000
while right < len(arr):
while right < len(arr) and (arr[right] == 1 or m > 0):
if arr[right] == 0:
m -= 1
right += 1
length = right - left
if length > maxlen:
maxlen = length
s_idx = left
while left < len(arr) and arr[left] == 1:
left += 1
left += 1
m += 1
return maxlen | FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
left = right = zero_count = max_count = 0
while right < n:
if arr[right] == 0:
zero_count += 1
right += 1
while zero_count > m:
if arr[left] == 0:
zero_count -= 1
left += 1
max_count = max(max_count, right - left)
return max_count | FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
a = 0
j = 0
for i in range(len(arr)):
if arr[i] == 0:
a += 1
if a > m:
if arr[j] == 0:
a -= 1
j += 1
return n - j | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
i = 0
j = 0
cnt = 0
maxlen = 0
while j < n:
if cnt <= m:
if arr[j] == 0:
cnt += 1
maxlen = max(maxlen, j - i)
j += 1
else:
if arr[i] == 0:
cnt -= 1
i += 1
if cnt <= m:
maxlen = max(maxlen, j - i)
return maxlen | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | import sys
def findZeroes(arr, n, m):
M = m
cz = 0
ans = 0
i = 0
for j in range(n):
if arr[j] == 0:
M -= 1
while M < 0:
if arr[i] == 0:
M += 1
i += 1
cz = j - i + 1
ans = max(ans, cz)
return ans | IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
right = 0
left = 0
countZero = 0
while right < n:
if arr[right] == 0:
countZero += 1
if countZero > m:
if arr[left] == 0:
countZero -= 1
left += 1
right += 1
return right - left | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
czero = 0
j = -1
ans = 0
for i in range(n):
if arr[i] == 0:
czero += 1
while czero > m:
j += 1
if arr[j] == 0:
czero -= 1
tot = i - j
ans = max(ans, tot)
return ans | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
left_index = 0
right_index = 0
zeros_count = []
res = 0
for i in range(n):
if arr[i] == 0:
zeros_count.append(i)
if len(zeros_count) <= m:
res = max(res, right_index - left_index)
else:
left_index = zeros_count[0] + 1
zeros_count.pop(0)
res = max(res, right_index - left_index)
else:
res = max(res, right_index - left_index)
right_index += 1
return res + 1 | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
stack = [i for i in range(n - 1, -1, -1) if arr[i] == 0]
t = m
maxi = 0
i = 0
j = 0
c = 0
while i < n:
if arr[i] == 1:
c += 1
i += 1
elif arr[i] == 0 and t > 0:
t -= 1
c += 1
i += 1
else:
old = j
top = stack.pop()
j = top + 1
c -= j - old
t += 1
maxi = max(maxi, c)
return maxi | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
p1 = 0
p2 = 0
maxi = 0
while p2 < n and p1 < n:
if m > 0 or arr[p2] == 1:
if arr[p2] == 0:
m -= 1
maxi = max(maxi, p2 - p1 + 1)
p2 += 1
else:
if arr[p1] == 0:
m += 1
p1 += 1
return maxi | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
k = m
cnt = 0
l = 0
i = 0
mx = -1
while i < n:
if arr[i] == 1:
l += 1
else:
if cnt >= m:
break
l += 1
cnt += 1
i += 1
mx = max(mx, l)
s = 0
while i < n:
if arr[i] == 0:
cnt += 1
if cnt > m:
if arr[s] == 0:
cnt -= 1
s += 1
if cnt <= m:
mx = max(mx, i - s + 1)
i += 1
return mx | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
start = 1
end = 1
zero = 0
maxx = 0
for i in range(n):
if arr[i] == 0:
zero += 1
end += 1
while zero > m:
if arr[start - 1] == 0:
zero -= 1
start += 1
l = end - start
if l > maxx:
maxx = l
return maxx | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
i, j, zeroes, ones, res = 0, 0, 0, 0, 0
while j < n:
if arr[j] == 0:
zeroes += 1
else:
ones += 1
while j - i + 1 - ones > m:
if arr[i] == 0:
zeroes -= 1
else:
ones -= 1
i += 1
res = max(res, j - i + 1)
j += 1
return res | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
windowLeft = 0
windowRight = 0
result = 0
zero_count = 0
while windowRight < n:
if arr[windowRight] == 0:
if zero_count == m:
while arr[windowLeft] != 0:
windowLeft += 1
windowLeft += 1
else:
zero_count += 1
windowRight += 1
result = max(result, windowRight - windowLeft)
return result | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER IF VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
window_size = 0
j = 0
for i in range(n):
if arr[i] == 0:
if m > 0:
m -= 1
else:
while arr[j] != 0:
j += 1
j += 1
window_size = max(i - j + 1, window_size)
return window_size | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR |
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's.
Example 1:
Input:
N = 3
arr[] = {1, 0, 1}
M = 1
Output:
3
Explanation:
Maximum subarray is of size 3
which can be made subarray of all 1 after
flipping one zero to 1.
Example 2:
Input:
N = 11
arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}
M = 2
Output:
8
Explanation:
Maximum subarray is of size 8
which can be made subarray of all 1 after
flipping two zeros to 1.
Your Task:
Complete the function findZeroes() which takes array arr and two integers n, m, as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{7}
0 <= M <= N
0 <= arr_{i} <= 1 | def findZeroes(arr, n, m):
if m == 0:
maxi = 0
count = 0
for i in range(n):
if arr[i] == 1:
count += 1
if i == n - 1:
maxi = max(maxi, count)
return maxi
else:
maxi = max(maxi, count)
count = 0
return maxi
start = 0
cnt_0 = 0
for i in range(n):
if arr[i] == 0:
cnt_0 += 1
if cnt_0 > m:
if arr[start] == 0:
cnt_0 -= 1
start += 1
return n - start | FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR |
In order to expand its reach to the outer universe and ensure universal peace, the [MIB] has decided to expand its offices.
Namely, it has established its office on N most important planets in the universe, with the base station on the planet S. Each office has an intergalactic teleporter that connects it to other planet offices. But the teleporters are bound to a planet's policy, so you cannot teleport to any planet you wish.
Due to intergalactic feuds, the planets are divided into K different alliances, numbered 1 through K. You know for each planet i, the alliance that it belongs to. In other words, you're given a sequence A_{1}, A_{2}, \dots, A_{n}, which says that planet i belongs to alliance A_{i}.
Each planet i has a policy of teleportation to the planets of other alliances:
Cost to travel from one planet to another is determined by the alliance of the destination planet. More formally, the cost to reach a planet which belongs to alliance j from planet i is represented as C_{i, j}.
Intra-alliance travel is free, i.e., if A_{i} = j, then C_{i, j} = 0.
For a planet i, there are some forbidden alliances as well. For these alliances, C_{i, j} = -1, given that alliance j is forbidden to travel from planet i.
As MIB is bound to follow the intergalactic rules and since they have limited funds (yes, the government is cheap everywhere), they have decided to find the most optimal way to travel to each of the planets from the base station at planet S. With all other agents busy with their missions, you are assigned the task to find these minimum-cost paths. This is your first task in MIB, so don't let them down!
------ Input Format ------
- The first line will consist of three space-separated integers N, K, and S (number of planets, number of alliances, and base planet).
- Second-line will consist of N space-separated integers representing A_{i}, the alliance corresponding to the i^{th} planet.
- Each of the next N lines will consist of K space-separated integers, where the j^{th} integer of the i^{th} line represents C_{i, j}, the cost to travel from planet i to alliance j.
------ Output Format ------
Print N space separated integers, the i^{th} integer representing the minimal cost to reach the i^{th} planet from the base station. For unreachable planets print -1.
------ Constraints ------
$1 ≤ N ≤ 2 * 10^{4}$
$1 ≤ K ≤ min(N, 1000)$
$N * K ≤ 2 * 10^{6}$
$1 ≤ A_{i} ≤ K$
$-1 ≤ C_{i,j} ≤ 10^{9}$
----- Sample Input 1 ------
5 3 4
1 3 1 2 2
0 5 -1
-1 4 0
0 3 -1
4 0 -1
4 0 3
----- Sample Output 1 ------
4 3 4 0 0
----- explanation 1 ------
- As $4$ and $5$ belong to the same component, the cost of traveling in-between is $0$.
- There are multiple shortest paths from $4$ to $1$. They are:
$4 \rightarrow 3 \rightarrow 1, 4 \rightarrow 5 \rightarrow 3 \rightarrow 1$, $4 \rightarrow 1$, etc. All of these have equal costs, that is $4$.
- Only path from $4$ to $2$ is $4 \rightarrow 5 \rightarrow 2$, which costs $3$ units.
- Similarly for node $3$, the cost is $4$ units. | N, K, S = map(int, input().split())
S -= 1
A = list(map(lambda x: int(x) - 1, input().split()))
C = []
for i in range(N):
C.append(list(map(int, input().split())))
C_BW_A = [{} for i in range(K)]
for i in range(N):
a = A[i]
for b in range(K):
if a != b:
cur_c = C_BW_A[a].get(b, float("inf"))
cost_f_p = C[i][b]
if 0 <= cost_f_p < cur_c:
C_BW_A[a][b] = cost_f_p
C_F_BASE = [float("inf") for i in range(K)]
C_F_BASE[A[S]] = 0
unvisited = set(range(K))
while unvisited:
min_d, min_a = float("inf"), -1
for a in unvisited:
if C_F_BASE[a] < min_d:
min_d = C_F_BASE[a]
min_a = a
if min_a == -1:
break
unvisited.remove(min_a)
for n, l in C_BW_A[min_a].items():
ndist = min_d + l
if ndist < C_F_BASE[n]:
C_F_BASE[n] = ndist
for i in range(K):
if C_F_BASE[i] == float("inf"):
C_F_BASE[i] = -1
print(" ".join(str(C_F_BASE[A[i]]) for i in range(N))) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR IF NUMBER VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
if n * m - 2 > k:
print("YA")
continue
pos = n * m - 3
isPosib = True
while pos < len(a):
if a[pos] >= k:
isPosib = False
break
k -= 1
pos += 1
if not isPosib:
print("TIDAK")
continue
print("YA") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | class FenwickTree:
def __init__(self, n):
self.bit = [0] * n
self.size = n
def update(self, idx, x):
while idx < self.size:
self.bit[idx] += x
idx |= idx + 1
def __call__(self, start, end):
return self.__getitem__(end) - self.__getitem__(start)
def __getitem__(self, end):
x = 0
while end:
x += self.bit[end - 1]
end &= end - 1
return x
def find_kth(self, k):
idx = -1
for d in reversed(range(self.size.bit_length())):
right_idx = idx + (1 << d)
if right_idx < self.size and self.bit[right_idx] <= k:
idx = right_idx
k -= self.bit[idx]
return idx + 1, k
for _ in range(int(input())):
n, m, k = map(int, input().split())
a = [(k - x) for x in list(map(int, input().split()))]
pos = [0] * k
for i in range(k):
pos[a[i]] = i
F = FenwickTree(k)
for i in range(k):
F.update(i, 1)
ok = True
for i in range(k):
now = pos[i]
num = F(0, now)
if num > n * m - 4:
print("TIDAK")
ok = False
break
F.update(now, -1)
if ok:
print("YA") | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | import sys
def read():
return [int(x) for x in sys.stdin.readline().split(" ")]
[t] = read()
for _ in range(t):
[n, m, k] = read()
A = read()
for i in range(len(A)):
A[i] -= 1
l = n * m - 3
done = k * [0]
acc = 0
next = k - 1
ok = True
for a in A:
acc += 1
done[a] = 1
if a != next:
continue
if acc > l:
ok = False
break
while next and done[next]:
acc -= 1
next -= 1
print("YA" if ok else "TIDAK") | IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN LIST VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | def solve(n, m, k, a):
d = {}
val = n * m - 4
nxt = k
p1 = 0
while p1 < k:
if a[p1] == nxt:
nxt -= 1
while True:
try:
d[nxt] -= 1
nxt -= 1
val += 1
except:
break
else:
try:
d[nxt] -= 1
val += 1
nxt -= 1
except:
d[a[p1]] = 1
val -= 1
if val < 0:
return "TIDAK"
p1 += 1
return "YA"
for _ in range(int(input())):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
print(solve(m, n, k, a)) | FUNC_DEF ASSIGN VAR DICT ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER WHILE NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN STRING VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR VAR VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
while t > 0:
n, m, k = map(int, input().split())
cards = list(map(int, input().split()))
onBoard = {}
freeSpots = n * m - 2
cardNo = 0
reqd = k
freeSpotmin = 2
if m == 2 and n == 2:
freeSpotmin = 1
while freeSpots >= freeSpotmin and cardNo < k:
card = cards[cardNo]
if card != reqd:
onBoard[card] = 1
freeSpots -= 1
else:
reqd -= 1
while reqd in onBoard:
del onBoard[reqd]
reqd -= 1
freeSpots += 1
cardNo += 1
if freeSpots < freeSpotmin:
print("TIDAK")
else:
print("YA")
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR 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 DICT ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
for _ in range(t):
n, m, k = [int(x) for x in input().split()]
lst = [int(x) for x in input().split()]
empty = n * m - 3
if k <= empty:
print("YA")
else:
i = 0
count = 0
mp = {}
ans = True
while empty < k and count <= empty:
if k in mp:
del mp[k]
count = count - 1
k = k - 1
else:
mp[lst[i]] = 1
i = i + 1
count = count + 1
if count == empty + 1:
ans = False
break
if ans == True:
print("YA")
else:
print("TIDAK") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
for _ in range(t):
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
wait_set = set([])
wait_len = 0
max_len = n * m - 4
answer = "YA"
M = k
i = 0
while M > 0:
if M not in wait_set:
x = a[i]
if x != M:
wait_set.add(x)
wait_len += 1
i += 1
else:
M = M - 1
i += 1
else:
wait_set.remove(M)
wait_len -= 1
M = M - 1
if wait_len > max_len:
answer = "TIDAK"
break
print(answer) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | def my_function(ms, sz, k):
if sz - k >= 3:
print("YA")
return
my_dic = {}
for index in range(k):
my_dic[ms[index]] = index + 1
cnt = sz
for index in range(k, 0, -1):
if cnt - my_dic[index] < 3:
print("TIDAK")
return
else:
cnt += 1
print("YA")
def alg(mass):
for arr in mass:
ms = arr["arr"]
sz = arr["sz"]
k = arr["k"]
my_function(ms, sz, k)
def parsing():
cnt = int(input())
mass = []
while cnt > 0:
st = input().split(" ")
n, m, k = int(st[0]), int(st[1]), int(st[2])
arr = list(map(int, input().split(" ")))
mass.append({"sz": n * m, "k": k, "arr": arr})
cnt -= 1
return mass
res = parsing()
alg(res) | FUNC_DEF IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER EXPR FUNC_CALL VAR STRING FUNC_DEF FOR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR DICT STRING STRING STRING BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
for i in range(t):
n, m, k = [int(v) for v in input().split()]
w = [int(v) for v in input().split()][::-1]
rho = n * m - 4
zeta = k
eta = 0
res = set()
while zeta > 0:
if w:
if eta <= rho:
eta += 1
res.add(w.pop())
else:
print("TIDAK")
break
else:
zeta = 0
continue
while zeta in res:
res.remove(zeta)
zeta -= 1
eta -= 1
else:
print("YA") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER IF VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | def solve() -> None:
n, m, k = map(int, input().split())
cards = list(map(int, input().split()))
have = [False] * (k + 1)
need_card = k
occupied = 0
for card in cards:
if card == need_card:
if occupied == n * m - 3:
print("TIDAK")
return
need_card -= 1
while need_card >= 1 and have[need_card]:
occupied -= 1
need_card -= 1
else:
occupied += 1
have[card] = True
if occupied > n * m - 3:
print("TIDAK")
return
print("YA")
tt = int(input())
for _ in range(tt):
solve() | FUNC_DEF ASSIGN VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | import sys
input = sys.stdin.readline
def readList():
return list(map(int, input().split()))
def readInt():
return int(input())
def readInts():
return map(int, input().split())
def readStr():
return input().strip()
def solve():
n, m, k = readInts()
arr = readList()
isPresent = [False] * (k + 1)
curr = k
cnt = 0
for i in range(k):
if arr[i] == curr:
if cnt < n * m - 3:
curr -= 1
continue
return "TIDAK"
else:
while isPresent[curr] and curr > 0 and cnt <= n * m - 3:
isPresent[curr] = False
cnt -= 1
curr -= 1
isPresent[arr[i]] = True
cnt += 1
if cnt > n * m - 2:
return "TIDAK"
return "YA"
for _ in range(int(input())):
print(solve()) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN STRING WHILE VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | for _ in range(int(input())):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * (k + 5)
def get(i):
ans = 0
while i > 0:
ans += f[i]
i -= -i & i
return ans
def up(i):
while i <= k:
f[i] += 1
i += -i & i
ok = True
for e in a:
if get(e) > m * n - 4:
print("TIDAK")
ok = False
break
else:
up(e)
if ok:
print("YA") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF WHILE VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | def main():
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
ind = [0] * (k + 1)
for i in range(k):
ind[arr[i]] = i
aux = n * m - 4
card = k
curr = 0
while card > 0:
index = ind[card]
if curr > index:
aux += 1
card -= 1
continue
elif curr == index:
card -= 1
curr += 1
continue
else:
req = index - curr
if req <= aux:
aux -= req
curr = index + 1
card -= 1
else:
return "TIDAK"
return "YA"
for _ in range(int(input())):
print(main()) | FUNC_DEF ASSIGN VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
cap = m * n - 4
d = {}
need = k
i = 0
flag = False
while need > 0:
if need in d:
need -= 1
cap += 1
elif a[i] == need:
need -= 1
i += 1
else:
if cap == 0:
flag = True
break
cap -= 1
d[a[i]] = 1
i += 1
if flag:
print("TIDAK")
else:
print("YA") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | for _ in range(int(input())):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
freeCells = n * m - (n + m - 1)
buffers = n * m - freeCells - 4
for i in range(k):
if i - k + a[i] > freeCells + buffers:
print("TIDAK")
break
else:
print("YA") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input(""))
for j in range(t):
l = list(map(int, input("").split()))
n = l[0]
m = l[1]
k = l[2]
s = [0] * (k + 1)
s[0] = 0
c = 0
l = list(map(int, input("").split()))
a = n * m - 4
if a >= k - 1:
print("YA")
continue
for i in l:
if i != k:
s[i] = 1
c += 1
else:
k = k - 1
while s[k] == 1:
c -= 1
s[k] = 0
k -= 1
if c >= a + 1:
print("TIDAK")
break
else:
print("YA") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | I = lambda: int(input())
Is = lambda: map(int, input().split())
Li = lambda: list(map(int, input().split()))
def solve():
n, m, k = Is()
a = Li()
s = n * m - 2
seen = set()
cur = k
po = 0
for i in a:
seen.add(i)
po += 1
if po == s:
print("TIDAK")
return
if i == k:
po -= 1
seen.remove(i)
cur -= 1
while cur in seen:
po -= 1
seen.remove(cur)
cur -= 1
print("YA")
return 1
t = I()
while t:
solve()
t -= 1 | 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 VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
for x in range(t):
S = list(map(int, input().split()))
n, m, k = S[0], S[1], S[2]
stack = list(map(int, input().split()))
count = 0
d = dict()
for i in range(k):
d[stack[i]] = i
for i in range(k, 0, -1):
if d[i] > m * n - 4 + k - i:
count = 1
print("TIDAK")
break
if count == 0:
print("YA") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | def f(n, m, arr):
k = len(arr)
on_board = set()
max_size = n * m - 2
for i in range(k, 0, -1):
if i in on_board:
on_board.remove(i)
continue
while arr[-1] != i and len(on_board) < max_size:
top_value = arr.pop()
on_board.add(top_value)
if len(on_board) >= max_size - 1:
return False
arr.pop()
return True
t = int(input())
for i in range(t):
n, m, k = [int(el) for el in input().split(" ")]
arr = [int(el) for el in input().split(" ")]
r_arr = list(reversed(arr))
if f(n, m, r_arr):
print("YA")
else:
print("TIDAK") | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | for _ in range(int(input())):
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
idx = [i for i in range(k, 0, -1)]
ans = "YA"
if n * m - 3 < k:
mx = 0
for i in range(k):
if arr[i] > idx[i]:
mx = max(mx, arr[i] - idx[i])
if n * m - 4 < mx:
ans = "TIDAK"
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
for _ in range(t):
m, n, p = [int(x) for x in input().split()]
permut = [int(x) for x in input().split()]
s = set()
i = 0
flag = 0
for need in range(p, 0, -1):
while True:
if flag == 1:
break
if need in s:
s.remove(need)
break
elif len(s) == m * n - 3:
print("TIDAK")
flag = 1
else:
s.add(permut[i])
i += 1
if flag == 1:
break
if flag != 1:
print("YA") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER WHILE NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | for _ in range(int(input())):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
covered = {x: i for i, x in enumerate(a)}
avail = n * m - 4
for i in range(k, 0, -1):
o = k - i
if covered[i] - o > avail:
print("TIDAK")
break
else:
print("YA") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, m, k = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
lk = [i for i in range(k, 0, -1)]
p = n * m - 3
ans = ""
if p >= k:
ans = "YA"
else:
co = 0
for i in range(k):
if l[i] > lk[i]:
co = max(co, l[i] - lk[i])
if p > co:
ans = "YA"
else:
ans = "TIDAK"
print(ans) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | for _ in range(int(input())):
n, m, k = map(int, input().split())
a = [(x - 1) for x in list(map(int, input().split()))]
kosong, sekarang = n * m - 2, k - 1
ok, bisa = [0] * k, True
for i in range(k):
ok[a[i]] = 1
kosong -= 1
if kosong <= 0:
print("TIDAK")
bisa = False
break
while sekarang >= 0 and ok[sekarang]:
sekarang -= 1
kosong += 1
if bisa:
print("YA") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING |
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column.
Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ written on it. More specifically, the $i$-th card from the top of the stack in cell $(1, 1)$ has the number $a_i$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $1$ to $k$. All other cells are empty.
You need to move the $k$ cards to cell $(n, m)$ to create another stack of cards. Let $b_i$ be the number written on the $i$-th card from the top of the stack in cell $(n, m)$. You should create the stack in cell $(n, m)$ in such a way so that $b_i = i$ for all $1 \leq i \leq k$.
In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:
Each cell other than $(1,1)$ and $(n,m)$ must not have more than one card on it.
You cannot move a card onto cell $(1,1)$.
You cannot move a card from cell $(n,m)$.
Given the values of $n$, $m$, $k$ and the array $a$, determine if the puzzle is solvable.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains three integers $n$, $m$, and $k$ ($3 \leq n, m \leq 10^6$, $nm \leq 10^6$, $1 \leq k \leq 10^5$) — the size of the board and the number of cards.
The second line of the test case contains $k$ integers $a_1, a_2, \ldots, a_k$ — the array $a$, representing the numbers written on the cards. The values of $a$ are a permutation of integers from $1$ to $k$.
It is guaranteed that the sum of $nm$ and $k$ over all test cases do not exceed $10^6$ and $10^5$ respectively.
-----Output-----
For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively.
You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).
-----Examples-----
Input
4
3 3 6
3 6 4 1 2 5
3 3 10
1 2 3 4 5 6 7 8 9 10
5 4 4
2 1 3 4
3 4 10
10 4 9 3 5 6 8 2 7 1
Output
YA
TIDAK
YA
YA
-----Note-----
In the first test case, the following is one way the puzzle can be done:
Move the card with $3$ written on it from cell $(1, 1)$ to cell $(1, 2)$, then cell $(1, 3)$.
Move the card with $6$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $4$ written on it from cell $(1, 1)$ to cell $(1, 2)$.
Move the card with $1$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$, then cell $(2, 3)$.
Move the card with $2$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(2, 2)$.
Move the card with $5$ written on it from cell $(1, 1)$ to cell $(2, 1)$, then cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 2)$ to cell $(2, 1)$.
Move the card with $4$ written on it from cell $(1, 2)$ to cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $3$ written on it from cell $(1, 3)$ to cell $(1, 2)$, then cell $(2, 2)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $2$ written on it from cell $(2, 1)$ to cell $(3, 1)$, then cell $(3, 2)$, then cell $(3, 3)$.
Move the card with $1$ written on it from cell $(2, 3)$ to cell $(3, 3)$.
An animated illustration regarding the process mentioned above is as follows: | t = int(input())
while t > 0:
ip = [int(x) for x in input().split()]
n = ip[0]
m = ip[1]
k = ip[2]
a = [int(x) for x in input().split()]
freq = []
val = k
count = n * m - 4
for i in range(k + 1):
freq.append(0)
flag = True
for i in a:
if i == k:
k -= 1
while freq[k] > 0:
freq[k] -= 1
count += 1
k -= 1
elif count > 0:
freq[i] += 1
count -= 1
else:
flag = False
break
if flag:
print("YA")
else:
print("TIDAK")
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
table = {}
solve(root, 1, table)
for k in sorted(table):
print(k, end=" ")
print(table[k], end=" $")
print()
def solve(root, path_len, table):
if not root:
return
if not root.left and not root.right:
table[path_len] = 1 + table.get(path_len, 0)
solve(root.left, path_len + 1, table)
solve(root.right, path_len + 1, table) | FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF VAR RETURN IF VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def asd(root, d, c):
if root == None:
return
else:
c += 1
if root.left == None and root.right == None:
if c in d.keys():
d[c] += 1
else:
d[c] = 1
asd(root.left, d, c)
asd(root.right, d, c)
def pathCounts(root):
c = 0
d = {}
asd(root, d, c)
for i in sorted(d.keys()):
print(i, end=" ")
print(d[i], end=" ")
print("$", end="")
print() | FUNC_DEF IF VAR NONE RETURN VAR NUMBER IF VAR NONE VAR NONE IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
l = []
q = [[root, 1]]
c = 0
s = {}
while c != len(q):
t = q[c][0]
g = q[c][1]
f = 0
if t.left:
f = 1
q.append([t.left, g + 1])
if t.right:
f = 1
q.append([t.right, g + 1])
c += 1
if f == 0:
if g in s:
s[g] += 1
else:
s[g] = 1
b = []
for i in s:
b.append([i, s[i]])
b.sort(key=lambda x: x[0])
for i in b:
print(i[0], i[1], end=" $")
print() | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
ans = {}
def util(root, level):
nonlocal ans
if root is None:
return
if root.left is None and root.right is None:
ans[level] = ans.get(level, 0) + 1
return
util(root.left, level + 1)
util(root.right, level + 1)
util(root, 1)
s = ""
for i, j in ans.items():
s = s + str(i) + " " + str(j) + " " + "$"
print(s) | FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
def count(root, ans, path):
if not root:
return ans
if not root.left and not root.right:
ans[path] = ans.get(path, 0) + 1
return ans
count(root.left, ans, path + 1)
count(root.right, ans, path + 1)
return ans
d = count(root, {}, 1)
s = ""
for x in d:
s += "{} {} $".format(x, d[x])
print(s) | FUNC_DEF FUNC_DEF IF VAR RETURN VAR IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR DICT NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def preOrder(p, ans, k):
if p == None:
return
if p.left == None and p.right == None:
ans[k + 1] = ans.get(k + 1, 0) + 1
else:
preOrder(p.left, ans, k + 1)
preOrder(p.right, ans, k + 1)
def pathCounts(root):
dict = {}
preOrder(root, dict, 0)
ans = []
for k, v in dict.items():
ans.append((k, v))
ans.sort()
for a in ans:
print(a[0], a[1], "$", end="") | FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING STRING |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
def root_node(root, count):
if root == None:
return None
count += 1
if root.left == None and root.right == None:
if count not in dict1:
dict1[count] = 1
else:
dict1[count] += 1
if root_node(root.left, count) or root_node(root.right, count):
return True
count -= 1
return False
string = ""
dict1 = dict()
root_node(root, 0)
for i in dict1:
string = string + str(i) + " " + str(dict1[i]) + " " + "$"
print(string) | FUNC_DEF FUNC_DEF IF VAR NONE RETURN NONE VAR NUMBER IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
final = {}
def solve(root, ans):
ans.append(root.data)
if root.left == None and root.right == None:
n = len(ans)
if n in final:
final[n] += 1
else:
final[n] = 1
if root.left:
solve(root.left, ans)
if root.right:
solve(root.right, ans)
ans.pop()
solve(root, [])
d = ""
for i in final.items():
d += str(i[0])
d += " "
d += str(i[1])
d += " "
d += "$"
print(d) | FUNC_DEF ASSIGN VAR DICT FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR NONE VAR NONE ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR STRING VAR FUNC_CALL VAR VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
lengthMap = dict()
_pathCounts(root, lengthMap, [])
for key in sorted(lengthMap.keys()):
s = str(key) + " " + str(lengthMap[key]) + " " + "$"
print(s, end="")
print()
def _pathCounts(root, lengthMap, path):
if not root:
return
path.append(root)
if root.left is None and root.right is None:
if len(path) in lengthMap:
lengthMap[len(path)] += 1
else:
lengthMap[len(path)] = 1
_pathCounts(root.left, lengthMap, path)
_pathCounts(root.right, lengthMap, path)
path.remove(root) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF VAR RETURN EXPR FUNC_CALL VAR VAR IF VAR NONE VAR NONE IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
d = dict()
D(d, root, 1)
for i in d:
print(i, d[i], end=" $")
print()
def D(d, root, k):
if root and not root.left and not root.right:
if k not in d:
d[k] = 1
else:
d[k] += 1
if root:
D(d, root.left, k + 1)
D(d, root.right, k + 1) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
d = {}
def f(root, pl, d):
if root == None:
return
if root.left == None and root.right == None:
d[pl] = d.get(pl, 0) + 1
return
f(root.left, pl + 1, d)
f(root.right, pl + 1, d)
f(root, 1, d)
for i in sorted(d):
print(i, d[i], "$", end="")
print() | FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def pathCounts(root):
def func(node, arr, ans):
if node == None:
return
if node.left == None and node.right == None:
arr.append(node.data)
ans.append(arr.copy())
arr.pop()
return 0
arr.append(node.data)
func(node.left, arr, ans)
func(node.right, arr, ans)
arr.pop()
ans = []
func(root, [], ans)
d = {}
for x in ans:
if len(x) in d:
d[len(x)] += 1
else:
d[len(x)] = 1
ans = []
for x in d:
ans += [[x, d[x]]]
for x in ans:
print(x[0], x[1], "$", end="")
print() | FUNC_DEF FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR LIST LIST VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING STRING EXPR FUNC_CALL VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def freq(arr, val):
return sum([(1) for u in arr if u == val])
def helper(r, D, l):
if r.right is None and r.left is None:
D = D + [l]
return D
elif r.right is None and r.left is not None:
return helper(r.left, D, l + 1)
elif r.right is not None and r.left is None:
return helper(r.right, D, l + 1)
else:
p1 = helper(r.left, D, l + 1)
p2 = helper(r.right, D, l + 1)
return p1 + p2
def pathCounts(r):
res = helper(r, [], 1)
L = set(res)
s = ""
for u in L:
s = s + str(u) + " " + str(freq(res, u)) + " $"
print(s) | FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_DEF IF VAR NONE VAR NONE ASSIGN VAR BIN_OP VAR LIST VAR RETURN VAR IF VAR NONE VAR NONE RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NONE VAR NONE RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def helper(root, d, l):
if root == None:
return
if root.left == None and root.right == None:
if l in d:
d[l] = d[l] + 1
else:
d[l] = 1
helper(root.left, d, l + 1)
helper(root.right, d, l + 1)
def pathCounts(root):
d = {}
helper(root, d, 1)
for l in sorted(d):
print(l, d[l], "$", end="")
print()
del d | FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR |
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000 | def helper(root, d, count_dict):
if root is None:
return
if root.left is None and root.right is None:
count_dict.setdefault(d + 1, 0)
count_dict[d + 1] += 1
return
helper(root.left, d + 1, count_dict)
helper(root.right, d + 1, count_dict)
def pathCounts(root):
count_dict = {}
helper(root, 0, count_dict)
counts = list(sorted(list(count_dict.keys())))
tmp_string = ""
for key in counts:
tmp_string += str(key) + " " + str(count_dict[key]) + " $"
print(tmp_string) | FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.