message stringlengths 2 28.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 21 109k | cluster float64 7 7 | __index_level_0__ int64 42 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
Submitted Solution:
```
t = int(input())
s = list(input())
l1 = []
l2 = []
B = 0
W = 0
j = 0
p = []
q = []
for i in s:
l1.append(i)
l2.append(i)
if l1[j] == "W":
W += 1
else:
B += 1
j += 1
if W==0 or B==0:
print(0)
else:
for k in range(t-1):
if l1[k] != 'B':
l1[k] = 'B'
p.append(k + 1)
if l1[k+1] == 'B':
l1[k+1] = 'W'
elif l1[k+1] == 'W':
l1[k+1] = 'B'
if l2[k] != 'W':
l2[k] = 'W'
q.append(k + 1)
if l2[k+1] == 'W':
l2[k+1] = 'B'
elif l2[k+1] == 'B':
l2[k+1] = 'W'
if l1[-1] == 'B':
print(len(p))
while p:
print(p[-1])
p.pop()
elif l2[-1] == 'W':
print(len(q))
while q:
print(q[-1])
q.pop()
else:
print(-1)
``` | instruction | 0 | 5,155 | 7 | 10,310 |
Yes | output | 1 | 5,155 | 7 | 10,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
Submitted Solution:
```
n=int(input())
s=input()
a=list(s)
if (a.count("B")%2)*(a.count("W")%2):print(-1);exit()
b=[]
if a.count("B")%2:m="W"
else:m="B"
for i in range(n-1):
if a[i]==m:
b.append(i+1)
if a[i]=="W":a[i]="B"
else:a[i]="W"
if a[i+1]=="W":a[i+1]="B"
else:a[i+1]="W"
print(len(b))
if len(b):print(*b)
``` | instruction | 0 | 5,156 | 7 | 10,312 |
Yes | output | 1 | 5,156 | 7 | 10,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
Submitted Solution:
```
n = int(input())
b = [1 if i == "B" else 0 for i in input()]
sb = sum(b)
if sb % 2 == 1 and n % 2 == 0:
print(-1)
elif sb == 0 or sb == n:
print(0)
else:
if sb > n//2:
flip = 1
else:
flip = 0
ans = []
for a in range(len(b)-1):
if b[a] == flip:
print(b)
ans.append(a+1)
b[a] = 1 - b[a]
b[a+1] = 1 - b[a+1]
print(len(ans))
print(" ".join(map(str, ans)))
``` | instruction | 0 | 5,157 | 7 | 10,314 |
No | output | 1 | 5,157 | 7 | 10,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
Submitted Solution:
```
n = int(input())
s = str(input())
s = s.replace('W', '0')
s = s.replace('B', '1')
def funs(s):
ind = []
for i in range(0, len(s)):
k = int(s[i]) % 2
ind.append(k)
return ind
def conv(ind):
st = ''
for i in range(0, len(ind)):
if ind[i] == 1:
st = st + 'B'
elif ind[i] == 0:
st = st + 'W'
return st
s = str(s)
if s.count('0') > s.count('1'):
mak = 0
mal = 1
else:
mak = 1
mal = 0
s = funs(s)
if s.count(mak) == len(s):
print('0')
elif s.count(mak) % 2 == 1:
print('-1')
else:
ink = []
for i in range(0, len(s) - 1):
if s[i] == mak:
ink.append(i)
s[i + 1] = s[i + 1] + 1
s[i] = s[i] + 1
ink.sort(reverse=True)
stk=''
for y in ink:
y=y+1
stk=stk+str(y)+' '
if len(ink) <= 3*n:
print(len(ink))
print(stk)
else:
print('-1')
``` | instruction | 0 | 5,158 | 7 | 10,316 |
No | output | 1 | 5,158 | 7 | 10,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
Submitted Solution:
```
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
def main():
n = int(input())
s = input()
s = list(s)
# print(s)
if len(set(s)) == 1:
print(0)
return
a = []
for i in range(n - 1):
if s[i] == 'W' and s[i + 1] == 'B':
s[i] = 'B'
s[i + 1] = 'W'
a.append(i + 1)
elif s[i] == 'W' and s[i + 1] == 'W':
a.append(i + 1)
s[i] = 'B'
s[i + 1] = 'B'
if len(set(s)) > 1:
print(-1)
else:
print(len(a))
print(*a)
return
if __name__ == "__main__":
main()
``` | instruction | 0 | 5,159 | 7 | 10,318 |
No | output | 1 | 5,159 | 7 | 10,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
Submitted Solution:
```
import sys,math,bisect
from random import randint
inf = float('inf')
mod = (10**9)+7
"========================================"
def lcm(a,b):
return int((a/math.gcd(a,b))*b)
def gcd(a,b):
return int(math.gcd(a,b))
def tobinary(n):
return bin(n)[2:]
def binarySearch(a,x):
i = bisect.bisect_left(a,x)
if i!=len(a) and a[i]==x:
return i
else:
return -1
def lowerBound(a, x):
i = bisect.bisect_left(a, x)
if i:
return (i-1)
else:
return -1
def upperBound(a,x):
i = bisect.bisect_right(a,x)
if i!= len(a)+1 and a[i-1]==x:
return (i-1)
else:
return -1
def primesInRange(n):
ans = []
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
for p in range(2, n+1):
if prime[p]:
ans.append(p)
return ans
def primeFactors(n):
factors = []
while n % 2 == 0:
factors.append(2)
n = n // 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
factors.append(i)
n = n // i
if n > 2:
factors.append(n)
return factors
def isPrime(n,k=5):
if (n <2):
return True
for i in range(0,k):
a = randint(1,n-1)
if(pow(a,n-1,n)!=1):
return False
return True
"========================================="
"""
n = int(input())
n,k = map(int,input().split())
arr = list(map(int,input().split()))
"""
from collections import deque,defaultdict,Counter
import heapq,string
n=int(input())
s=input()
freq = {}
for i in s:
if i in freq:
freq[i]+=1
else:
freq[i]=1
if 'B' not in s or 'W' not in s:
print(0)
elif freq['B']%2!=0 and freq['W']%2!=0:
print(-1)
else:
even = []
if freq['B']%2==0:
for i in range(n):
if s[i]=='B':
even.append(i+1)
else:
for i in range(n):
if s[i]=='W':
even.append(i+1)
ans = []
cnt = 0
for i in range(len(even)-1):
if even[i]+1==even[i+1]:
x,y=even[i],even[i+1]
cnt+=1
ans.append(even[i])
even[i]=-1
even[i+1]=-1
newEven = [ ]
for i in even:
if i!=-1:
newEven.append(i)
for i in range(1,len(newEven)):
cnt+=(newEven[i]-newEven[i-1])
for i in range(len(newEven)-1):
for j in range(newEven[i],newEven[i+1]):
ans.append(j)
print(cnt)
print(*ans)
``` | instruction | 0 | 5,160 | 7 | 10,320 |
No | output | 1 | 5,160 | 7 | 10,321 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2 | instruction | 0 | 5,697 | 7 | 11,394 |
"Correct Solution:
```
color = set(input().split())
print(len(color))
``` | output | 1 | 5,697 | 7 | 11,395 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2 | instruction | 0 | 5,698 | 7 | 11,396 |
"Correct Solution:
```
L = set(map(int, input().split()))
print(len(L))
``` | output | 1 | 5,698 | 7 | 11,397 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2 | instruction | 0 | 5,699 | 7 | 11,398 |
"Correct Solution:
```
s = {x for x in input().split()}
print(len(s))
``` | output | 1 | 5,699 | 7 | 11,399 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2 | instruction | 0 | 5,700 | 7 | 11,400 |
"Correct Solution:
```
S = set(input().split())
print(len(S))
``` | output | 1 | 5,700 | 7 | 11,401 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2 | instruction | 0 | 5,701 | 7 | 11,402 |
"Correct Solution:
```
st=set(input().split())
print(len(st))
``` | output | 1 | 5,701 | 7 | 11,403 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2 | instruction | 0 | 5,702 | 7 | 11,404 |
"Correct Solution:
```
str = input().split()
print(len(set(str)))
``` | output | 1 | 5,702 | 7 | 11,405 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2 | instruction | 0 | 5,703 | 7 | 11,406 |
"Correct Solution:
```
x = list(map(int,input().split()))
print(len(set(x)))
``` | output | 1 | 5,703 | 7 | 11,407 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2 | instruction | 0 | 5,704 | 7 | 11,408 |
"Correct Solution:
```
inks = input().split()
print(len(set(inks)))
``` | output | 1 | 5,704 | 7 | 11,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2
Submitted Solution:
```
List=input().split()
print(len(list(set(List))))
``` | instruction | 0 | 5,705 | 7 | 11,410 |
Yes | output | 1 | 5,705 | 7 | 11,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2
Submitted Solution:
```
col = set(map(int,input().split()))
print (len(col))
``` | instruction | 0 | 5,706 | 7 | 11,412 |
Yes | output | 1 | 5,706 | 7 | 11,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2
Submitted Solution:
```
c = input().split()
print(len(list(set(c))))
``` | instruction | 0 | 5,707 | 7 | 11,414 |
Yes | output | 1 | 5,707 | 7 | 11,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2
Submitted Solution:
```
a=set(input().split())
print(len(a))
``` | instruction | 0 | 5,708 | 7 | 11,416 |
Yes | output | 1 | 5,708 | 7 | 11,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2
Submitted Solution:
```
a=input().split()
#a=int(input())
#b=int(input())
#c=int(input())
#d=int(input())
if int(a[0])==int(a[1])==int(a[2]):
print(3)
elif int(a[0])!=int(a[1])!=int(a[2]):
print(1)
else:
print(2)
``` | instruction | 0 | 5,709 | 7 | 11,418 |
No | output | 1 | 5,709 | 7 | 11,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2
Submitted Solution:
```
penki = [i for i in map(int, input().split())]
count = 3
if penki[0] == penki[1]:
count -= 1
if penki[0] == penki[2]:
count -= 1
if penki[1] == penki[2]:
count -= 1
print(count)
``` | instruction | 0 | 5,710 | 7 | 11,420 |
No | output | 1 | 5,710 | 7 | 11,421 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2
Submitted Solution:
```
a, b, c = map(int, input().split())
cnt = 3
if a == b or b == c:
cnt -= 1
if b == c or a == c:
cnt -= 1
print(cnt)
``` | instruction | 0 | 5,711 | 7 | 11,422 |
No | output | 1 | 5,711 | 7 | 11,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
Constraints
* 1≦a,b,c≦100
Input
The input is given from Standard Input in the following format:
a b c
Output
Print the number of different kinds of colors of the paint cans.
Examples
Input
3 1 4
Output
3
Input
3 3 33
Output
2
Submitted Solution:
```
penki = input().split(" ")
if penki[0] == penki[1]:
print("2")
if penki[1] == penki[2]:
print("1")
else:
print("3")
``` | instruction | 0 | 5,712 | 7 | 11,424 |
No | output | 1 | 5,712 | 7 | 11,425 |
Provide a correct Python 3 solution for this coding contest problem.
There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same.
Two cubes are said to be identically colored if some suitable rotations of one of the cubes give identical looks to both of the cubes. For example, two cubes shown in Figure 2 are identically colored. A set of cubes is said to be identically colored if every pair of them are identically colored.
A cube and its mirror image are not necessarily identically colored. For example, two cubes shown in Figure 3 are not identically colored.
You can make a given set of cubes identically colored by repainting some of the faces, whatever colors the faces may have. In Figure 4, repainting four faces makes the three cubes identically colored and repainting fewer faces will never do.
Your task is to write a program to calculate the minimum number of faces that needs to be repainted for a given set of cubes to become identically colored.
Input
The input is a sequence of datasets. A dataset consists of a header and a body appearing in this order. A header is a line containing one positive integer n and the body following it consists of n lines. You can assume that 1 ≤ n ≤ 4. Each line in a body contains six color names separated by a space. A color name consists of a word or words connected with a hyphen (-). A word consists of one or more lowercase letters. You can assume that a color name is at most 24-characters long including hyphens.
A dataset corresponds to a set of colored cubes. The integer n corresponds to the number of cubes. Each line of the body corresponds to a cube and describes the colors of its faces. Color names in a line is ordered in accordance with the numbering of faces shown in Figure 5. A line
color1 color2 color3 color4 color5 color6
corresponds to a cube colored as shown in Figure 6.
The end of the input is indicated by a line containing a single zero. It is not a dataset nor a part of a dataset.
<image>
<image>
<image>
Output
For each dataset, output a line containing the minimum number of faces that need to be repainted to make the set of cubes identically colored.
Example
Input
3
scarlet green blue yellow magenta cyan
blue pink green magenta cyan lemon
purple red blue yellow cyan green
2
red green blue yellow magenta cyan
cyan green blue yellow magenta red
2
red green gray gray magenta cyan
cyan green gray gray magenta red
2
red green blue yellow magenta cyan
magenta red blue yellow cyan green
3
red green blue yellow magenta cyan
cyan green blue yellow magenta red
magenta red blue yellow cyan green
3
blue green green green green blue
green blue blue green green green
green green green green green sea-green
3
red yellow red yellow red yellow
red red yellow yellow red yellow
red red red red red red
4
violet violet salmon salmon salmon salmon
violet salmon salmon salmon salmon violet
violet violet salmon salmon violet violet
violet violet violet violet salmon salmon
1
red green blue yellow magenta cyan
4
magenta pink red scarlet vermilion wine-red
aquamarine blue cyan indigo sky-blue turquoise-blue
blond cream chrome-yellow lemon olive yellow
chrome-green emerald-green green olive vilidian sky-blue
0
Output
4
2
0
0
2
3
4
4
0
16 | instruction | 0 | 5,747 | 7 | 11,494 |
"Correct Solution:
```
def rotateX(dice):
d1, d2, d3, d4, d5, d6 = dice
return [d2, d6, d3, d4, d1, d5]
def rotateY(dice):
d1, d2, d3, d4, d5, d6 = dice
return [d4, d2, d1, d6, d5, d3]
def rotateZ(dice):
d1, d2, d3, d4, d5, d6 = dice
return [d1, d3, d5, d2, d4, d6]
def check():
global n, s_count
diff = [[0 for i in range(s_count)] for j in range(6)]
for dice in color_list[:-1]:
for i in range(6):
if color_list[-1][i] != dice[i]:
diff[i][dice[i]] += 1
count = 0
for c in diff:
c_max = max(c)
c_sum = sum(c)
if n - c_max < c_sum:
count += n - c_max
else:
count += c_sum
return count
def solve(i):
global ans
if i == len(color_list) - 1:
count = check()
if ans > count:
ans = count
else:
dice_memo = []
for x in range(4):
temp_dice = rotateX(color_list[i])
for y in range(4):
temp_dice = rotateY(temp_dice)
for z in range(4):
temp_dice = rotateZ(temp_dice)
color_list[i] = temp_dice
if color_list[i] in dice_memo:
continue
dice_memo.append(color_list[i])
solve(i + 1)
while True:
n = int(input())
if n == 0:
break
memo = {}
s_count = 0
color_list = [[0 for j in range(6)] for i in range(n)]
for i in range(n):
for j, s in enumerate(input().split(" ")):
if s not in memo:
color_list[i][j] = memo.setdefault(s, s_count)
s_count += 1
else:
color_list[i][j] = memo[s]
if n == 1:
print(0)
continue
ans = float("inf")
solve(0)
print(ans)
``` | output | 1 | 5,747 | 7 | 11,495 |
Provide a correct Python 3 solution for this coding contest problem.
There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same.
Two cubes are said to be identically colored if some suitable rotations of one of the cubes give identical looks to both of the cubes. For example, two cubes shown in Figure 2 are identically colored. A set of cubes is said to be identically colored if every pair of them are identically colored.
A cube and its mirror image are not necessarily identically colored. For example, two cubes shown in Figure 3 are not identically colored.
You can make a given set of cubes identically colored by repainting some of the faces, whatever colors the faces may have. In Figure 4, repainting four faces makes the three cubes identically colored and repainting fewer faces will never do.
Your task is to write a program to calculate the minimum number of faces that needs to be repainted for a given set of cubes to become identically colored.
Input
The input is a sequence of datasets. A dataset consists of a header and a body appearing in this order. A header is a line containing one positive integer n and the body following it consists of n lines. You can assume that 1 ≤ n ≤ 4. Each line in a body contains six color names separated by a space. A color name consists of a word or words connected with a hyphen (-). A word consists of one or more lowercase letters. You can assume that a color name is at most 24-characters long including hyphens.
A dataset corresponds to a set of colored cubes. The integer n corresponds to the number of cubes. Each line of the body corresponds to a cube and describes the colors of its faces. Color names in a line is ordered in accordance with the numbering of faces shown in Figure 5. A line
color1 color2 color3 color4 color5 color6
corresponds to a cube colored as shown in Figure 6.
The end of the input is indicated by a line containing a single zero. It is not a dataset nor a part of a dataset.
<image>
<image>
<image>
Output
For each dataset, output a line containing the minimum number of faces that need to be repainted to make the set of cubes identically colored.
Example
Input
3
scarlet green blue yellow magenta cyan
blue pink green magenta cyan lemon
purple red blue yellow cyan green
2
red green blue yellow magenta cyan
cyan green blue yellow magenta red
2
red green gray gray magenta cyan
cyan green gray gray magenta red
2
red green blue yellow magenta cyan
magenta red blue yellow cyan green
3
red green blue yellow magenta cyan
cyan green blue yellow magenta red
magenta red blue yellow cyan green
3
blue green green green green blue
green blue blue green green green
green green green green green sea-green
3
red yellow red yellow red yellow
red red yellow yellow red yellow
red red red red red red
4
violet violet salmon salmon salmon salmon
violet salmon salmon salmon salmon violet
violet violet salmon salmon violet violet
violet violet violet violet salmon salmon
1
red green blue yellow magenta cyan
4
magenta pink red scarlet vermilion wine-red
aquamarine blue cyan indigo sky-blue turquoise-blue
blond cream chrome-yellow lemon olive yellow
chrome-green emerald-green green olive vilidian sky-blue
0
Output
4
2
0
0
2
3
4
4
0
16 | instruction | 0 | 5,748 | 7 | 11,496 |
"Correct Solution:
```
import copy
# 回転方法の全列挙
def turn(box):
turnlist = []
for j in range(4):
for i in range(4):
turnlist.append(box)
box = [box[0], box[3], box[1], box[4], box[2], box[5]]
box = [box[3], box[1], box[0], box[5], box[4], box[2]]
box = [box[1], box[5], box[2], box[3], box[0], box[4]]
for j in range(2):
for i in range(4):
turnlist.append(box)
box = [box[0], box[3], box[1], box[4], box[2], box[5]]
box = [box[0], box[3], box[1], box[4], box[2], box[5]]
box = [box[5], box[4], box[2], box[3], box[1], box[0]]
return turnlist
# 回転した先がどれだけ一致しているかどうかの確認
def solve():
ans = float('inf')
if n == 1:
return 0
for d1 in turn(color[0]):
if n > 2:
for d2 in turn(color[1]):
if n > 3:
for d3 in turn(color[2]):
tmp = 0
for num in range(6):
tmp += fourcheck([d1[num], d2[num], d3[num], color[3][num]])
ans = min(ans, tmp)
else:
tmp = 0
for num in range(6):
tmp += threecheck(d1[num], d2[num], color[2][num])
ans = min(ans, tmp)
else:
tmp = 0
for num in range(6):
if color[1][num] != d1[num]:
tmp += 1
ans = min(tmp, ans)
return ans
# 3つの時のチェック
def threecheck(a, b, c):
if a == b and b == c:
return 0
if a == b or b == c or c == a:
return 1
return 2
# 4つの時のチェック
def fourcheck(dlist):
tdict = {}
for check in dlist:
if check not in tdict:
tdict[check] = 0
tdict[check] += 1
if max(tdict.values()) == 4:
return 0
if max(tdict.values()) == 3:
return 1
if max(tdict.values()) == 2:
return 2
return 3
while True:
n = int(input())
if n == 0:
break
color = [input().split() for i in range(n)]
colordict = dict()
tmp = 0
for i in range(n):
for j in range(6):
if color[i][j] not in colordict.keys():
colordict[color[i][j]] = tmp
tmp += 1
color[i][j] = colordict[color[i][j]]
print(solve())
``` | output | 1 | 5,748 | 7 | 11,497 |
Provide a correct Python 3 solution for this coding contest problem.
There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same.
Two cubes are said to be identically colored if some suitable rotations of one of the cubes give identical looks to both of the cubes. For example, two cubes shown in Figure 2 are identically colored. A set of cubes is said to be identically colored if every pair of them are identically colored.
A cube and its mirror image are not necessarily identically colored. For example, two cubes shown in Figure 3 are not identically colored.
You can make a given set of cubes identically colored by repainting some of the faces, whatever colors the faces may have. In Figure 4, repainting four faces makes the three cubes identically colored and repainting fewer faces will never do.
Your task is to write a program to calculate the minimum number of faces that needs to be repainted for a given set of cubes to become identically colored.
Input
The input is a sequence of datasets. A dataset consists of a header and a body appearing in this order. A header is a line containing one positive integer n and the body following it consists of n lines. You can assume that 1 ≤ n ≤ 4. Each line in a body contains six color names separated by a space. A color name consists of a word or words connected with a hyphen (-). A word consists of one or more lowercase letters. You can assume that a color name is at most 24-characters long including hyphens.
A dataset corresponds to a set of colored cubes. The integer n corresponds to the number of cubes. Each line of the body corresponds to a cube and describes the colors of its faces. Color names in a line is ordered in accordance with the numbering of faces shown in Figure 5. A line
color1 color2 color3 color4 color5 color6
corresponds to a cube colored as shown in Figure 6.
The end of the input is indicated by a line containing a single zero. It is not a dataset nor a part of a dataset.
<image>
<image>
<image>
Output
For each dataset, output a line containing the minimum number of faces that need to be repainted to make the set of cubes identically colored.
Example
Input
3
scarlet green blue yellow magenta cyan
blue pink green magenta cyan lemon
purple red blue yellow cyan green
2
red green blue yellow magenta cyan
cyan green blue yellow magenta red
2
red green gray gray magenta cyan
cyan green gray gray magenta red
2
red green blue yellow magenta cyan
magenta red blue yellow cyan green
3
red green blue yellow magenta cyan
cyan green blue yellow magenta red
magenta red blue yellow cyan green
3
blue green green green green blue
green blue blue green green green
green green green green green sea-green
3
red yellow red yellow red yellow
red red yellow yellow red yellow
red red red red red red
4
violet violet salmon salmon salmon salmon
violet salmon salmon salmon salmon violet
violet violet salmon salmon violet violet
violet violet violet violet salmon salmon
1
red green blue yellow magenta cyan
4
magenta pink red scarlet vermilion wine-red
aquamarine blue cyan indigo sky-blue turquoise-blue
blond cream chrome-yellow lemon olive yellow
chrome-green emerald-green green olive vilidian sky-blue
0
Output
4
2
0
0
2
3
4
4
0
16 | instruction | 0 | 5,749 | 7 | 11,498 |
"Correct Solution:
```
def solve():
from itertools import product
from sys import stdin
f_i = stdin
# idices of faces
indices = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5),
(0, 4, 3, 2, 1, 5), (0, 3, 1, 4, 2, 5),
(1, 0, 3, 2, 5, 4), (1, 3, 5, 0, 2, 4),
(1, 5, 2, 3, 0, 4), (1, 2, 0, 5, 3, 4),
(2, 0, 1, 4, 5, 3), (2, 1, 5, 0, 4, 3),
(2, 5, 4, 1, 0, 3), (2, 4, 0, 5, 1, 3),
(3, 0, 4, 1, 5, 2), (3, 4, 5, 0, 1, 2),
(3, 5, 1, 4, 0, 2), (3, 1, 0, 5, 4, 2),
(4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
(4, 5, 3, 2, 0, 1), (4, 3, 0, 5, 2, 1),
(5, 1, 3, 2, 4, 0), (5, 3, 4, 1, 2, 0),
(5, 4, 2, 3, 1, 0), (5, 2, 1, 4, 3, 0))
while True:
n = int(f_i.readline())
if n == 0:
break
cubes = tuple(tuple(f_i.readline().split()) for i in range(n))
if n == 1:
print(0)
continue
cube1 = cubes[0]
cubes = cubes[1:]
cnt = 6 * (n - 1)
for tpl in product(indices, repeat=n-1):
tmp = 0
for idx, color1 in zip(zip(*tpl), cube1):
d = {color1: 1}
for c, i in zip(cubes, idx):
color = c[i]
if color in d:
d[color] += 1
else:
d[color] = 1
tmp += n - max(d.values())
if tmp >= cnt:
break
else:
cnt = tmp
print(cnt)
if __name__ == '__main__':
solve()
``` | output | 1 | 5,749 | 7 | 11,499 |
Provide a correct Python 3 solution for this coding contest problem.
There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same.
Two cubes are said to be identically colored if some suitable rotations of one of the cubes give identical looks to both of the cubes. For example, two cubes shown in Figure 2 are identically colored. A set of cubes is said to be identically colored if every pair of them are identically colored.
A cube and its mirror image are not necessarily identically colored. For example, two cubes shown in Figure 3 are not identically colored.
You can make a given set of cubes identically colored by repainting some of the faces, whatever colors the faces may have. In Figure 4, repainting four faces makes the three cubes identically colored and repainting fewer faces will never do.
Your task is to write a program to calculate the minimum number of faces that needs to be repainted for a given set of cubes to become identically colored.
Input
The input is a sequence of datasets. A dataset consists of a header and a body appearing in this order. A header is a line containing one positive integer n and the body following it consists of n lines. You can assume that 1 ≤ n ≤ 4. Each line in a body contains six color names separated by a space. A color name consists of a word or words connected with a hyphen (-). A word consists of one or more lowercase letters. You can assume that a color name is at most 24-characters long including hyphens.
A dataset corresponds to a set of colored cubes. The integer n corresponds to the number of cubes. Each line of the body corresponds to a cube and describes the colors of its faces. Color names in a line is ordered in accordance with the numbering of faces shown in Figure 5. A line
color1 color2 color3 color4 color5 color6
corresponds to a cube colored as shown in Figure 6.
The end of the input is indicated by a line containing a single zero. It is not a dataset nor a part of a dataset.
<image>
<image>
<image>
Output
For each dataset, output a line containing the minimum number of faces that need to be repainted to make the set of cubes identically colored.
Example
Input
3
scarlet green blue yellow magenta cyan
blue pink green magenta cyan lemon
purple red blue yellow cyan green
2
red green blue yellow magenta cyan
cyan green blue yellow magenta red
2
red green gray gray magenta cyan
cyan green gray gray magenta red
2
red green blue yellow magenta cyan
magenta red blue yellow cyan green
3
red green blue yellow magenta cyan
cyan green blue yellow magenta red
magenta red blue yellow cyan green
3
blue green green green green blue
green blue blue green green green
green green green green green sea-green
3
red yellow red yellow red yellow
red red yellow yellow red yellow
red red red red red red
4
violet violet salmon salmon salmon salmon
violet salmon salmon salmon salmon violet
violet violet salmon salmon violet violet
violet violet violet violet salmon salmon
1
red green blue yellow magenta cyan
4
magenta pink red scarlet vermilion wine-red
aquamarine blue cyan indigo sky-blue turquoise-blue
blond cream chrome-yellow lemon olive yellow
chrome-green emerald-green green olive vilidian sky-blue
0
Output
4
2
0
0
2
3
4
4
0
16 | instruction | 0 | 5,750 | 7 | 11,500 |
"Correct Solution:
```
def solve():
from itertools import product
from sys import stdin
f_i = stdin
# idices of faces
indices = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5),
(0, 4, 3, 2, 1, 5), (0, 3, 1, 4, 2, 5),
(1, 0, 3, 2, 5, 4), (1, 3, 5, 0, 2, 4),
(1, 5, 2, 3, 0, 4), (1, 2, 0, 5, 3, 4),
(2, 0, 1, 4, 5, 3), (2, 1, 5, 0, 4, 3),
(2, 5, 4, 1, 0, 3), (2, 4, 0, 5, 1, 3),
(3, 0, 4, 1, 5, 2), (3, 4, 5, 0, 1, 2),
(3, 5, 1, 4, 0, 2), (3, 1, 0, 5, 4, 2),
(4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
(4, 5, 3, 2, 0, 1), (4, 3, 0, 5, 2, 1),
(5, 1, 3, 2, 4, 0), (5, 3, 4, 1, 2, 0),
(5, 4, 2, 3, 1, 0), (5, 2, 1, 4, 3, 0))
while True:
n = int(f_i.readline())
if n == 0:
break
cubes = tuple(tuple(f_i.readline().split()) for i in range(n))
if n == 1:
print(0)
continue
cube1 = cubes[0]
cubes = cubes[1:]
cnt = 6 * (n - 1)
for tpl in product(indices, repeat=n-1):
tmp = 0
for idx, color1 in zip(zip(*tpl), cube1):
d = {color1: 1}
for c, i in zip(cubes, idx):
color = c[i]
if color in d:
d[color] += 1
else:
d[color] = 1
tmp += n - max(d.values())
if tmp >= cnt:
break
else:
cnt = tmp
print(cnt)
solve()
``` | output | 1 | 5,750 | 7 | 11,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | instruction | 0 | 6,349 | 7 | 12,698 |
Tags: implementation, strings
Correct Solution:
```
s = list(input())
a = ['A', 'B', 'C']
m = set(a)
f = False
for i in range(1, len(s) - 1):
a = [s[i], s[i - 1], s[i + 1]]
if set(a) == m:
print('Yes')
f = True
break
if not f:
print('No')
``` | output | 1 | 6,349 | 7 | 12,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | instruction | 0 | 6,350 | 7 | 12,700 |
Tags: implementation, strings
Correct Solution:
```
s = input()
if 'BAC' in s or 'CAB' in s or 'ABC' in s or 'CBA' in s or 'ACB' in s or 'BCA' in s:
print('Yes')
else:
print('No')
``` | output | 1 | 6,350 | 7 | 12,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | instruction | 0 | 6,351 | 7 | 12,702 |
Tags: implementation, strings
Correct Solution:
```
ch=input()
#easy
if "ABC" in ch or "ACB" in ch or "BAC" in ch or "BCA" in ch or "CAB" in ch or "CBA" in ch:
print("Yes")
else:
print("No")
``` | output | 1 | 6,351 | 7 | 12,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | instruction | 0 | 6,352 | 7 | 12,704 |
Tags: implementation, strings
Correct Solution:
```
s=input()
flag=0
for i in range(1,len(s)-1):
if(s[i]=='.'):
continue
elif (s[i]=='A' and ((s[i-1]=='B'and s[i+1]=='C') or (s[i-1]=='C' and s[i+1]=='B'))):
flag=1
break
elif (s[i]=='B' and((s[i-1]=='A' and s[i+1]=='C') or (s[i-1]=='C' and s[i+1]=='A'))):
flag=1
break
elif (s[i]=='C'and ((s[i-1]=='A'and s[i+1]=='B') or (s[i-1]=='B' and s[i+1]=='A'))):
flag=1
break
if(flag==1):
print("Yes")
elif(len(s)<3):
print("No")
elif(flag==0):
print("No")
``` | output | 1 | 6,352 | 7 | 12,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | instruction | 0 | 6,353 | 7 | 12,706 |
Tags: implementation, strings
Correct Solution:
```
s=input()
f=0
for i in range(len(s)-2):
p=[]
for j in range(i,i+3):
if s[j]!='.':
if s[j] not in p:
p.append(s[j])
#print(p)
if len(p)==3:
f=1
break
if f==1:
print("YES")
else:
print("NO")
``` | output | 1 | 6,353 | 7 | 12,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | instruction | 0 | 6,354 | 7 | 12,708 |
Tags: implementation, strings
Correct Solution:
```
string = input()
list = ['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA']
if any(substring in string for substring in list):
print("Yes")
else:
print("No")
``` | output | 1 | 6,354 | 7 | 12,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | instruction | 0 | 6,355 | 7 | 12,710 |
Tags: implementation, strings
Correct Solution:
```
a = input()
if 'ABC'in a or 'ACB'in a or'BCA'in a or 'BAC'in a or 'CBA'in a or'CAB'in a :
print("Yes")
else:
print("No")
'''
n,k= map(int,input().split())
w = 0
if n == 999983 and k == 1000:
print(999983001)
exit()
elif n ==994009 and k ==997:
print(991026974)
exit()
elif n ==999883 and k ==200:
print(199976601)
exit()
elif n ==199942 and k ==1000:
print(99971002)
exit()
elif n ==999002 and k ==457:
print(228271959)
exit()
elif n ==999995 and k ==1000:
print(199999005)
exit()
while 1:
w+=1
if (w//k)*(w%k)==n:
print(w)
break
'''
'''
'''
'''
#n,k= map(int,input().split())
#w = 0
#while 1:
# w+=1
# if (w//k)*(w%k)==n:
# print(w)
# break
'''
'''
n=int(input())
m=list(map(int,input().split()))
print(m.count(1))
for j in range(n-1):
if m[j+1]==1:
print(m[j],end=' ')
print(m[-1])
'''
'''
a = int(input())
f1 = 1
f2 = 1
if a < 3:
print(1)
exit()
cnt = 2
for i in range(a - 2):
a = f2
f2 += f1
f1 = a
cnt += f2
print(cnt)
'''
``` | output | 1 | 6,355 | 7 | 12,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | instruction | 0 | 6,356 | 7 | 12,712 |
Tags: implementation, strings
Correct Solution:
```
s=input()
print("Yes"if"ABC"in s or "ACB"in s or "BCA"in s or "BAC"in s or "CBA"in s or "CAB"in s else "No")
``` | output | 1 | 6,356 | 7 | 12,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
Submitted Solution:
```
# def iscommon(a, b):
# for i in range(2, min(a, b) + 1):
# if a % i == b % i == 0:
# return True
# else:
# return False
# for _ in range(int(input())):
# n = int(input())
# arr = [int(i) for i in input().split()]
# cnt = n
# for i in range(n - 1):
# for j in range(i + 1, n):
# if iscommon(arr[i], arr[j]):
# cnt -= 1
# break
# print(cnt)
s = input()
check = {'ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA'}
if any(i in s for i in check):
print('Yes')
else:
print('No')
``` | instruction | 0 | 6,357 | 7 | 12,714 |
Yes | output | 1 | 6,357 | 7 | 12,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
Submitted Solution:
```
s = input()
print(('No', 'Yes')[any(set(s[i:i+3]) == set('ABC') for i in range(len(s) - 2))])
``` | instruction | 0 | 6,358 | 7 | 12,716 |
Yes | output | 1 | 6,358 | 7 | 12,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
Submitted Solution:
```
n=input()
a=0
for i in range(1,len(n)-1):
if n[i]!="." and n[i-1]!="." and n[i+1]!="." and n[i]!=n[i+1] and n[i]!=n[i-1] and n[i-1]!=n[i+1]:
print("Yes")
a=1
break
if a==0:
print("NO")
``` | instruction | 0 | 6,359 | 7 | 12,718 |
Yes | output | 1 | 6,359 | 7 | 12,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
Submitted Solution:
```
s=input()
if 'ABC' in s or 'BAC' in s or 'CBA' in s or 'ACB' in s or 'BCA' in s or 'CAB' in s:
print('Yes')
else:
print('No')
``` | instruction | 0 | 6,360 | 7 | 12,720 |
Yes | output | 1 | 6,360 | 7 | 12,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
Submitted Solution:
```
#Winners never quit, Quitters never win............................................................................
from collections import deque as de
import math
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
class My_stack():
def __init__(self):
self.data = []
def my_push(self, x):
return (self.data.append(x))
def my_pop(self):
return (self.data.pop())
def my_peak(self):
return (self.data[-1])
def my_contains(self, x):
return (self.data.count(x))
def my_show_all(self):
return (self.data)
def isEmpty(self):
return len(self.data)==0
arrStack = My_stack()
def decimalToBinary(n):
return bin(n).replace("0b", "")
def binarytodecimal(n):
return int(n,2)
def isPrime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def get_prime_factors(number):
prime_factors = []
while number % 2 == 0:
prime_factors.append(2)
number = number / 2
for i in range(3, int(math.sqrt(number)) + 1, 2):
while number % i == 0:
prime_factors.append(int(i))
number = number / i
if number > 2:
prime_factors.append(int(number))
return prime_factors
def get_frequency(list):
dic={}
for ele in list:
if ele in dic:
dic[ele] += 1
else:
dic[ele] = 1
return dic
def Log2(x):
return (math.log10(x) /
math.log10(2));
# Function to get product of digits
def getProduct(n):
product = 1
while (n != 0):
product = product * (n % 10)
n = n // 10
return product
def isPowerOfTwo(n):
return (math.ceil(Log2(n)) == math.floor(Log2(n)));
def ceildiv(x,y): return (x+y-1)//y #ceil function gives wrong answer after 10^17 so i have to create my own :)
# because i don't want to doubt on my solution of 900-1000 problem set.
def di():return map(int, input().split())
def li():return list(map(int, input().split()))
#Here we go......................
#Winners never quit, Quitters never win
#concentration and mental toughness are margins of victory
s=input()
ch=1
for i in range(len(s)-3):
if len(set(s[i:i+3]))==3:
print("YES")
ch=0
break
if ch:
print("NO")
``` | instruction | 0 | 6,361 | 7 | 12,722 |
No | output | 1 | 6,361 | 7 | 12,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
Submitted Solution:
```
s = input()
flag = True
for i in range(len(s)-3):
s2 = s[i:i+3]
l = list(s)
st = set(l)
if(len(l)==len(st)):
print("Yes")
flag=False
if(flag):
print("No")
``` | instruction | 0 | 6,362 | 7 | 12,724 |
No | output | 1 | 6,362 | 7 | 12,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
Submitted Solution:
```
s = input()
if len(s)<3:
for i in range(1,len(s)-1):
if sorted([s[i-1],s[i],s[i+1]]) == ['A','B','C']:
b = 'yes'
break
else:
b = 'no'
print(b)
else:
print('no')
``` | instruction | 0 | 6,363 | 7 | 12,726 |
No | output | 1 | 6,363 | 7 | 12,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input
The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
Note
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
Submitted Solution:
```
baccab = input()
if 'BAC' in baccab:
print('Yes')
elif 'CAB' in baccab:
print('Yes')
elif 'ABC' in baccab:
print('Yes')
else:
print('No')
``` | instruction | 0 | 6,364 | 7 | 12,728 |
No | output | 1 | 6,364 | 7 | 12,729 |
Provide a correct Python 3 solution for this coding contest problem.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Examples
Input
4 3
1 2 1 3
1 3
2 4
3 3
Output
2
3
1
Input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
Output
1
2
2
1
2
2
6
3
3
3 | instruction | 0 | 6,365 | 7 | 12,730 |
"Correct Solution:
```
class fenwick_tree:
"""
区間の一点更新と,区間和の取得がO(log n)で可能なデータ構造
1-indexedで実装
"""
def __init__(self, N):
self.size = N
self.tree = [0] * (N+1)
def sum_until(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & (-i)
return s
def sum_acc(self, i, j):
""" [i,j] の和を返す """
return self.sum_until(j) - self.sum_until(i-1)
def add(self, i, x):
if i <= 0:
return
while i <= self.size:
self.tree[i] += x
i += i & (-i)
def main():
N, Q = (int(i) for i in input().split())
C = [int(i) for i in input().split()]
Query = [[] for _ in range(N+1)]
for j in range(Q):
le, ri = (int(i) for i in input().split())
Query[ri].append((le, j))
Query.append((-1, -1, -1))
lastappend = [-1] * (N + 1)
bit = fenwick_tree(N)
ans = [0]*Q
for i, a in enumerate(C, start=1):
if lastappend[a] != -1:
bit.add(lastappend[a], -1)
lastappend[a] = i
bit.add(i, 1)
for (le, j) in Query[i]:
ri = i
ans[j] = bit.sum_acc(le, ri)
print(*ans, sep="\n")
if __name__ == '__main__':
main()
``` | output | 1 | 6,365 | 7 | 12,731 |
Provide a correct Python 3 solution for this coding contest problem.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Examples
Input
4 3
1 2 1 3
1 3
2 4
3 3
Output
2
3
1
Input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
Output
1
2
2
1
2
2
6
3
3
3 | instruction | 0 | 6,366 | 7 | 12,732 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
class BitSum:
def __init__(self, n):
self.n = n + 1
self.table = [0] * self.n
def add(self, i, x):
i += 1
while i < self.n:
self.table[i] += x
i += i & -i
def sum(self, i):
i += 1
res = 0
while i > 0:
res += self.table[i]
i -= i & -i
return res
n,q=MI()
cc=LI()
lri=[]
mx=500005
#mx=10
for i in range(q):
l,r=MI()
l-=1
lri.append((l,r-1,i))
lri.sort(key=lambda x:x[1])
#print(lri)
last=[-1]*mx
st=BitSum(mx)
ans=[0]*q
now=0
for l,r,i in lri:
for j in range(now,r+1):
c=cc[j]
pre=last[c]
if pre!=-1:st.add(pre,-1)
last[c]=j
st.add(j,1)
#print(l,r,st.tree,last)
now=r+1
ans[i]=st.sum(r)-st.sum(l-1)
print(*ans,sep="\n")
``` | output | 1 | 6,366 | 7 | 12,733 |
Provide a correct Python 3 solution for this coding contest problem.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Examples
Input
4 3
1 2 1 3
1 3
2 4
3 3
Output
2
3
1
Input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
Output
1
2
2
1
2
2
6
3
3
3 | instruction | 0 | 6,367 | 7 | 12,734 |
"Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
N,Q = map(int,input().split())
BIT = [0]*(N+1)
def BIT_query(idx):
res_sum = 0
while idx > 0:
res_sum += BIT[idx]
idx -= idx&(-idx)
return res_sum
def BIT_update(idx,x):
while idx <= N:
BIT[idx] += x
idx += idx&(-idx)
return
c = [0]+list(map(int,input().split()))
lastAppeared = [-1]*(N+1)
ans = [0]*Q
queries = []
for q in range(Q):
l,r = map(int,input().split())
queries.append(r*10**12+l*10**6+q)
queries.sort()
curR = 0
for i in range(Q):
query = queries[i]
r = query//10**12
query %= 10**12
l = query//10**6
q = query % 10**6
while curR < r:
curR += 1
color = c[curR]
last = lastAppeared[color]
if last != -1:
BIT_update(last,-1)
lastAppeared[color] = curR
BIT_update(curR,1)
ans[q] = BIT_query(r)-BIT_query(l-1)
for i in range(Q):
print(ans[i])
``` | output | 1 | 6,367 | 7 | 12,735 |
Provide a correct Python 3 solution for this coding contest problem.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Examples
Input
4 3
1 2 1 3
1 3
2 4
3 3
Output
2
3
1
Input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
Output
1
2
2
1
2
2
6
3
3
3 | instruction | 0 | 6,368 | 7 | 12,736 |
"Correct Solution:
```
def solve():
import sys
input = sys.stdin.readline
class FenwickTree:
def __init__(self, size):
self.size = size
self.array = [0]*size
def add(self, index, value):
while index < self.size:
self.array[index] += value
index += index&(-index)
def sum(self, index):
answer = 0
while index > 0:
answer += self.array[index]
index -= index&(-index)
return answer
def rangesum(self, start, end):
return self.sum(end)-self.sum(start-1)
N, Q = map(int, input().split())
*c, = map(int, input().split())
tree = FenwickTree(N+1)
m = [tuple(map(int, input().split()))+(i,) for i in range(Q)]
m.sort(key=lambda x:x[1])
right = 0
pos = [-1] * (N+1)
ans = [-1] * (Q)
for l, r, idx in m:
for i in range(right, r):
x = pos[c[i]]
if x != -1:
tree.add(x, -1)
pos[c[i]] = i+1
tree.add(i+1, 1)
ans[idx] = tree.rangesum(l, r)
right = r
for i in ans:
print(i)
solve()
``` | output | 1 | 6,368 | 7 | 12,737 |
Provide a correct Python 3 solution for this coding contest problem.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Examples
Input
4 3
1 2 1 3
1 3
2 4
3 3
Output
2
3
1
Input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
Output
1
2
2
1
2
2
6
3
3
3 | instruction | 0 | 6,369 | 7 | 12,738 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
C = [0] + list(map(int, input().split()))
D = [-1]*(n+1)
A = [0]*q
U = 10**6
LR = tuple(tuple(map(int, input().split())) for _ in range(q))
W = tuple(sorted(r*U+i for i, (l, r) in enumerate(LR)))
B = [0]*(n+1)
def add(i, a):
while i <= n:
B[i] += a
i += i & -i
def acc(i):
res = 0
while i:
res += B[i]
i -= i & -i
return res
temp = 1
for w in W:
r, i = divmod(w, U)
while temp <= r:
c = C[temp]
add(temp, 1)
if D[c] != -1:
add(D[c], -1)
D[c] = temp
temp += 1
l = LR[i][0]
A[i] = acc(r) - acc(l-1)
print(*A, sep="\n")
``` | output | 1 | 6,369 | 7 | 12,739 |
Provide a correct Python 3 solution for this coding contest problem.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Examples
Input
4 3
1 2 1 3
1 3
2 4
3 3
Output
2
3
1
Input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
Output
1
2
2
1
2
2
6
3
3
3 | instruction | 0 | 6,370 | 7 | 12,740 |
"Correct Solution:
```
def main():
import sys
input = sys.stdin.readline
class BIT:
def __init__(self,n):
self.size = n
self.tree = [0]*(n+1)
def add(self,i,x):
while i <= self.size:
self.tree[i] += x
i += i&-i
def sum(self,i):
s = 0
while i > 0:
s += self.tree[i]
i -= i&-i
return s
N,Q = map(int,input().split())
C = list(map(int,input().split()))
LR = []
for i in range(Q):
l,r = map(int,input().split())
LR.append((l,r,i))
bit = BIT(N)
#color[i] => 色iが最後に登場したインデックス(1-indexed)
color = [0]*(N+1)
ANS = [0]*Q
LR.sort(key=lambda x: x[1])
cur = 1
for l,r,j in LR:
for i in range(cur,r+1):
c = C[i-1]
if color[c] != 0:
bit.add(color[c],-1)
color[c] = i
bit.add(i,1)
cur = r+1
ANS[j] = bit.sum(r)-bit.sum(l-1)
for a in ANS:
print(a)
main()
``` | output | 1 | 6,370 | 7 | 12,741 |
Provide a correct Python 3 solution for this coding contest problem.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Examples
Input
4 3
1 2 1 3
1 3
2 4
3 3
Output
2
3
1
Input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
Output
1
2
2
1
2
2
6
3
3
3 | instruction | 0 | 6,371 | 7 | 12,742 |
"Correct Solution:
```
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n+1)
def sum(self, i): # sum in [0, i)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x): # i > 0
assert i > 0
while i <= self.size:
self.tree[i] += x
i += i & -i
N, Q = map(int, input().split())
c = list(map(int, input().split()))
lr = []
for i in range(Q):
l, r = map(int, input().split())
lr.append([l-1, r-1, i])
lr.sort(key=lambda x: x[1])
rightest = [-1] * (N + 1)
current_q = 0
bit = Bit(N)
ans = [0] * Q
for i in range(N):
if rightest[c[i]] != -1:
bit.add(rightest[c[i]]+1, -1)
rightest[c[i]] = i
bit.add(i+1, 1)
while current_q < Q and lr[current_q][1] == i:
ans[lr[current_q][2]] = bit.sum(lr[current_q][1] + 1) - bit.sum(lr[current_q][0])
current_q += 1
for i in range(Q):
print(ans[i])
``` | output | 1 | 6,371 | 7 | 12,743 |
Provide a correct Python 3 solution for this coding contest problem.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
Constraints
* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Examples
Input
4 3
1 2 1 3
1 3
2 4
3 3
Output
2
3
1
Input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
Output
1
2
2
1
2
2
6
3
3
3 | instruction | 0 | 6,372 | 7 | 12,744 |
"Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
# 足す時はi番目に足し、返すのは累積和
class sumBIT():
def __init__(self, N):
self.N = N
self.bit = [0 for _ in range(self.N+1)]
def __str__(self):
ret = []
for i in range(1, self.N+1):
ret.append(self.__getitem__(i))
return "[" + ", ".join([str(a) for a in ret]) + "]"
def __getitem__(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.N:
self.bit[i] += x
i += i & -i
N, Q = map(int, input().split())
C = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(Q)]
Toask = [[] for _ in range(N+1)]
for i, (l, r) in enumerate(LR):
Toask[l].append((r, i))
bit = sumBIT(N+3)
ans = [-1]*Q
Color = [-1]*(N+1)
for l in reversed(range(1, N+1)):
c = C[l-1]
if Color[c] != -1:
last = Color[c]
bit.add(last, -1)
bit.add(l, 1)
for r, ind in Toask[l]:
ans[ind] = str(bit[r])
Color[c] = l
print("\n".join(ans))
``` | output | 1 | 6,372 | 7 | 12,745 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.