text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland prime numbers are fashionable β the respectable citizens dwell only on the floors with numbers that are prime numbers. The numismatists value particularly high the coins with prime nominal values. All the prime days are announced holidays!
Yet even this is not enough to make the Berland people happy. On the main street of the capital stand n houses, numbered from 1 to n. The government decided to paint every house a color so that the sum of the numbers of the houses painted every color is a prime number.
However it turned out that not all the citizens approve of this decision β many of them protest because they don't want many colored houses on the capital's main street. That's why it is decided to use the minimal possible number of colors. The houses don't have to be painted consecutively, but every one of n houses should be painted some color. The one-colored houses should not stand consecutively, any way of painting is acceptable.
There are no more than 5 hours left before the start of painting, help the government find the way when the sum of house numbers for every color is a prime number and the number of used colors is minimal.
Input
The single input line contains an integer n (2 β€ n β€ 6000) β the number of houses on the main streets of the capital.
Output
Print the sequence of n numbers, where the i-th number stands for the number of color for house number i. Number the colors consecutively starting from 1. Any painting order is allowed. If there are several solutions to that problem, print any of them. If there's no such way of painting print the single number -1.
Examples
Input
8
Output
1 2 2 1 1 1 1 2
Submitted Solution:
```
#import sys
#import itertools
#import math
#t = int(input())
t = 1
while t > 0:
#print(t)
n = int(input())
res = []
res.append(1)
res.append(2)
n-=2
for _ in range(n):
res.append(1)
print(" ".join(str(x) for x in res))
t -= 1
```
No
| 88,800 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Tags: brute force, implementation, math, number theory
Correct Solution:
```
def gcd(a, b):
if(a == 0 or b == 0): return a + b
else: return gcd(b, a % b);
l, r = map(int, input().split())
r = r + 1
for a in range(l, r):
for b in range(a + 1, r):
for c in range(b + 1, r):
if(gcd(a, b) == 1 and gcd(b, c) == 1 and gcd(a, c) != 1):
print(str(a) + " " + str(b) + " " + str(c))
exit(0)
print(-1)
```
| 88,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Tags: brute force, implementation, math, number theory
Correct Solution:
```
import sys
le, rg = map(int, input().split())
rg += 1
def gcd(a, b):
while b:
a, b = b, a % b
return a
for a in range(le, rg):
for b in range(a + 1, rg):
gab = gcd(a, b)
if gab != 1:
continue
for c in range(b + 1, rg):
if gcd(b, c) == 1 and gcd(a, c) > 1:
print(a, b, c)
sys.exit(0)
print(-1)
```
| 88,802 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Tags: brute force, implementation, math, number theory
Correct Solution:
```
l, r = map(int, input().split())
if r - l + 1 < 3 or (r - l + 1 == 3 and l % 2 == 1):
print(-1)
else:
base = l % 2 + l
ans = [base, base+1, base+2]
print(*ans, sep=' ')
```
| 88,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Tags: brute force, implementation, math, number theory
Correct Solution:
```
inp = input().split(' ')
a = int(inp[0])
b = int(inp[1])
if (b-a)<2:
print(-1)
elif (b-a) == 2 and b%2 == 1:
print(-1)
else:
if a%2 == 1:
a = a + 1
print(a,a+1,a+2)
```
| 88,804 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Tags: brute force, implementation, math, number theory
Correct Solution:
```
# t=int(input())
t=1
# see u codeforces on 11-07-2020..bye bye
for _ in range(t):
# n=int(input())
n,m=map(int,input().split())
# l=list(map(int,input().split()))
if(n&1):
n+=1
if(n+2>m):
print(-1)
else:
print(n,n+1,n+2)
```
| 88,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Tags: brute force, implementation, math, number theory
Correct Solution:
```
import sys,random
def gcd(x,y):
if y==0:
return x
else:
return gcd(y,x%y)
def pollard(n):
i = 1
x = random.randint(0,n-1)
y = x
k = 2
while True:
i = i+1
x = (x*x - 1)%n
d = gcd(y-x,n)
if d!=1 and d!=n:
print(d)
if i == k:
y = x
k = 2*k
def div(a,b):
c = a+2
while not (gcd(c,a)!=1 and gcd(c,b)==1):
c+=1
return c
def iff(l,r):
if r-l <=1:
return -1
a = l
b = l+1
c = div(a,b)
return a,b,c
l,r = map(int,input().split())
if l%2!=0:
l+=1
if r-l <=1:
print(-1)
else:
print(l,l+1,l+2)
```
| 88,806 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Tags: brute force, implementation, math, number theory
Correct Solution:
```
l, r = map(int, input().split())
if l % 2 != 0:
l += 1
if l + 2 > r:
print(-1)
else:
print(l, l+1, l+2)
```
| 88,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Tags: brute force, implementation, math, number theory
Correct Solution:
```
if __name__ == '__main__':
l, r = [int(i) for i in input().split()]
if r - l < 2: print(-1)
elif l % 2 == 0: print(l, l + 1, l + 2)
elif r - l > 2: print(l + 1, l + 2, l + 3)
else: print(-1)
```
| 88,808 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Submitted Solution:
```
l, r = map(int, input().split())
l += l % 2
if (r - l < 2):
print(-1)
else:
print(l, l + 1, l + 2)
```
Yes
| 88,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Submitted Solution:
```
from math import gcd
l,r=map(int,input().split())
res=False
for a in range(l,r+1):
for b in range(a+1,r+1):
for c in range(b+1,r+1):
if gcd(a,b)==1 and gcd(b,c)==1 and gcd(a,c)!=1:
print(str(a)+' '+str(b)+' '+str(c))
res=True
break
if res:
break
if res:
break
if not res:
print(-1)
```
Yes
| 88,810 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Submitted Solution:
```
l, r = map(int, input().split())
if r - l < 2:
print('-1')
if r - l == 2 and l % 2 == 1:
print('-1')
if r - l >= 2 and l % 2 == 0:
print(l, l + 1, l + 2)
if r - l > 2 and l % 2 == 1:
print(l + 1, l + 2, l + 3)
```
Yes
| 88,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Submitted Solution:
```
# In this template you are not required to write code in main
import sys
inf = float("inf")
#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd
#from bisect import bisect_left,bisect_right
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod,MOD=1000000007,998244353
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
l,r=get_ints()
flag=0
for i in range(l,r-1):
for j in range(i+1,r):
for k in range(j+1,r+1):
if gcd(i,j)==1 and gcd(j,k)==1 and gcd(i,k)!=1:
flag=1
store1,store2,store3=i,j,k
break
if flag==1:
break
if flag==1:
break
if flag==1:
print(store1,store2,store3)
else:
print(-1)
```
Yes
| 88,812 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Submitted Solution:
```
a,b=map(int,input().split())
if((b-a)==1):
print(-1)
else:
if(a%3==0):
print(a,a+1,a+12)
elif(a%2==0):
print(a,a+1,a+2)
else:
if((b-a)<3):
if(a%2==0):
print(a,a+1,a+2)
else:
print(-1)
```
No
| 88,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Submitted Solution:
```
import math
a,b=input().split(" ")
a=int(a)
b=int(b)
if(b-a==1):
print(-1)
else:
x = math.gcd(a,b)
i=a+1
while(i<=i+x):
if(math.gcd(i,a)==math.gcd(i,b)):
print(a,i,b)
exit(0)
print(-1)
```
No
| 88,814 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Submitted Solution:
```
l,r=map(int,input().split())
c=-1
if l==r or r-l==1:
print(-1)
c=1
if l%2==0 and c!=1:
print(l,l+1,l+2)
c=1
if l%2!=0 and c!=1:
print(l+1,l+2,l+3)
c=1
if c!=1:
print(c)
```
No
| 88,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l β€ a < b < c β€ r.
More specifically, you need to find three numbers (a, b, c), such that l β€ a < b < c β€ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
Input
The single line contains two positive space-separated integers l, r (1 β€ l β€ r β€ 1018; r - l β€ 50).
Output
Print three positive space-separated integers a, b, c β three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Examples
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
Submitted Solution:
```
import math
buff = input().split(" ")
l = int(buff[0])
r = int(buff[1])
a = l
b = l + 1
c = -1
for i in range(b + 1, r + 1):
if math.gcd(a, i) != 1:
c = i
break
if c != -1:
print(a, b, c)
else:
print(-1)
```
No
| 88,816 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Tags: greedy, implementation, sortings
Correct Solution:
```
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = [(arr[i], i) for i in range(n)]
arr.sort()
t = 0
res = []
for i in arr:
res.append(i)
if(sum([i[0] for i in res])>k):
res = res[:-1]
break
if(len(res)==0):
print('0')
else:
print(len(res))
print(' '.join([str(i[1]+1) for i in res]))
```
| 88,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Tags: greedy, implementation, sortings
Correct Solution:
```
k, n = map(int,input().split())
temp = input().split()
data = []
i = 1
for item in temp:
data.append([int(item),i])
i += 1
data.sort()
cost = 0
answer = []
for item in data:
if (item[0]+cost)<=n:
cost += item[0]
answer.append(item[1])
else:
break
print(len(answer))
if(len(answer) != 0):
for i in range(len(answer)-1):
print(answer[i],end=' ')
print(answer[-1])
```
| 88,818 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Tags: greedy, implementation, sortings
Correct Solution:
```
n,k=map(int,input().split())
l=list(map(int,input().split()))
p=sorted(l)
s=0
a=[]
c=0
for i in range(n):
if(p[i]+s)<=k:
s=s+p[i]
c=c+1
z=l.index(p[i])
a.append(z+1)
l[z]=0
print(c)
print(*a)
```
| 88,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Tags: greedy, implementation, sortings
Correct Solution:
```
n, k = map(int, input().split())
a = [(i, e) for i, e in enumerate(map(int, input().split()))]
a.sort(key=lambda x: x[1])
s, d = 0, []
for i, e in a:
if s + e <= k:
s += e
d.append(i + 1)
else:
break
print(len(d))
for i in d:
print(i, end=' ')
```
| 88,820 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Tags: greedy, implementation, sortings
Correct Solution:
```
n,k=map(int,input().split())
l=sorted([(x,i) for i,x in enumerate(map(int,input().split()),1)])
s=[]
for i in range(n):
if l[i][0]>k: break
s+=[l[i][1]]
k-=l[i][0]
print(len(s))
print(' '.join(map(str,s)))
```
| 88,821 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Tags: greedy, implementation, sortings
Correct Solution:
```
n,k = map(int, input().split())
a = input().split()
def ke(n):
return n[1]
for i in range(n):
a[i] = [i,int(a[i])]
a.sort(key=ke)
s = 0
i = 0
answ = 0
answ_v=[]
while True:
if i == n:
break
if s+a[i][1]>k:
break
s += a[i][1]
answ+=1
answ_v.append(a[i][0]+1)
i+=1
print(answ)
for i in answ_v:
print(i,end=" ")
```
| 88,822 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Tags: greedy, implementation, sortings
Correct Solution:
```
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=[(a[i],i+1) for i in range(len(a))]
#print(a)
l=0
a.sort()
for i in a:
k-=i[0]
if(k<0):
break
l+=1
if(l==0):
print(l)
else:
print(l)
for i in a[:l]:
print(i[1],end=" ")
```
| 88,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Tags: greedy, implementation, sortings
Correct Solution:
```
a,k = map(int,input().split())
ls = list(map(int,input().split()))
nls = []
for i in ls:
nls.append(i)
ls.sort()
ind = []
ins = 0
for i in range(a):
if ls[i] <= k and ins <= k:
if ins + ls[i]>k:
break
else:
ins += ls[i]
ind.append(nls.index(ls[i])+1)
nls[nls.index(ls[i])] = "l"
print(len(ind))
for i in sorted(ind):
print(i,end = " ")
```
| 88,824 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Submitted Solution:
```
n,k=map(int,input().split())
l=list(map(int,input().split()))
new=[]
ans=[]
s=0
for i in range(n):
new.append([l[i],i+1])
new.sort()
for i in range(n):
s+=new[i][0]
if(s<=k):
ans.append(new[i][1])
else:
break
if(len(ans)==0):
print(0)
else:
print(len(ans))
print(*ans)
```
Yes
| 88,825 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Submitted Solution:
```
s=list(map(int,input().split()))
l=list(map(int,input().split()))
s1=sorted(l)
su=0
idx={}
for i in range(len(l)):
try:
idx[l[i]].append(i)
except:
idx[l[i]]=[i]
x=[]
for i in s1:
su+=i
if(su<=s[1]):
x.append(idx[i][0]+1)
idx[i].pop(0)
print(len(x))
if(len(x)!=0):
print(*x,sep=" ")
```
Yes
| 88,826 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Submitted Solution:
```
x,y = list(map(int,input().split()))
arr = list(map(int,input().split()))
copy = list(arr)
arr = sorted(arr)
count, i = 0,0
res = []
while ((count<=y) & (i<x)):
if (count + arr[i] <=y):
res.append(copy.index(arr[i])+1)
copy[copy.index(arr[i])] = -1
count += arr[i]
i+=1
else:
break
print (i)
if (i!=0):
res = map(str,res)
print (" ".join(res))
```
Yes
| 88,827 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Submitted Solution:
```
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = a.copy();d=1
l=list([0]);vis=[0]*n
sumo,cnt,j=0,0,0
a.sort()
for i in range(n):
if sumo+a[i]<=k:
sumo+=a[i];
for j in range(n):
if a[i]==b[j] and vis[j]==0:
vis[j]=1;l.append(j+1);break
print(len(l)-1)
for i in l[1:]:
print(i,end=" ")
```
Yes
| 88,828 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Submitted Solution:
```
n, k = map(int, input().split())
k_1 = list(map(int, input().split()))
summ = 0
index = []
for i in range(len(k_1)):
if (summ + k_1[i]) <= k:
summ += k_1[i]
index.append(i+1)
if len(index) == 0:
print(0)
else:
print(len(index))
for i in index:
print(i, end=" ")
```
No
| 88,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Submitted Solution:
```
n,k=map(int,input().split(" "))
a=[int(i) for i in input().split(" ")]
a=list(set(a))
z=sorted(a)
i=0
while(k!=0) and i<n:
if z[i]>k:
print(0)
break
else:
k=k-z[i]
print(z[i],end=" ")
i=i+1
```
No
| 88,830 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Submitted Solution:
```
instr, days = (int(x) for x in input().split())
# print (instr, days)
arr = [(int(y), x + 1) for x, y in enumerate(input().split())]
arr.sort()
if arr[0][0] > days:
print(0)
else:
result = []
for hard in arr:
days -= hard[0]
if days >= 0:
result.append(str(hard[1]))
else:
break
print (" ".join(result))
```
No
| 88,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input
The first line contains two numbers n, k (1 β€ n β€ 100, 0 β€ k β€ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 β€ ai β€ 100), representing number of days required to learn the i-th instrument.
Output
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Examples
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
Note
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
Submitted Solution:
```
n,k=map(int,input().split())
b=list(map(int,input().split()))
a=[]
tot=0
for i in range(n):
a.append([b[i],i+1])
tot+=a[i][0]
a.sort()
pos=0
if tot<=k:
pos=n
else:
for i in range(n):
if k>=a[i][0]:
k-=a[i][0]
else:
pos=i
break
ans=[]
for i in range(pos):
ans.append(a[i][1])
ans.sort()
print(*ans)
```
No
| 88,832 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Tags: brute force, implementation
Correct Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect, insort
from time import perf_counter
from fractions import Fraction
import copy
from copy import deepcopy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,6)))
sys.stdin = open("input.txt", "r")
# sys.stdout = open("../output.txt", "w")
except:
pass
def pmat(A):
for ele in A:
print(*ele,end="\n")
n=L()[0]
A=L()
B=[i for i in range(n)]
s=set()
ans="No"
while(tuple(A) not in s):
s.add(tuple(A))
z=1
for i in range(n):
A[i]=(A[i]+z)%n
z*=-1
if A==B:
ans="Yes"
print(ans)
endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")
```
| 88,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
l = [int(i) for i in input().split()]
d = (n - l[0]) % n
for i in range(1, n):
r = n
if i & 1 == 0:
if i >= l[i]:
r = i - l[i]
else:
r = i - l[i] + n
else:
if i <= l[i]:
r = l[i] - i
else:
r = l[i] - i + n
if r != d:
print("No")
d = -1
break
if d >= 0:
print("Yes")
```
| 88,834 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split(' ')))
count = n - a[0]
for i in range(n):
if i % 2 == 0:
a[i] = (a[i] + count + n) % n
else:
a[i] = (a[i] - count + n) % n
if a[i] != i:
print("No")
exit()
print("Yes")
```
| 88,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
diff = (n - a[0]) % n
for i in range(1, n):
if i % 2 == 0:
if (a[i] + diff) % n != i:
#print((a[i] - diff) % n, i)
print("No")
exit()
else:
if (a[i] - diff) % n != i:
#print((a[i] - diff) % n, i)
print("No")
exit()
print("Yes")
```
| 88,836 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Tags: brute force, implementation
Correct Solution:
```
n, a, move = int(input()), list(map(int, input().split())), []
for i in range(n):
if i & 1:
move.append(((a[i] + 1) + (n - 1 - i)) % n)
else:
move.append((n - a[i] + i) % n)
print('Yes' if len(set(move)) == 1 else 'NO')
```
| 88,837 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Tags: brute force, implementation
Correct Solution:
```
from sys import stdout
n = int(input())
gears = list(map(int, input().split()))
targetGears = []
for i in range(0, n):
targetGears.append(i)
def check():
for i in range(0, n):
if(gears == targetGears):
stdout.write('Yes')
return
for j in range(0, n):
gears[j] += 1 if j%2==0 else -1
gears[j] %= n
stdout.write('No')
check()
```
| 88,838 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Tags: brute force, implementation
Correct Solution:
```
import functools as ft
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
b = [i for i in range(n)]
for i in range(1, n + 1):
a = [(a[j] + 1) % n if not j % 2 else (a[j] - 1) % n for j in range(n)]
cnt = ft.reduce(lambda x, y: x + y, [a[j] == b[j] for j in range(n)])
if cnt == n:
print("YES")
break
else:
print("NO")
```
| 88,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
g = list(map(int,input().split()))
left = g[0]
right = n-g[0]
# check left
i = 0
while i<n and (g[i]+[-left,+left][i%2])%n == i:
i += 1
if i == n:
print ("Yes")
exit()
i = 0
#(g[i]-[-left,right][i%2])%n
while i<n and (g[i]+[right,-right][i%2])%n == i:
i += 1
if i == n:
print ("Yes")
exit()
print ("No")
```
| 88,840 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
steps = -l[0]
l[0] = 0
for i in range(1,n):
if i%2 == 1:
l[i] = (l[i]-steps)%n
if i%2 == 0:
l[i] = l[i]+steps
if l[i] < 0:
l[i] = n+l[i]
# print(l)
if l == list(range(n)):
print("YES")
else:
print("NO")
```
Yes
| 88,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Submitted Solution:
```
import sys
n = int(input())
a = [int(x) for x in input().split()]
for i in range(1000):
turn = n - a[0]
ok = True
for i in range(len(a)):
a[i] = (a[i] + (turn if i % 2 == 0 else -turn)) % n
if a[i] != i:
ok = False
if ok:
print("Yes")
sys.exit(0)
print("No")
```
Yes
| 88,842 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Submitted Solution:
```
def main():
n = int(input())
a = [int(i) for i in input().split()]
d = 0 if a[0] == 0 else n - a[0]
for i in range(n):
if i % 2 == 0:
a[i] = (a[i] + d) % n
else:
a[i] = (a[i] - d + n) % n
if a == list(range(n)):
print("Yes")
else:
print("No")
main()
```
Yes
| 88,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Submitted Solution:
```
#----Kuzlyaev-Nikita-Codeforces-----
#------------02.04.2020-------------
alph="abcdefghijklmnopqrstuvwxyz"
#-----------------------------------
n=int(input())
a=list(map(int,input().split()))
p=(n-a[0])%n
for j in range(n):
if j%2==0:
if a[j]>j:r=n+j-a[j]
elif a[j]==j:r=0
else:
r=j-a[j]
else:
if a[j]>j:r=a[j]-j
elif a[j]==j:r=0
else:
r=a[j]+n-j
if r!=p:
print("No")
break
else:
print("Yes")
```
Yes
| 88,844 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Submitted Solution:
```
# char_to_dots = {
# 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
# 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
# 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
# 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
# 'Y': '-.--', 'Z': '--..', ' ': ' ', '0': '-----',
# '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....',
# '6': '-....', '7': '--...', '8': '---..', '9': '----.',
# '&': '.-...', "'": '.----.', '@': '.--.-.', ')': '-.--.-', '(': '-.--.',
# ':': '---...', ',': '--..--', '=': '-...-', '!': '-.-.--', '.': '.-.-.-',
# '-': '-....-', '+': '.-.-.', '"': '.-..-.', '?': '..--..', '/': '-..-.'
# }
#from cmath import sqrt
# def printThreads(max, steps):
# step = max // steps
# print("{")
# start = 0
# for i in range(1, steps + 1):
# print("std::thread th", i, "(sr, arr + ", start, ", arr + ", start + step, ");", sep = "")
# start += step
# for i in range(1, steps + 1):
# print("th", i, ".join();", sep = "")
# print("}")
# index = 2
# steps //= 2
# while steps >= 2:
# start = 0
# print("{")
# for i in range(1, steps + 1):
# print("std::thread th", i, "(inplace, arr + ", start, ", arr + ", start + step * (index // 2), ", arr + ", start + step * 2 * (index // 2), ");", sep = "")
# start += step * index
# for i in range(1, steps + 1):
# print("th", i, ".join();", sep = "")
# print("}")
# index *= 2
# steps //= 2
# printThreads(1000000000, 32)
from math import *
import random
def isSorted(list):
for i in range(1, len(list)):
if list[i] < list[i - 1]:
return False
return True
def stringToList(string):
return [int(i) for i in string.split(' ')]
def isTrue(list):
for i in range(4):
add = -1
for i in range(len(list)):
list[i] += add
if list[i] < 0:
list[i] = 4
elif list[i] > 4:
list[i] = 0
if add == 1:
add = -1
else:
add = 1
if isSorted(list):
return True
return False
list = stringToList("0 2 3 1")
if isTrue(list):
print("Yes")
else:
print("No")
```
No
| 88,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
steps = -l[0]
l[0] = 0
for i in range(1,n):
if i%2 == 1:
l[i] = (l[i]-steps)%n
if i%2 == 0:
l[i] = l[i]+steps
if l[i] < 0:
l[i] = n+l[i]
print(l)
if l == list(range(n)):
print("YES")
else:
print("NO")
```
No
| 88,846 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Submitted Solution:
```
import math
import string
num = int(input())
ch = str(input())
m=2*num-2
Z="0"
od=str(num-1)
delt=str(num-1)
beta = "1"
if len(ch)<2*num-1:
for w1 in range(num-len(ch)):
ch=ch +"0"
elif len(ch)> 2*num-1:
ch =ch[0:num]
if num % 2 is 0:
for i in range (1,num):
Z=Z+" "+ str(i)
od =od +" "+str(num-1-i)
else :
for v in range (1,num):
delt = delt +" "
delt= delt +str( v -int(math.pow(-1,v)))
for k in range (1,num):
beta=beta + " "
if k +int(math.pow(-1,k)) is num :
beta =beta +"0"
else:
beta=beta+str( k +int(math.pow(-1,k)))
if num%2 is 0:
for d in range(0,m+1,2):
if eval(Z[d]) is eval(ch [d]):
if d is m:
print ("yes")
elif eval(od[d]) is eval(ch [d]):
if d is m:
print("yes")
else:
print("no")
break
else:
for d in range(0,m+1,2):
if eval(delt[d]) is eval(ch[d]):
if d is m:
print ("yes")
elif eval(beta[d]) is eval(ch [d]):
if d is m:
print ("yes")
else:
print ("no")
break
```
No
| 88,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of gears.
The second line contains n digits a1, a2, ..., an (0 β€ ai β€ n - 1) β the sequence of active teeth: the active tooth of the i-th gear contains number ai.
Output
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
Examples
Input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
even = a[::2]
odd = a[1::2]
ans = 0
if n == 2 and len(set(a)) == 1:ans = 1
if (len(even) != len(set(even))) or (len(odd) != len(set(odd))):
ans = 1
de = 0
def rotdiff(x, y):
if (x + 2)%n == y:
return True
return False
def nordiff(x, y):
if (x - 2)%n == y:
return True
return False
for i in range(len(even) - 1):
if de == 0:
if nordiff(even[i], even[i+1]):
de = 1
elif rotdiff(even[i], even[i+1]):
de = -1
else:
ans = 1
break
else:
if de == 1:
if not nordiff(even[i], even[i+1]):
ans = 1
else:
if not rotdiff(even[i], even[i+1]):
ans = 1
de = 0
for i in range(len(odd) - 1):
if de == 0:
if nordiff(odd[i], odd[i+1]):
de = 1
elif rotdiff(odd[i], odd[i+1]):
de = -1
else:
ans = 1
break
else:
if de == 1:
if not nordiff(odd[i], odd[i+1]):
ans = 1
else:
if not rotdiff(odd[i], odd[i+1]):
ans = 1
print('No' if ans else 'Yes')
```
No
| 88,848 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on n main squares of the capital of Berland. Each of the n squares certainly can have demonstrations of only one party, otherwise it could lead to riots. On the other hand, both parties have applied to host a huge number of demonstrations, so that on all squares demonstrations must be held. Now the capital management will distribute the area between the two parties.
Some pairs of squares are connected by (n - 1) bidirectional roads such that between any pair of squares there is a unique way to get from one square to another. Some squares are on the outskirts of the capital meaning that they are connected by a road with only one other square, such squares are called dead end squares.
The mayor of the capital instructed to distribute all the squares between the parties so that the dead end squares had the same number of demonstrations of the first and the second party. It is guaranteed that the number of dead end squares of the city is even.
To prevent possible conflicts between the zublicanes and the mumocrates it was decided to minimize the number of roads connecting the squares with the distinct parties. You, as a developer of the department of distributing squares, should determine this smallest number.
Input
The first line of the input contains a single integer n (2 β€ n β€ 5000) β the number of squares in the capital of Berland.
Next n - 1 lines contain the pairs of integers x, y (1 β€ x, y β€ n, x β y) β the numbers of the squares connected by the road. All squares are numbered with integers from 1 to n. It is guaranteed that the number of dead end squares of the city is even.
Output
Print a single number β the minimum number of roads connecting the squares with demonstrations of different parties.
Examples
Input
8
1 4
2 4
3 4
6 5
7 5
8 5
4 5
Output
1
Input
5
1 2
1 3
1 4
1 5
Output
2
Submitted Solution:
```
i=int(input())
c={}
for j in range(i-1):
(a,b)=(int(n) for n in input().split())
if a in c:
c[a].append(b)
else:
c[a]=[b]
if b in c:
c[b].append(a)
else:
c[b]=[a]
co=0
for j in c.keys():
if len(c[j])==1:
co=co+1
print(co//2)
```
No
| 88,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on n main squares of the capital of Berland. Each of the n squares certainly can have demonstrations of only one party, otherwise it could lead to riots. On the other hand, both parties have applied to host a huge number of demonstrations, so that on all squares demonstrations must be held. Now the capital management will distribute the area between the two parties.
Some pairs of squares are connected by (n - 1) bidirectional roads such that between any pair of squares there is a unique way to get from one square to another. Some squares are on the outskirts of the capital meaning that they are connected by a road with only one other square, such squares are called dead end squares.
The mayor of the capital instructed to distribute all the squares between the parties so that the dead end squares had the same number of demonstrations of the first and the second party. It is guaranteed that the number of dead end squares of the city is even.
To prevent possible conflicts between the zublicanes and the mumocrates it was decided to minimize the number of roads connecting the squares with the distinct parties. You, as a developer of the department of distributing squares, should determine this smallest number.
Input
The first line of the input contains a single integer n (2 β€ n β€ 5000) β the number of squares in the capital of Berland.
Next n - 1 lines contain the pairs of integers x, y (1 β€ x, y β€ n, x β y) β the numbers of the squares connected by the road. All squares are numbered with integers from 1 to n. It is guaranteed that the number of dead end squares of the city is even.
Output
Print a single number β the minimum number of roads connecting the squares with demonstrations of different parties.
Examples
Input
8
1 4
2 4
3 4
6 5
7 5
8 5
4 5
Output
1
Input
5
1 2
1 3
1 4
1 5
Output
2
Submitted Solution:
```
def dfs1(now):
global cnt
vst[now] = 1
for nxt in roads[now]:
if not vst[nxt]:
dfs1(nxt)
if len(roads[now]) == 1:
par[now] = cnt < (dn // 2)
cnt += 1
else:
cnt = sum(par[child] for child in roads[now])
par[now] = cnt > (len(roads[now]) // 2)
def dfs2(now):
global cnt
vst[now] = 1
for nxt in roads[now]:
if not vst[nxt]:
if par[now] != par[nxt]:
cnt += 1
dfs2(nxt)
n = int(input())
roads = {}
for _ in range(n-1):
a, b = map(int, input().split())
roads.setdefault(a-1, []).append(b-1)
roads.setdefault(b-1, []).append(a-1)
root = next((i for i in range(n) if len(roads[i]) > 1))
dn = sum(len(roads[i]) == 1 for i in range(n))
par = [-1]*n
cnt = 0
vst = [0]*n
dfs1(root)
cnt = 0
vst = [0]*n
dfs2(root)
print(cnt)
```
No
| 88,850 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on n main squares of the capital of Berland. Each of the n squares certainly can have demonstrations of only one party, otherwise it could lead to riots. On the other hand, both parties have applied to host a huge number of demonstrations, so that on all squares demonstrations must be held. Now the capital management will distribute the area between the two parties.
Some pairs of squares are connected by (n - 1) bidirectional roads such that between any pair of squares there is a unique way to get from one square to another. Some squares are on the outskirts of the capital meaning that they are connected by a road with only one other square, such squares are called dead end squares.
The mayor of the capital instructed to distribute all the squares between the parties so that the dead end squares had the same number of demonstrations of the first and the second party. It is guaranteed that the number of dead end squares of the city is even.
To prevent possible conflicts between the zublicanes and the mumocrates it was decided to minimize the number of roads connecting the squares with the distinct parties. You, as a developer of the department of distributing squares, should determine this smallest number.
Input
The first line of the input contains a single integer n (2 β€ n β€ 5000) β the number of squares in the capital of Berland.
Next n - 1 lines contain the pairs of integers x, y (1 β€ x, y β€ n, x β y) β the numbers of the squares connected by the road. All squares are numbered with integers from 1 to n. It is guaranteed that the number of dead end squares of the city is even.
Output
Print a single number β the minimum number of roads connecting the squares with demonstrations of different parties.
Examples
Input
8
1 4
2 4
3 4
6 5
7 5
8 5
4 5
Output
1
Input
5
1 2
1 3
1 4
1 5
Output
2
Submitted Solution:
```
i=int(input())
c={}
for j in range(i-1):
(a,b)=(int(n) for n in input().split())
if a in c:
c[a].append(b)
else:
c[a]=[b]
if b in c:
c[b].append(a)
else:
c[b]=[a]
co=0
for j in c.keys():
if len(c[j])==1:
co=co+1
if i%2==0:
print((i-co)//2)
else:
print(i-co+1)
```
No
| 88,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Tags: brute force, greedy, math, number theory
Correct Solution:
```
n,m = map(int, input().split())
answer=0
while True:
if n >=3 and m>=2:
if n/m>3/2:
n-=3
m-=1
else:
n-=2
m-=2
answer+=6
else:
if m == 1:
answer += max(3, 2* n)
break
elif m == 0:
answer+= 2*n
break
else:
answer += 3*m
break
print(answer)
```
| 88,852 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Tags: brute force, greedy, math, number theory
Correct Solution:
```
n, m = map(int, input().split())
start = 0
end = 10**10
while (end - start > 1):
mid = (end + start) // 2
two = mid // 2 - mid // 6
three = mid // 3 - mid // 6
six = mid // 6
nn = n
mm = m
nn -= two
mm -= three
nn = max(nn, 0)
mm = max(mm, 0)
if (six >= nn + mm):
end = mid
else:
start = mid
print(end)
```
| 88,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Tags: brute force, greedy, math, number theory
Correct Solution:
```
n, m = input().split()
n = int(n)
m = int(m)
res_n = n * 2
res_m = m * 3
tmp_height = 6
while(tmp_height <= min(res_n, res_m)):
tmpresn = res_n + 2
tmpresm = res_m + 3
# print(tmpresn)
# print(tmpresm)
if max(tmpresn, res_m) > max(res_n, tmpresm):
res_m = tmpresm
else:
res_n = tmpresn
tmp_height += 6
print(max(res_m, res_n))
```
| 88,854 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Tags: brute force, greedy, math, number theory
Correct Solution:
```
n,m=map(int,input().split())
curr=max(n*2,m*3)
while n+m>(curr//2+curr//3-curr//6):
curr+=1
print(curr)
```
| 88,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Tags: brute force, greedy, math, number theory
Correct Solution:
```
nm = input().split(" ")
n = int(nm[0])
m = int(nm[1])
#not allowed to be the same height, not not same number of blocks
if n == 0:
print(3*m)
elif m == 0:
print(2*n)
else:
new = max(3*m, 2*n)
i = 0
while i<new+1:
if i%6 == 0 and i != 0:
if i//3 <= m and i//2 <= n and 2*(n+1)-new < 3*(m+1)-new:
n += 1
elif i//3 <= m and i//2 <= n and 2*(n+1)-new >= 3*(m+1)-new:
m += 1
new = max(3*m, 2*n)
i+=1
print(max(3*m,2*n))
```
| 88,856 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Tags: brute force, greedy, math, number theory
Correct Solution:
```
if __name__=='__main__':
d,t = map(int,input().split(' '))
result = 0
i2 = d*2
i3 = t*3
cm = int(max(i2,i3)/6) #common
while cm>0:
if i2+2<i3+3:
i2+=2
elif i2+2> i3+3:
i3+=3
else:
i2+=2
cm+=1
cm-=1
print (max(i2,i3))
'''
if index2+common*2<=index3:
result = index3
else:
result = index2+common*2
if index2>=index3+common*3:
result = index2
'''
'''
while common>0:
print (d,t,common,oldCommon)
if (d+1)*2<=(t+1)*3:
d+=1
else:
t+=1
index2 = d*2
index3 = t*3
print (index2,index3)
common = int(min(index2,index3)/6)
x = common
common-=oldCommon
oldCommon=x
print(max(index2,index3))
'''
'''
C. Block Towers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0ββ€βn,βmββ€β1β000β000, nβ+βmβ>β0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
'''
```
| 88,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Tags: brute force, greedy, math, number theory
Correct Solution:
```
def check(n, m, ans):
div2 = ans // 2
div3 = ans // 3
div6 = ans // 6
k = 0
if div2 < n or div3 < m:
return False
if div2 - div6 < n:
k = n - (div2 - div6)
return div3 - k >= m
n, m = list(map(int, input().split()))
l = -1
r = max(n * 6, m * 6) + 1
while l < r - 1:
mid = (l + r) // 2
if check(n, m, mid):
r = mid
else:
l = mid
print(r)
```
| 88,858 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Tags: brute force, greedy, math, number theory
Correct Solution:
```
n, m = map(int, input().split())
num = max(n * 2, m * 3)
while True:
if num % 2 == 0 or num % 3 == 0:
x = num // 2
y = num // 3
z = num // 6
if x >= n and y >= m and x + y - z >= m + n:
print(num)
exit()
num += 1
```
| 88,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Submitted Solution:
```
def right(m, n, a):
b = True
n2 = a // 2 - a // 6
n3 = a // 3 - a // 6
n6 = a // 6
if n2+n6<n or n3+n6<m or n2+n3+n6<n+m:
b = False
return b
n, m = map(int, input().split())
ans = n+m
while not right(m, n, ans):
ans += 1
print(ans)
```
Yes
| 88,860 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Submitted Solution:
```
n,m = map(int,input().split())
ans = max(n*2, m*3)
while ans//2 + ans//3 - ans//6 < n+m:
ans += 1
print(ans)
```
Yes
| 88,861 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Submitted Solution:
```
n, m = map(int,input().split())
a, b, i = 2 * n, 3 * m, 6
while i <= min(a, b):
if b < a: b += 3
else: a += 2
i += 6
print(max(a, b))
```
Yes
| 88,862 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Submitted Solution:
```
#!/usr/bin/env python3
read_ints = lambda : map(int, input().split())
def solve(m, n):
h2 , h3 = 2*m , 3*n
left = min(h2,h3) // 6
while left > 0:
# print('h2=%d h3=%d n=%d' % (h2, h3, left))
if h2+2 < h3+3:
h2 += 2
if (h2 % 3 != 0) or (h2 > h3):
left -= 1
else:
h3 += 3
if (h3 % 2 != 0) or (h3 > h2):
left -= 1
return max(h2,h3)
if __name__ == '__main__':
m, n = read_ints()
print(solve(m, n))
```
Yes
| 88,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Submitted Solution:
```
n, m = map(int, input().split())
mx = m * 3
nx = mx // 6 * 2 + n * 2
ny = n * 2
my = ny // 6 * 3 + m * 3
print(min(max(nx, mx), max(ny, my)))
```
No
| 88,864 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Submitted Solution:
```
a, b = input().split()
a = int(a)
b = int(b)
cont = 0
def alt_min(n, m):
global a_mtn, a_mtm, cont
a_mtn = n*2
#print(a_mtn)
a_mtm = m*3
#print(a_mtm)
if a_mtn %3 == 0 and (n+1)*2 < (m+1)*3 and cont == 0:
#print('entrou')
cont += 1
alt_min(n+1, m)
elif a_mtm % 2 == 0 and cont == 0:
#print('ent_3')
cont += 1
alt_min(n, m+1)
else:
#print('chamou_dnv')
#print(a_mtn)
#print(a_mtm)
return(max(a_mtn, a_mtm))
alt_min(a, b)
print(max(a_mtm, a_mtn))
# 1481132396353
```
No
| 88,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Submitted Solution:
```
nm = input().split(" ")
n = int(nm[0])
m = int(nm[1])
#not allowed to be the same height, not not same number of blocks
if n == 0:
print(3*m)
elif m == 0:
print(2*n)
else:
new = max(3*m, 2*n)
for i in range(new+1):
if i%6 == 0 and i != 0:
if i//3 <= m and i//2 <= n and 2*(n+1)-new < 3*(m+1)-new:
n += 1
elif i//3 <= m and i//2 <= n and 2*(n+1)-new >= 3*(m+1)-new:
m += 1
print(max(3*m,2*n))
```
No
| 88,866 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students donβt want to use too many blocks, but they also want to be unique, so no two studentsβ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
Input
The first line of the input contains two space-separated integers n and m (0 β€ n, m β€ 1 000 000, n + m > 0) β the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
Submitted Solution:
```
import math
n, m=map(int, input().rstrip().split())
nums_3=[]
for i in range(m):
nums_3.append(3*(i+1))
#print(nums_3)
total=0
if len(nums_3)==0:
print(n*2)
else:
for i in range(10**9):
c=2*(i+1)
if c not in nums_3:
total+=1
if total==n:
print(max(max(nums_3), c))
break
```
No
| 88,867 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Tags: data structures, geometry, math
Correct Solution:
```
from collections import defaultdict as dc
x=int(input())
dx=dc(lambda:0)
dy=dc(lambda:0)
dxy=dc(lambda:0)
for n in range(x):
a,b=map(int,input().split())
dx[a]+=1
dy[b]+=1
dxy[(a,b)]+=1
res=0
for n in dx:
res+=int(dx[n]!=1)*(dx[n]*(dx[n]-1)//2)
for n in dy:
res+=int(dy[n]!=1)*(dy[n]*(dy[n]-1)//2)
for n in dxy:
res-=int(dxy[n]!=1)*(dxy[n]*(dxy[n]-1)//2)
print(res)
```
| 88,868 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Tags: data structures, geometry, math
Correct Solution:
```
n = int(input())
z=n
x={}
y={}
xy={}
ans = 0
while z:
a=0
b=0
a,b=input().split(" ")
a=int(a)
b=int(b)
try:
x[a]=x[a]+1
except:
x[a]=1
try:
y[b]=y[b]+1
except:
y[b]=1
try:
xy[(a,b)]=xy[(a,b)]+1
except:
xy[(a,b)]=1
ans+=x[a]+y[b]-xy[(a,b)]
z-=1
print(ans-n)
```
| 88,869 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Tags: data structures, geometry, math
Correct Solution:
```
n = int(input())
dict_x = {}
dict_y = {}
dict_xy = {}
for _ in range(n):
x, y = map(int, input().split())
try:
dict_xy[(x, y)] += 1
except KeyError:
dict_xy[(x, y)] = 1
try:
dict_x[x] += 1
except KeyError:
dict_x[x] = 1
try:
dict_y[y] += 1
except KeyError:
dict_y[y] = 1
ans = 0
for i in (*dict_x.values(), *dict_y.values()):
ans += i*(i-1)//2
for i in dict_xy.values():
ans -= i*(i-1)//2
print(ans)
```
| 88,870 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Tags: data structures, geometry, math
Correct Solution:
```
from sys import stdin
input = stdin.readline
n = int(input())
x, y, s, ans = dict(), dict(), dict(), 0
for i in range(n):
a, b = [int(i) for i in input().split()]
s[(a, b)] = 1 if (a, b) not in s.keys() else s[(a, b)] + 1
x[a] = 1 if a not in x.keys() else x[a] + 1
y[b] = 1 if b not in y.keys() else y[b] + 1
for k, v in x.items():
ans += v * (v - 1) // 2
for k, v in y.items():
ans += v * (v - 1) // 2
for k, v in s.items():
ans -= v * (v - 1) // 2
print(ans)
```
| 88,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Tags: data structures, geometry, math
Correct Solution:
```
n = int(input())
Dx = dict()
Dy = dict()
Dxy = dict()
for _ in range(n):
x,y = map(int,input().split())
if x in Dx:
Dx[x] += 1
else:
Dx[x] = 1
if y in Dy:
Dy[y] += 1
else:
Dy[y] = 1
if (x,y) in Dxy:
Dxy[(x,y)] += 1
else:
Dxy[(x,y)] = 1
R = dict()
for v in Dx.values():
if v in R:
R[v] += 1
else:
R[v] = 1
for v in Dy.values():
if v in R:
R[v] += 1
else:
R[v] = 1
for v in Dxy.values():
if v in R:
R[v] -= 1
else:
R[v] = -1
ans = 0
for v in R:
ans += (R[v]*v*(v-1))//2
print(ans)
```
| 88,872 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Tags: data structures, geometry, math
Correct Solution:
```
def main():
n = int(input())
xs = {}
ys = {}
xys = {}
total = 0
for i in range(n):
ab = list(map(int, input().split()))
a = ab[0]
b = ab[1]
if a in xs:
xs[a] += 1
total += xs[a]
else:
xs[a] = 0
if b in ys:
ys[b] += 1
total += ys[b]
else:
ys[b] = 0
if (a, b) in xys:
xys[(a, b)] += 1
total -= xys[(a, b)]
else:
xys[(a, b)] = 0
print(total)
if __name__ == '__main__':
main()
```
| 88,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Tags: data structures, geometry, math
Correct Solution:
```
x={}
y={}
d={}
ans=0
for i in range(int(input())):
a,b=map(int,input().split())
if a in x:
x[a]+=1
else:
x[a]=1
if b in y:
y[b]+=1
else:
y[b]=1
if (a,b) in d:
d[(a,b)]+=1
else:
d[(a,b)]=1
x=list(x.values())
y=list(y.values())
d=list(d.values())
for i in x:
ans+=(i*(i-1))//2
for i in y:
ans+=(i*(i-1))//2
for i in d:
ans-=(i*(i-1))//2
print(ans)
```
| 88,874 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Tags: data structures, geometry, math
Correct Solution:
```
n = int(input())
arr = list()
for i in range(n):
x, y = map(int, input().split())
arr.append((x, y))
arr.sort()
c = 0
x = 1
for i in range(n - 1):
if arr[i][0] == arr[i + 1][0]:
x += 1
else:
c += x * (x - 1) // 2
x = 1
c += x * (x - 1) // 2
x = 1
arr.sort(key = lambda T : T[1])
for i in range(n - 1):
if arr[i][1] == arr[i + 1][1]:
x += 1
else:
c += x * (x - 1) // 2
x = 1
c += x * (x - 1) // 2
x = 1
for i in range(n - 1):
if arr[i][1] == arr[i + 1][1] and arr[i][0] == arr[i + 1][0]:
x += 1
else:
c -= x * (x - 1) // 2
x = 1
c -= x * (x - 1) // 2
print(c)
```
| 88,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
from collections import defaultdict
(X, Y, P), k = (defaultdict(int) for _ in range(3)), 0
for _ in range(int(input())):
x, y = input().split()
k += X[x] + Y[y] - P[(x, y)]
X[x], Y[y], P[(x, y)] = X[x] + 1, Y[y] + 1, P[(x, y)] + 1
print(k)
```
Yes
| 88,876 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
#!/usr/bin/python3
from operator import itemgetter
n = int(input())
# points = []
rows = {}
cols = {}
freq = {}
res = 0
for i in range(n):
x, y = map(int, input().split())
# points.append((x, y))
if x in cols:
cols[x].append(y)
else:
cols[x] = [y]
if y in rows:
rows[y].append(x)
else:
rows[y] = [x]
pt = (x, y)
if pt not in freq:
freq[pt] = 1
else:
freq[pt] += 1
res -= freq[pt] - 1
# points.sort(key=itemgetter(0))
for x, col in cols.items():
k = len(col)
res += k*(k-1)//2
for y, row in rows.items():
k = len(row)
res += k*(k-1)//2
print(res)
```
Yes
| 88,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
n = int(input())
coords_x = {}
coords_y = {}
dots = []
tmp = 0
def dictappender_x(a):
try:
coords_x[a] += 1
except KeyError:
coords_x[a] = 1
def dictappender_y(a):
try:
coords_y[a] += 1
except KeyError:
coords_y[a] = 1
for i in range(n):
a, b = list(map(int, input().split()))
dots.append((a, b))
for i in range(len(dots)):
dictappender_x(dots[i][0])
dictappender_y(dots[i][1])
#print(coords_x, coords_y)
count = 0
for key, value in coords_x.items():
count += value * (value - 1) // 2
for key, value in coords_y.items():
count += value * (value - 1) // 2
coords = {}
for dot in dots:
if dot in coords:
coords[dot] += 1
else:
coords[dot] = 1
summ = 0
for key, value in coords.items():
summ += value * (value - 1) // 2
#print(summ - len(coords))
#print(count, summ, count - summ)
print(count - summ)
```
Yes
| 88,878 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
from collections import Counter
a0 = int(input())
c = 0
xx = Counter()
yy = Counter()
xy = Counter()
for z in range(a0):
x, y = map(int, input().split())
c += xx[x] + yy[y] - xy[(x, y)]
xx[x] += 1
yy[y] += 1
xy[(x, y)] += 1
print(c)
```
Yes
| 88,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
import math
a = input()
k = int(a)
all = []
for i in range(k):
b = input()
x,y = b.split()
all.append((x,y))
count = 0
size = len(all)
for j in range(size):
x,y = all[j]
for k in range(j+2,size):
xx, yy = all[k]
if x == xx or y == yy:
count += 1
print(count)
```
No
| 88,880 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
for t in range(1):
n=int(input())
x_pos=dict()
y_pos=dict()
points=set()
for i in range(n):
x,y=map(int,input().split())
if x in x_pos:
x_pos[x]+=1
else:
x_pos[x]=1
if y in y_pos:
y_pos[y]+=1
else:
y_pos[y]=1
points.add((x,y))
count=0
for i in x_pos:
val=x_pos[i]
ans=(val)*(val-1)//2
count+=ans
for i in y_pos:
val=y_pos[i]
ans=(val)*(val-1)//2
count+=ans
print(count-n+len(points))
```
No
| 88,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
""" Watchmen """
def block(arr, index):
ref = arr[0][index]
count = 1
pairs = 0
for num in arr[1:]:
if num[index] == ref:
count += 1
else:
if count > 1:
pairs += count * (count - 1) // 2
ref = num[index]
count = 1
if count != 1:
pairs += count * (count - 1) // 2
return pairs
def CF651C():
""" Count the number of parallelograms given points such that no three points lie on the same line """
# Read input
N = int(input())
points = [tuple(map(int, input().split())) for _ in range(N)]
# N = 4
# points = [(0, 1), (1, 0), (1, 1), (2, 0)]
#
# N = 6
# points = [(0, 0), (0, 2), (2, 2), (4, 2), (1, 4), (3, 4)]
#
# N = 3
# points = [(1, 1), (7, 5), (1, 5)]
#
# N = 6
# points = [(0, 0), (0, 1), (0, 2), (-1, 1), (0, 1), (1, 1)]
# Sorted by x
points = sorted(points)
# Compute the number of duplicates
# Computing it using sets would be expensive. Also the array is already sorted
duplicates = 0
rx, ry = points[0]
curr = 1
for x, y in points[1:]:
if rx == x and ry == y:
curr += 1
else:
rx, ry = x, y
if curr > 1: duplicates += curr
curr = 1
if curr > 1: duplicates += curr
Nx = block(points, 0) # Count points with same x
# sorted by y
points = sorted(points, key=lambda x: x[1])
Ny = block(points, 1)
# Compute total number of pairs
res = Nx + Ny - duplicates // 2
return res
if __name__ == '__main__':
result = CF651C()
print(result)
```
No
| 88,882 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
from math import *
from operator import *
from collections import *
def arr_inp(n):
return [[int(x) for x in input().split()] for i in range(n)]
def nCr(n1, r):
if n1 < 2:
return n1
f = factorial
return int(f(n1) / (f(r) * f(n1 - r)))
n = int(input())
a = arr_inp(n)
dic, dic2, extra = [defaultdict(lambda: 1) for i in range(3)]
a.sort(key=itemgetter(0, 1))
for i in range(1, n):
if a[i][0] == a[i - 1][0]:
dic[a[i][0]] += 1
a.sort(key=itemgetter(1, 0))
for i in range(1, n):
if a[i][1] == a[i - 1][1]:
dic2[a[i][1]] += 1
if a[i][0] == a[i - 1][0]:
s = tuple(a[i])
extra[s] += 1
print(dic, dic2, extra)
ans = sum(list(map(lambda x: nCr(x, 2), dic.values()))) + sum(
list(map(lambda x: nCr(x, 2), dic2.values()))) - sum(
list(map(lambda x: nCr(x, 2), extra.values())))
print(ans)
```
No
| 88,883 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help.
You are given a sequence a, consisting of n distinct integers, that is used to construct the binary search tree. Below is the formal description of the construction process.
1. First element a_1 becomes the root of the tree.
2. Elements a_2, a_3, β¦, a_n are added one by one. To add element a_i one needs to traverse the tree starting from the root and using the following rules:
1. The pointer to the current node is set to the root.
2. If a_i is greater than the value in the current node, then its right child becomes the current node. Otherwise, the left child of the current node becomes the new current node.
3. If at some point there is no required child, the new node is created, it is assigned value a_i and becomes the corresponding child of the current node.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100 000) β the length of the sequence a.
The second line contains n distinct integers a_i (1 β€ a_i β€ 10^9) β the sequence a itself.
Output
Output n - 1 integers. For all i > 1 print the value written in the node that is the parent of the node with value a_i in it.
Examples
Input
3
1 2 3
Output
1 2
Input
5
4 2 3 1 6
Output
4 2 2 4
Tags: data structures, trees
Correct Solution:
```
__author__ = "House"
import bisect
if __name__ == "__main__":
n = int(input())
s = [int(i) for i in input().split()]
f = [[s[0], 0]]
outp = list()
for i in range(1, n):
now = [s[i], i]
idx = bisect.bisect_left(f, now)
ans = 0
if idx == 0:
ans = f[0][0]
elif idx == i:
ans = f[idx - 1][0]
else:
if f[idx][1] < f[idx - 1][1]:
ans = f[idx - 1][0]
else:
ans = f[idx][0]
f[idx:idx] = [now]
outp.append(str(ans))
print(" ".join(outp))
```
| 88,884 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help.
You are given a sequence a, consisting of n distinct integers, that is used to construct the binary search tree. Below is the formal description of the construction process.
1. First element a_1 becomes the root of the tree.
2. Elements a_2, a_3, β¦, a_n are added one by one. To add element a_i one needs to traverse the tree starting from the root and using the following rules:
1. The pointer to the current node is set to the root.
2. If a_i is greater than the value in the current node, then its right child becomes the current node. Otherwise, the left child of the current node becomes the new current node.
3. If at some point there is no required child, the new node is created, it is assigned value a_i and becomes the corresponding child of the current node.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100 000) β the length of the sequence a.
The second line contains n distinct integers a_i (1 β€ a_i β€ 10^9) β the sequence a itself.
Output
Output n - 1 integers. For all i > 1 print the value written in the node that is the parent of the node with value a_i in it.
Examples
Input
3
1 2 3
Output
1 2
Input
5
4 2 3 1 6
Output
4 2 2 4
Tags: data structures, trees
Correct Solution:
```
from bisect import bisect
n=int(input())
elements=list(map(int, input().split()))
tree=[]
ans=['']*n
for i,x in enumerate(elements):
index = bisect(tree, (x,i))
if i!= 0:
if index==0:
ans[i]=str(tree[0][0])
elif index==i:
ans[i]=str(tree[i-1][0])
else:
if tree[index-1][1] < tree[index][1]:
ans[i]=str(tree[index][0])
else:
ans[i]=str(tree[index-1][0])
tree[index:index] = [(x, i)]
print(' '.join(ans[1:]))
```
| 88,885 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help.
You are given a sequence a, consisting of n distinct integers, that is used to construct the binary search tree. Below is the formal description of the construction process.
1. First element a_1 becomes the root of the tree.
2. Elements a_2, a_3, β¦, a_n are added one by one. To add element a_i one needs to traverse the tree starting from the root and using the following rules:
1. The pointer to the current node is set to the root.
2. If a_i is greater than the value in the current node, then its right child becomes the current node. Otherwise, the left child of the current node becomes the new current node.
3. If at some point there is no required child, the new node is created, it is assigned value a_i and becomes the corresponding child of the current node.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100 000) β the length of the sequence a.
The second line contains n distinct integers a_i (1 β€ a_i β€ 10^9) β the sequence a itself.
Output
Output n - 1 integers. For all i > 1 print the value written in the node that is the parent of the node with value a_i in it.
Examples
Input
3
1 2 3
Output
1 2
Input
5
4 2 3 1 6
Output
4 2 2 4
Tags: data structures, trees
Correct Solution:
```
from bisect import bisect
n = int(input())
array = [int(x) for x in input().split()]
tree = []
ans = [''] * n
for i in range(n):
item = array[i]
index = bisect(tree, (item, i))
if i != 0:
if index == 0:
ans[i] = str(tree[0][0])
elif index == i:
ans[i] = str(tree[i - 1][0])
else:
ans[i] = str(tree[index - 1][0] if tree[index - 1][1] > tree[index][1] else tree[index][0])
tree[index:index] = [(item, i)]
print(' '.join(ans[1:]))
```
| 88,886 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help.
You are given a sequence a, consisting of n distinct integers, that is used to construct the binary search tree. Below is the formal description of the construction process.
1. First element a_1 becomes the root of the tree.
2. Elements a_2, a_3, β¦, a_n are added one by one. To add element a_i one needs to traverse the tree starting from the root and using the following rules:
1. The pointer to the current node is set to the root.
2. If a_i is greater than the value in the current node, then its right child becomes the current node. Otherwise, the left child of the current node becomes the new current node.
3. If at some point there is no required child, the new node is created, it is assigned value a_i and becomes the corresponding child of the current node.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100 000) β the length of the sequence a.
The second line contains n distinct integers a_i (1 β€ a_i β€ 10^9) β the sequence a itself.
Output
Output n - 1 integers. For all i > 1 print the value written in the node that is the parent of the node with value a_i in it.
Examples
Input
3
1 2 3
Output
1 2
Input
5
4 2 3 1 6
Output
4 2 2 4
Tags: data structures, trees
Correct Solution:
```
from bisect import *
n=int(input())
d,a=[(0,0)],[0]*n
for i,x in enumerate(map(int,input().split())):
no=bisect(d,(x,0))-1
l,y=d[no]
a[i]=str(y)
d[no:no+1]=[(l,x),(x,x)]
print(' '.join(a[1:]))
```
| 88,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help.
You are given a sequence a, consisting of n distinct integers, that is used to construct the binary search tree. Below is the formal description of the construction process.
1. First element a_1 becomes the root of the tree.
2. Elements a_2, a_3, β¦, a_n are added one by one. To add element a_i one needs to traverse the tree starting from the root and using the following rules:
1. The pointer to the current node is set to the root.
2. If a_i is greater than the value in the current node, then its right child becomes the current node. Otherwise, the left child of the current node becomes the new current node.
3. If at some point there is no required child, the new node is created, it is assigned value a_i and becomes the corresponding child of the current node.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100 000) β the length of the sequence a.
The second line contains n distinct integers a_i (1 β€ a_i β€ 10^9) β the sequence a itself.
Output
Output n - 1 integers. For all i > 1 print the value written in the node that is the parent of the node with value a_i in it.
Examples
Input
3
1 2 3
Output
1 2
Input
5
4 2 3 1 6
Output
4 2 2 4
Submitted Solution:
```
n = int(input())
array = [int(x) for x in input().split()]
tree = []
ans = ''
for i in range(n):
item = array[i]
if i == 0:
tree.append((item, 0))
else:
if item < tree[0][0]:
father = tree[0][0]
tree.insert(0, (item, father))
elif item > tree[i - 1][0]:
father = tree[i - 1][0]
tree.append((item, father))
else:
beg = 0
end = i - 1
while True:
if tree[end][0] < item:
break
mid = (beg + end + 1) // 2
if tree[mid][0] < item:
beg = mid
else:
end = mid - 1
if tree[end][1] == tree[end + 1][0]:
father = tree[end][0]
else:
father = tree[end + 1][0]
tree.insert(end + 1, (item, father))
ans += '%d ' % father
print(ans)
```
No
| 88,888 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Tags: math
Correct Solution:
```
import sys
read=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(x+"\n")
p, a, b = map(int, read().split())
qa, ra = divmod(a, p)
qb, rb = divmod(b, p)
if qa >= 1 and qb >= 1:
write(str(qa + qb))
elif qa >= 1 and qb == 0:
if ra == 0:
write(str(qa))
else:
write("-1")
elif qb >= 1 and qa == 0:
if rb == 0:
write(str(qb))
else:
write("-1")
else:
write("-1")
```
| 88,889 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Tags: math
Correct Solution:
```
k, a, b = map(int, input().split())
mx_a = a // k
mx_b = b // k
if mx_a == 0 and b % k != 0:
print(-1)
elif mx_b == 0 and a % k != 0:
print(-1)
else:
print(mx_a + mx_b)
```
| 88,890 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Tags: math
Correct Solution:
```
k,a,b = map(int,input().split())
match = a//k + b//k
if match==0 or (a%k and b//k==0) or (b%k and a//k==0):
print(-1)
else:
print(match)
```
| 88,891 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Tags: math
Correct Solution:
```
k, a, b = list(map(int, input().split()))
if a == 0 and (b % k != 0):
print(-1)
exit()
if b == 0 and (a % k != 0):
print(-1)
exit()
time_a = (b >= k)
time_b = (a >= k)
if a % k != 0 and not time_a:
print(-1)
exit()
if b % k != 0 and not time_b:
print(-1)
exit()
print(a // k + b // k)
```
| 88,892 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Tags: math
Correct Solution:
```
k, a, b = map(int, input().split())
if (a >= k and b >= k) or (a != 0 and a % k == 0) or(b != 0 and b % k == 0):
print(a // k + b // k)
else:
print(-1)
```
| 88,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Tags: math
Correct Solution:
```
a, b, c = (input().split(" "))
# print(a + " " + b + " " + c)
a = int(a)
b = int(b)
c = int(c)
if a > b and a > c:
print(-1)
elif a > b:
if c % a == 0:
print(int(c/a))
else:
print(-1)
elif (a > c):
if b % a == 0:
print(int(b/a))
else:
print(-1)
else:
print(int(b/a) + int(c/a))
```
| 88,894 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Tags: math
Correct Solution:
```
c,a, b = [ int(x) for x in input().split() ]
if a%c != 0 and b < c: print('-1')
elif b%c != 0 and a < c: print('-1')
else: print(str(a//c + b//c))
```
| 88,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Tags: math
Correct Solution:
```
k,a,b=map(int,input().split())
print(-1 if a<k and b%k or b<k and a%k else a//k+b//k)
# Made By Mostafa_Khaled
```
| 88,896 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Submitted Solution:
```
K, a, b = map(int, input().split())
if a >= K and b >= K:
print(a//K + b//K)
elif a >= K and b < K:
print(-1 if a%K != 0 else a//K)
elif a < K and b >= K:
print(-1 if b%K != 0 else b//K)
else:
print(-1)
```
Yes
| 88,897 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Submitted Solution:
```
k,a,b = map(int,input().split())
from math import floor
awin = floor(a/k)
bwin = floor(b/k)
if b%k > awin*(k-1) or a%k > bwin*(k-1) :
print(-1)
else : print(awin + bwin)
```
Yes
| 88,898 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 β€ k β€ 109, 0 β€ a, b β€ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Submitted Solution:
```
a,b,c=map(int,input().split())
if b<a and c<a:print(-1)
elif b<a and c%a:print(-1)
elif c<a and b%a:print(-1)
else:print(b//a+c//a)
```
Yes
| 88,899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.