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.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of points on a plane.
Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordinates are between - 1000 and 1000, inclusive.
Output
Output a single real number ΞΈ β the answer to the problem statement. The absolute or relative error of your answer should be at most 10 - 2.
Examples
Input
8
-2.14 2.06
-1.14 2.04
-2.16 1.46
-2.14 0.70
-1.42 0.40
-0.94 -0.48
-1.42 -1.28
-2.16 -1.62
Output
5.410
Input
5
2.26 1.44
2.28 0.64
2.30 -0.30
1.58 0.66
3.24 0.66
Output
5.620
Input
8
6.98 2.06
6.40 1.12
5.98 0.24
5.54 -0.60
7.16 0.30
7.82 1.24
8.34 0.24
8.74 -0.76
Output
5.480
Input
5
10.44 2.06
10.90 0.80
11.48 -0.48
12.06 0.76
12.54 2.06
Output
6.040
Input
8
16.94 2.42
15.72 2.38
14.82 1.58
14.88 0.50
15.76 -0.16
16.86 -0.20
17.00 0.88
16.40 0.92
Output
6.040
Input
7
20.62 3.00
21.06 2.28
21.56 1.36
21.66 0.56
21.64 -0.52
22.14 2.32
22.62 3.04
Output
6.720
Submitted Solution:
```
s = 0
n = int(input())
for i in range(n):
x, y = map(float, input().split())
s += y
print(s / n + 5)
```
Yes
| 99,000 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of points on a plane.
Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordinates are between - 1000 and 1000, inclusive.
Output
Output a single real number ΞΈ β the answer to the problem statement. The absolute or relative error of your answer should be at most 10 - 2.
Examples
Input
8
-2.14 2.06
-1.14 2.04
-2.16 1.46
-2.14 0.70
-1.42 0.40
-0.94 -0.48
-1.42 -1.28
-2.16 -1.62
Output
5.410
Input
5
2.26 1.44
2.28 0.64
2.30 -0.30
1.58 0.66
3.24 0.66
Output
5.620
Input
8
6.98 2.06
6.40 1.12
5.98 0.24
5.54 -0.60
7.16 0.30
7.82 1.24
8.34 0.24
8.74 -0.76
Output
5.480
Input
5
10.44 2.06
10.90 0.80
11.48 -0.48
12.06 0.76
12.54 2.06
Output
6.040
Input
8
16.94 2.42
15.72 2.38
14.82 1.58
14.88 0.50
15.76 -0.16
16.86 -0.20
17.00 0.88
16.40 0.92
Output
6.040
Input
7
20.62 3.00
21.06 2.28
21.56 1.36
21.66 0.56
21.64 -0.52
22.14 2.32
22.62 3.04
Output
6.720
Submitted Solution:
```
n=int(input())
print(sum([float(input().split()[1])for i in range(n)])/n+5)
```
Yes
| 99,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of points on a plane.
Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordinates are between - 1000 and 1000, inclusive.
Output
Output a single real number ΞΈ β the answer to the problem statement. The absolute or relative error of your answer should be at most 10 - 2.
Examples
Input
8
-2.14 2.06
-1.14 2.04
-2.16 1.46
-2.14 0.70
-1.42 0.40
-0.94 -0.48
-1.42 -1.28
-2.16 -1.62
Output
5.410
Input
5
2.26 1.44
2.28 0.64
2.30 -0.30
1.58 0.66
3.24 0.66
Output
5.620
Input
8
6.98 2.06
6.40 1.12
5.98 0.24
5.54 -0.60
7.16 0.30
7.82 1.24
8.34 0.24
8.74 -0.76
Output
5.480
Input
5
10.44 2.06
10.90 0.80
11.48 -0.48
12.06 0.76
12.54 2.06
Output
6.040
Input
8
16.94 2.42
15.72 2.38
14.82 1.58
14.88 0.50
15.76 -0.16
16.86 -0.20
17.00 0.88
16.40 0.92
Output
6.040
Input
7
20.62 3.00
21.06 2.28
21.56 1.36
21.66 0.56
21.64 -0.52
22.14 2.32
22.62 3.04
Output
6.720
Submitted Solution:
```
print('_1001000110001100'[int(input())])
```
No
| 99,002 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of points on a plane.
Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordinates are between - 1000 and 1000, inclusive.
Output
Output a single real number ΞΈ β the answer to the problem statement. The absolute or relative error of your answer should be at most 10 - 2.
Examples
Input
8
-2.14 2.06
-1.14 2.04
-2.16 1.46
-2.14 0.70
-1.42 0.40
-0.94 -0.48
-1.42 -1.28
-2.16 -1.62
Output
5.410
Input
5
2.26 1.44
2.28 0.64
2.30 -0.30
1.58 0.66
3.24 0.66
Output
5.620
Input
8
6.98 2.06
6.40 1.12
5.98 0.24
5.54 -0.60
7.16 0.30
7.82 1.24
8.34 0.24
8.74 -0.76
Output
5.480
Input
5
10.44 2.06
10.90 0.80
11.48 -0.48
12.06 0.76
12.54 2.06
Output
6.040
Input
8
16.94 2.42
15.72 2.38
14.82 1.58
14.88 0.50
15.76 -0.16
16.86 -0.20
17.00 0.88
16.40 0.92
Output
6.040
Input
7
20.62 3.00
21.06 2.28
21.56 1.36
21.66 0.56
21.64 -0.52
22.14 2.32
22.62 3.04
Output
6.720
Submitted Solution:
```
print('_1001000101001100'[int(input())])
```
No
| 99,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of points on a plane.
Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordinates are between - 1000 and 1000, inclusive.
Output
Output a single real number ΞΈ β the answer to the problem statement. The absolute or relative error of your answer should be at most 10 - 2.
Examples
Input
8
-2.14 2.06
-1.14 2.04
-2.16 1.46
-2.14 0.70
-1.42 0.40
-0.94 -0.48
-1.42 -1.28
-2.16 -1.62
Output
5.410
Input
5
2.26 1.44
2.28 0.64
2.30 -0.30
1.58 0.66
3.24 0.66
Output
5.620
Input
8
6.98 2.06
6.40 1.12
5.98 0.24
5.54 -0.60
7.16 0.30
7.82 1.24
8.34 0.24
8.74 -0.76
Output
5.480
Input
5
10.44 2.06
10.90 0.80
11.48 -0.48
12.06 0.76
12.54 2.06
Output
6.040
Input
8
16.94 2.42
15.72 2.38
14.82 1.58
14.88 0.50
15.76 -0.16
16.86 -0.20
17.00 0.88
16.40 0.92
Output
6.040
Input
7
20.62 3.00
21.06 2.28
21.56 1.36
21.66 0.56
21.64 -0.52
22.14 2.32
22.62 3.04
Output
6.720
Submitted Solution:
```
print('_1001000111011100'[int(input())])
```
No
| 99,004 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of points on a plane.
Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordinates are between - 1000 and 1000, inclusive.
Output
Output a single real number ΞΈ β the answer to the problem statement. The absolute or relative error of your answer should be at most 10 - 2.
Examples
Input
8
-2.14 2.06
-1.14 2.04
-2.16 1.46
-2.14 0.70
-1.42 0.40
-0.94 -0.48
-1.42 -1.28
-2.16 -1.62
Output
5.410
Input
5
2.26 1.44
2.28 0.64
2.30 -0.30
1.58 0.66
3.24 0.66
Output
5.620
Input
8
6.98 2.06
6.40 1.12
5.98 0.24
5.54 -0.60
7.16 0.30
7.82 1.24
8.34 0.24
8.74 -0.76
Output
5.480
Input
5
10.44 2.06
10.90 0.80
11.48 -0.48
12.06 0.76
12.54 2.06
Output
6.040
Input
8
16.94 2.42
15.72 2.38
14.82 1.58
14.88 0.50
15.76 -0.16
16.86 -0.20
17.00 0.88
16.40 0.92
Output
6.040
Input
7
20.62 3.00
21.06 2.28
21.56 1.36
21.66 0.56
21.64 -0.52
22.14 2.32
22.62 3.04
Output
6.720
Submitted Solution:
```
print('_1001000111101100'[int(input())])
```
No
| 99,005 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Tags: bitmasks, greedy, implementation, sortings
Correct Solution:
```
while True:
try:
def solution(s, l ):
ans = list()
i = l
idn= t = 1
while i >= 1:
tr = i & t
if tr > 0 and t <= s:
s -= t
ans.append(i)
t, i= 1, i-1
elif tr > 0 and t > s:
i -= 1
t = 1
else:
t *= 2
if s == 0:
break
if s==0:
print(len(ans))
print(*ans)
else:print(-1)
def read():
sum, limit = map(int, input().split())
solution(sum, limit)
if __name__ == "__main__":
read()
except EOFError:
break
```
| 99,006 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Tags: bitmasks, greedy, implementation, sortings
Correct Solution:
```
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
def lbit(x):
return x&-x
def main():
n,s=map(int,input().split(" "))
ans=[]
for x in range(s,0,-1):
#print(n)
if n-(lbit(x))>=0:
ans.append(x)
n=n-(lbit(x))
#print(ans)
if n==0:
print(len(ans))
print(*ans)
else:
print(-1)
#-----------------------------BOSS-------------------------------------!
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
```
| 99,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Tags: bitmasks, greedy, implementation, sortings
Correct Solution:
```
import math
def lowerbit(x):
val = bin(x)[::-1]
a,b = val.split("1",1)
a +="1"
return int(a[::-1],2)
s,limit = map(int,input().split())
org = s
ans = 0
ones = math.ceil(limit/2)
if s<= ones:
print(s)
for i in range(1,limit+1,2):
if s == 0:
exit(0)
else:
s-=1
print(i,end=" ")
exit(0)
if limit%2==1:
high = limit-1
else:
high = limit
red = []
for i in range(high,0,-2):
if s <= ones or s==0:
break
elif s- lowerbit(i) >= 0:
red.append(i)
#print("red ",red)
s-=lowerbit(i)
#print(" s ",s)
ans += lowerbit(i)
#print(" ans ",ans)
if org == ans:
print(len(red))
for i in red:
print(i,end=" ")
elif ans+ones>=org:
for i in range(1,limit+1,2):
ans+=1
red.append(i)
if ans == org:
print(len(red))
for j in red:
print(j,end=" ")
exit(0)
else:
print(-1)
```
| 99,008 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Tags: bitmasks, greedy, implementation, sortings
Correct Solution:
```
s,l=map(int,input().split())
odd=l%2+l//2
even=l//2
limit=l
from math import log2,ceil,floor
allf=0
def less(i):#smallest power of 2 less than i
a=2**floor(log2(i))
return a
def rt(n):
for i in range(30):
if n&(1<<i):
return (1<<i)
for i in range(1,l+1):
allf+=(rt(i))
if s>allf:
print(-1)
exit()
else:
res=[rt(i) for i in range(1,limit+1)]
r=0
ans=[]
for i in range(limit,0,-1):
c=rt(i)
if r+c<=s:
r+=c
ans.append(i)
print(len(ans))
print(*ans)
```
| 99,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Tags: bitmasks, greedy, implementation, sortings
Correct Solution:
```
s,limit = map(int,input().split())
ans = []
for i in range(limit,0,-1):
if s-(i&-i) >=0:ans.append(i);s-=(i&-i)
if s == 0:
print(len(ans))
print(" ".join(map(str, ans)))
else:
print(-1)
```
| 99,010 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Tags: bitmasks, greedy, implementation, sortings
Correct Solution:
```
s,n=list(map(int,input().split()))
y=[]
y1=[]
sum1=0
for i in range(1,n+1):
power=0
de=i
while(i%2==0):
power+=1
i=i//2
if sum1+2**power<=s:
sum1+=2**power
y.append(de)
sum2=0
for i in range(n,0,-1):
power=0
de=i
while(i%2==0):
power+=1
i=i//2
if sum2+2**power<=s:
sum2+=2**power
y1.append(de)
if sum1==s:
print(len(y))
print(*y)
elif sum2==s:
print(len(y1))
print(*y1)
else:
print(-1)
```
| 99,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Tags: bitmasks, greedy, implementation, sortings
Correct Solution:
```
s,t = map(int,input().split())
c = {}
arr = []
for i in range(t,0,-1):
l = 0
tmp = i
while tmp%2==0:
tmp /= 2
l += 1
if 2**l<=s:
s -= 2**l
arr.append(i)
if s==0:
print(len(arr))
print(*arr)
else:
print(-1)
```
| 99,012 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Tags: bitmasks, greedy, implementation, sortings
Correct Solution:
```
"""
Template written to be used by Python Programmers.
Use at your own risk!!!!
Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd # defaultdict(<datatype>) Free of KeyError.
from collections import deque # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c # Counter(list) return a dict with {key: count}
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(var)
def l(): return list(map(int, data().split()))
def sl(): return list(map(str, data().split()))
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 [[val for i in range(n)] for j in range(m)]
def lower_two(n):
i = 17
answer = 1
while i >= 0:
answer = max(answer, gcd(int(pow(2, i)), n))
i -= 1
return answer
s, limit = sp()
dp = dict()
for i in range(1, limit+1):
dp[i] = lower_two(i)
prefix = sum(dp.values())
dp = sorted(dp.items(), key=lambda x: x[1])
if s > prefix:
out("-1")
exit(0)
answer = []
for i in range(len(dp)-1, -1, -1):
if dp[i][1] <= s:
answer.append(dp[i][0])
s -= dp[i][1]
if s == 0:
break
out(str(len(answer))+"\n")
for i in answer:
out(str(i)+" ")
exit()
```
| 99,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Submitted Solution:
```
def check(num):
x=str(bin(num))
j=-1
for i in range(len(x)-1,-1,-1):
j+=1
if(x[i]=='1'):
break
return j
s,limit=[int(x) for x in input().split()]
res=[]
for i in range(1,limit+1):
x=check(i)
res.append([2**x,i])
res.sort(key=lambda x:x[0])
#print(res)
ans=[]
for i in range(len(res)-1,-1,-1):
if(s>=res[i][0]):
s-=res[i][0]
ans.append(res[i][1])
if(s==0):
break
if(s!=0):
print(-1)
else:
print(len(ans))
print(*ans,sep=" ")
```
Yes
| 99,014 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Submitted Solution:
```
n, m = map(int, input().split())
vals = {}
temp = []
for j in range(1, m + 1):
lowest_bit = j & (-j)
if lowest_bit not in vals:
vals[lowest_bit] = []
vals[lowest_bit].append(j)
temp.append(lowest_bit)
temp.sort()
result = []
for x in reversed(temp):
if x <=n and len(vals[x]):
n -= x
result.append(vals[x][-1])
vals[x].pop()
if n == 0:
print(len(result))
print(*result)
else:
print(-1)
```
Yes
| 99,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Submitted Solution:
```
s,limit=map(int,input().split())
Cnt=[[]]
for i in range(10**5):
Cnt.append([])
Ind=[0]*(10**5+1)
m=0
for i in range(1,limit+1):
pos=0
x=i
while(x%2==0):
x//=2
pos+=1
Cnt[2**pos].append(i)
m=max(m,2**pos)
L=[]
while(s>0):
e=s
for j in range(min(m,s),-1,-1):
if(Ind[j]<len(Cnt[j])):
L.append(Cnt[j][Ind[j]])
Ind[j]+=1
s-=j
m=min(m,j)
break
if(s==e):
print(-1)
break
if(s==0):
print(len(L))
for item in L:
print(item,end=" ")
```
Yes
| 99,016 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Submitted Solution:
```
n,m=map(int,input().split())
ans=[]
maxa=0
count=0
from collections import defaultdict
al=defaultdict(list)
for i in range(1,m+1):
temp=bin(i)
temp=temp[2:]
temp=temp[::-1]
flag=0
for j in range(len(temp)):
if(temp[j]=='1'):
al[pow(2,j)].append(i)
count+=pow(2,j)
maxa=max(maxa,pow(2,j))
flag=1
if(flag==1):
break;
ans=[]
if(n>count):
print(-1)
else:
while(maxa>=1 and n>0):
if(n>=maxa):
index=len(al[maxa])-1
while(n>=maxa and len(al[maxa])>0):
ans.append(al[maxa][index])
n-=maxa
al[maxa].pop()
index-=1
maxa=maxa//2
print(len(ans))
print(*ans)
```
Yes
| 99,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Submitted Solution:
```
def lowbit(x):
c = 1
while x:
if x % 2:
return c
c *= 2
x /= 2
s, l = map(int, input().split())
x = []
for i in range(1, l + 1):
x.append(lowbit(i))
ss = sum(x)
if ss < s: print(-1)
else:
xx = 0; res = []; rc = 0
for i in range(len(x)):
if xx + x[i] <= s:
xx += x[i]
res.append(i + 1)
rc += 1
if xx == s:
print(rc)
for i in range(rc):
print(res[i], end=' ')
else:
print(-1)
```
No
| 99,018 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Submitted Solution:
```
sum,limit = map(int,input().split())
def lowbit(k):
count = 0
for i in k[::-1]:
if i == '1':
return 2**count
else:
count+=1
actual = 0
for i in range(1,limit+1):
c = bin(i)[2:]
actual+=lowbit(c)
# print(actual)
if sum<=actual:
ans = []
count = 0
for i in range(2,limit+1,2):
count+=lowbit(bin(i)[2:])
# print(count)
ans.append(i)
if count > sum:
count-=lowbit(bin(i)[2:])
ans.pop(-1)
break
for i in range(1,limit+1,2):
if count == sum:
break
else:
count+=lowbit(bin(i)[2:])
ans.append(i)
print(len(ans))
print(*ans)
else:
print(-1)
```
No
| 99,019 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Submitted Solution:
```
s,l=map(int,input().split())
list1=[]
for i in range(1,l+1):
list1.append(i&-i)
list1.sort(reverse=True)
ll=[]
for i in range(l):
if(list1[i]<=s):
ll.append(list1[i])
s-=list1[i]
if(s==0):
print(len(ll))
print(*ll)
else:
print(-1)
```
No
| 99,020 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
* its elements were distinct integers from 1 to limit;
* the value of <image> was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
Input
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 105).
Output
In the first line print an integer n (1 β€ n β€ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
Examples
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
Note
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
Submitted Solution:
```
sum, limit = map (int, input().split())
x = 0
lis = list()
for i in range (sum, 0, -1) :
if limit > 0 and x < sum :
if i % 2 == 0 and i % 4 != 0 :
x += 2
lis.append (i)
limit -= 1
elif i % 4 == 0 :
x += i
lis.append (i)
limit -= 1
else :
x += 1
lis.append (i)
limit -= 1
if x != sum :
print (-1)
else :
print (len (lis))
for i in lis :
print (i, "", end = '')
```
No
| 99,021 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Tags: greedy, meet-in-the-middle, sortings
Correct Solution:
```
n=int(input())
a,ans,b=[],[0]*n,[0]*10000001
for i in range(n):
L,R=map(int,input().split())
a.append([R,L,i])
a.sort()
for z in a:
R,L,i=z
for j in range(L,R+1):
if b[j]==0:
b[j]=1
ans[i]=j
break
print(*ans)
```
| 99,022 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Tags: greedy, meet-in-the-middle, sortings
Correct Solution:
```
n = int(input())
intervals = [list(map(int, input().split())) for i in range(n)]
intervals = list(enumerate(intervals))
intervals.sort(key=lambda x: (x[1][1], x[1][0]))
ans = [0] * n
vis = set()
for idx, (l, _) in intervals:
while l in vis:
l += 1
vis.add(l)
ans[idx] = l
print(' '.join(list(map(str, ans))))
```
| 99,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Tags: greedy, meet-in-the-middle, sortings
Correct Solution:
```
n = int(input())
arr = [0]*10000001
ans = [0]*100
a2=[]
for i in range(n):
l,r = map(int,input().split())
tmp = (r,l,i)
a2.append(tmp)
a2.sort()
for i in range(n):
m=a2[i]
r=m[0]
l=m[1]
v=m[2]
dif=r-l+1
for j in range(dif):
if(arr[l+j]==0):
arr[l+j]=1
ans[v]=l+j
break
ans=ans[:n]
print(*ans)
```
| 99,024 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Tags: greedy, meet-in-the-middle, sortings
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
def main():
n=int(input())
a=[[list(map(int, input().split())),i] for i in range(n)]
a.sort()
now=1
avail=[1 for i in range(int(1e7+1)+1)]
ans=[-1 for i in range(n)]
#print(a)
for k in range(n):
i=a[k]
for j in range(i[0][0], i[0][1]+1):
if avail[j]:
avail[j]=0
ans[i[1]]=j
break
for t in range(k+1, n):
if a[t][0][0]==a[k][0][0]:
a[t][0][0]+=1
else:
break
a.sort()
#now+=1
print(*ans)
return
if __name__ == "__main__":
main()
```
| 99,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Tags: greedy, meet-in-the-middle, sortings
Correct Solution:
```
# sort by the end
n = int(input())
intervals = [list(map(int, input().split())) for i in range(n)]
intervals = list(enumerate(intervals))
intervals.sort(key=lambda x: (x[1][1], x[1][0]))
ans = [0] * n
vis = set()
for idx, (l, _) in intervals:
while l in vis:
l += 1
vis.add(l)
ans[idx] = l
print(' '.join(list(map(str, ans))))
```
| 99,026 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Tags: greedy, meet-in-the-middle, sortings
Correct Solution:
```
import random
class Event:
def __init__(self, id, start, end):
self.start = start
self.end = end
self.id = id
self.pick = None
def key(self):
return (self.start, self.end)
n = int(input())
events = [ Event(i, *map(int, input().split())) for i in range(n) ]
limit = events[0].end
for event in events:
limit = max(limit, event.end)
current_events = set()
for i in range(n):
if len(current_events) == 0:
pos = limit + 1
for event in events:
if event.pick == None and event.start < pos:
pos = event.start
for event in events:
if event.pick == None and event.start == pos:
current_events.add(event)
best_event = random.sample(current_events, 1)[0]
for event in current_events:
if event.end < best_event.end:
best_event = event
best_event.pick = pos
current_events.remove(best_event)
pos += 1
result = [ events[i].pick for i in range(n) ]
print(' '.join(map(str, result)))
```
| 99,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Tags: greedy, meet-in-the-middle, sortings
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
n = int(input())
freq = [0] * 10000001
ans = [0] * 100
a = []
for i in range(n):
l , r = map(int, input().split())
temp = (r, l, i)
a.append(temp)
a.sort()
for i in range(n):
r, l, v = a[i][0], a[i][1], a[i][2]
for j in range(l, r+1):
if freq[j] == 0:
freq[j] = 1
ans[v] = j
break
for i in range(n):
print(ans[i], " ", end = "")
```
| 99,028 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Tags: greedy, meet-in-the-middle, sortings
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
n = int(input())
freq = [0] * 10000001
ans = [0] * 100
a = []
for i in range(n):
l , r = map(int, input().split())
temp = (r, l, i)
a.append(temp)
a.sort()
for i in range(n):
r, l, v = a[i][0], a[i][1], a[i][2]
for j in range(l, r+1):
if freq[j] == 0:
freq[j] = 1
ans[v] = j
break
for i in range(n):
print(ans[i], " ", end = "")
# Made By Mostafa_Khaled
```
| 99,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Submitted Solution:
```
# from dust i have come, dust i will be
n = int(input())
seg = []
for i in range(n):
l, r = map(int, input().split())
seg.append((l, r, i))
seg.sort(key=lambda tup: (tup[1], tup[0], tup[2]))
assigned = set()
ans = [0] * n
for i in range(n):
# this loop won't run more than 100 times as n <= 100
for j in range(seg[i][0], seg[i][1] + 1, 1):
if j not in assigned:
ans[seg[i][2]] = j
assigned.add(j)
break
for i in range(n):
print(ans[i], end=' ')
'''
10
1 10
3 4
8 10
3 4
5 9
1 4
7 10
1 9
1 8
4 10
'''
```
Yes
| 99,030 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Submitted Solution:
```
# http://codeforces.com/contest/45/problem/D
from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0
def next_str():
global tokens, tokens_next
while tokens_next >= len(tokens):
tokens = inFile.readline().split()
tokens_next = 0
tokens_next += 1
return tokens[tokens_next - 1]
def nextInt():
return int(next_str())
n = nextInt()
intervals = [(nextInt(), nextInt(), i) for i in range(n)]
intervals.sort(key=lambda x: (x[1], x[0]))
# for i in intervals:
# print(i[0], i[1])
seen = set()
for i in range(n):
cur = intervals[i][0]
while cur in seen:
cur += 1
seen.add(cur)
intervals[i] = (intervals[i][0], intervals[i][1], intervals[i][2], cur)
intervals.sort(key=lambda x: x[2])
for i in range(n):
print(intervals[i][3], end=' ')
print()
```
Yes
| 99,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Submitted Solution:
```
n = int(input())
arr = [0]*10000001
ans = [0]*100
print()
a2=[]
for i in range(n):
l,r = map(int,input().split())
tmp = (r,l,i)
a2.append(tmp)
a2.sort()
for i in range(n):
m=a2[i]
r=m[0]
l=m[1]
v=m[2]
dif=r-l+1
for j in range(dif):
if(arr[l+j]==0):
arr[l+j]=1
ans[v]=l+j
break
for x in range(n):
print(ans[x], " ",end="")
```
Yes
| 99,032 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Submitted Solution:
```
import copy
def trying(dic, final, taken):
print("trying")
cond = True
c2 = True
while cond:
print("loop ")
if len(dic) == 0:
cond = False;
for i in range(len(final)):
print(final[i], end=' ')
return True
if c2:
c2 = False
tLength = len(taken)
for k, v in list(dic.items()):
v -=taken
if len(v) == 1:
(item ,) = v
taken.add(item)
final[k] = item
del dic[k]
c2 = True
print("removed",k,v)
else:
dic[k]=v
else:
#no single element found in for an event, branching:
for k,v in list(dic.items()):
options = list(v)
for opt in options:
dic2 = copy.deepcopy(dic)
final2 = copy.deepcopy(final)
taken2 = copy.deepcopy(taken)
del dic2[k]
final2[k] = opt
taken2.add(opt)
if trying(dic2, final2, taken2):
cond=False;
return True;
#not a single way worked out, return false.
return False;
tLength = 0
taken = set()
dic = {}
final = {}
for i in range(int(input())):
inp = list(map(int, input().split(" ")))
dic[i] = {x for x in range(inp[0],inp[1]+1)}
if len(dic[i]) == 1:
(item,) = dic[i]
taken.add(item)
final[i] = item
del dic[i]
print("removed",i,item)
trying(dic, final, taken)
print()
```
No
| 99,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Submitted Solution:
```
# from dust i have come, dust i will be
def cmp(element):
return element[1]
n = int(input())
seg = []
for i in range(n):
l, r = map(int, input().split())
seg.append((l, r))
seg.sort(key=cmp)
curr = 0
for i in range(n):
if seg[i][0] > curr:
print(seg[i][0], end='')
curr = seg[i][0] + 1
else:
print(curr, end='')
curr += 1
```
No
| 99,034 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
def main():
n=int(input())
a=[[list(map(int, input().split())),i] for i in range(n)]
a.sort()
now=1
ans=[-1 for i in range(n)]
for i in a:
while not (i[0][0]<=now<=i[0][1]):
now+=1
ans[i[1]]=now
print(*ans)
return
if __name__ == "__main__":
main()
```
No
| 99,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of known events. Then follow n lines containing two integers li and ri each (1 β€ li β€ ri β€ 107) β the earliest acceptable date and the latest acceptable date of the i-th event.
Output
Print n numbers β the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
Examples
Input
3
1 2
2 3
3 4
Output
1 2 3
Input
2
1 3
1 3
Output
1 2
Submitted Solution:
```
from operator import itemgetter
k2 = list(map(int,input().split()))
k = k2[0]
times = []
minimum = 10 ** 7
maximum = 0
for x in range (0,k):
tempList = list(map(int,input().split()))
tempList.append(tempList[1]-tempList[0])
times.append(tempList)
minimum = min(tempList[0],minimum)
maximum = max(tempList[1],maximum)
times = sorted(times, key=itemgetter(2))
#print(times)
#print(maximum)
#print(minimum)
results = []
Date = 0
while Date <= maximum:
tempList = [Date,False]
results.append(tempList)
Date += 1
#print(results)
finalResults = []
for dateRange in times:
tempDate = dateRange[0]
while (tempDate <= maximum and results[tempDate][1] == True):
if(tempDate > dateRange[1]):
print("We went out of the range for this possible event")
tempDate += 1
finalResults.append(tempDate)
results[tempDate][1] = True
finalResults.sort()
stringResults = ""
for x in finalResults:
stringResults = stringResults + str(x) + " "
print(stringResults)
```
No
| 99,036 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta's garden is planted with n bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the i-th bamboo is hi meters, and it grows ai meters at the end of each day.
Actually, Mr. Kitayuta hates these bamboos. He once attempted to cut them down, but failed because their stems are too hard. Mr. Kitayuta have not given up, however. He has crafted Magical Hammer with his intelligence to drive them into the ground.
He can use Magical Hammer at most k times during each day, due to his limited Magic Power. Each time he beat a bamboo with Magical Hammer, its height decreases by p meters. If the height would become negative by this change, it will become 0 meters instead (it does not disappear). In other words, if a bamboo whose height is h meters is beaten with Magical Hammer, its new height will be max(0, h - p) meters. It is possible to beat the same bamboo more than once in a day.
Mr. Kitayuta will fight the bamboos for m days, starting today. His purpose is to minimize the height of the tallest bamboo after m days (that is, m iterations of "Mr. Kitayuta beats the bamboos and then they grow"). Find the lowest possible height of the tallest bamboo after m days.
Input
The first line of the input contains four space-separated integers n, m, k and p (1 β€ n β€ 105, 1 β€ m β€ 5000, 1 β€ k β€ 10, 1 β€ p β€ 109). They represent the number of the bamboos in Mr. Kitayuta's garden, the duration of Mr. Kitayuta's fight in days, the maximum number of times that Mr. Kitayuta beat the bamboos during each day, and the power of Magic Hammer, respectively.
The following n lines describe the properties of the bamboos. The i-th of them (1 β€ i β€ n) contains two space-separated integers hi and ai (0 β€ hi β€ 109, 1 β€ ai β€ 109), denoting the initial height and the growth rate of the i-th bamboo, respectively.
Output
Print the lowest possible height of the tallest bamboo after m days.
Examples
Input
3 1 2 5
10 10
10 10
15 2
Output
17
Input
2 10 10 1000000000
0 10
0 10
Output
10
Input
5 3 3 10
9 5
9 2
4 7
9 10
3 8
Output
14
Submitted Solution:
```
n,m,k,p = input().split()
tall = 0
temp = 0
for i in range(int(n)):
h,a = input().split()
h=int(h)
for j in range(int(m)):
c=int(p)*int(k)
h-=c
if(h<0):
h=0
h+=int(a)
if(temp!=h):
temp=h
tall+=h
print(tall)
#input
#3 1 2 5
#10 10
#10 10
#15 2
```
No
| 99,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Tags: combinatorics
Correct Solution:
```
u=input
n,m=map(int,u().split())
l=[list(u()) for _ in range(n)]
R=[p.count('*') for p in l]
C=[p.count('*') for p in zip(*l)]
t=0
for i in range(n):
for j in range(m):
if(l[i][j]=='*'):
t+=(R[i]-1)*(C[j]-1)
print(t)
```
| 99,038 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Tags: combinatorics
Correct Solution:
```
n,m = map(int,input().split())
ma = []
for i in range(n):
ma.append(input())
x = [0] * n
y = [0] * m
for i in range(n):
for j in range(m):
if ma[i][j] == "*":
x[i] += 1
y[j] += 1
ans = 0
for i in range(n):
for j in range(m):
if ma[i][j] == "*":
ans += (x[i] - 1) * (y[j] - 1)
print(ans)
```
| 99,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Tags: combinatorics
Correct Solution:
```
n,m=map(int,input().split())
a,r,c=[""]*n,[0]*n,[0]*m
for i in range(n):
a[i]=input()
for i in range(n):
for j in range(m):
if a[i][j]=="*":
r[i]+=1
c[j]+=1
ans=0
for i in range(n):
for j in range(m):
if a[i][j]=="*":
ans+=(r[i]-1)*(c[j]-1)
print(ans)
```
| 99,040 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Tags: combinatorics
Correct Solution:
```
n, m = [int(x) for x in input().split()]
a = []
for _ in range(n):
a.append(input())
cnt_rows = [0] * n
cnt_cols = [0] * m
for i in range(n):
for j in range(m):
if a[i][j] == '*':
cnt_rows[i] +=1
cnt_cols[j] += 1
res = 0
for i in range(n):
for j in range(m):
if a[i][j] == '*':
res += (cnt_cols[j] - 1) * (cnt_rows[i] - 1)
print(res)
```
| 99,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Tags: combinatorics
Correct Solution:
```
u=input
n,m=map(int,u().split())
l=[list(u()) for _ in range(n)]
R=[p.count('*') for p in l]
C=[p.count('*') for p in zip(*l)]
t=0
for i in range(n):
for j in range(m):
if(l[i][j]=='*'):
t+=(R[i]-1)*(C[j]-1)
print(t)
# Made By Mostafa_Khaled
```
| 99,042 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Tags: combinatorics
Correct Solution:
```
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(input())
r = [0] * n
c = [0] * m
for i in range(n):
for j in range(m):
if a[i][j] == '*':
r[i] += 1
c[j] += 1
s = 0
for i in range(n):
for j in range(m):
if a[i][j] == '*':
s += (r[i] - 1) * (c[j] - 1)
print(s)
```
| 99,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Tags: combinatorics
Correct Solution:
```
n,m=list(map(int,input().split()))
a=[input() for i in range(n)]
b=[-1]*n
c=[-1]*m
for i in range(n):
for j in range(m):
if a[i][j]=='*':
b[i]+=1
c[j]+=1
d=0
for i in range(n):
for j in range(m):
if a[i][j]=='*':
d+=b[i]*c[j]
print(d)
```
| 99,044 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Tags: combinatorics
Correct Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
a = ([[0] * (m + 2)]
+ [[0] + list(1 if c == '*' else 0 for c in input().rstrip()) + [0] for _ in range(n)]
+ [[0] * (m + 2)])
lr = [[0] * (m + 2) for _ in range(n + 2)]
ud = [[0] * (m + 2) for _ in range(n + 2)]
for i in range(1, n + 1):
for j in range(1, m + 2):
lr[i][j] = lr[i][j - 1] + a[i][j]
for j in range(1, m + 1):
for i in range(1, n + 2):
ud[i][j] = ud[i - 1][j] + a[i][j]
ans = 0
for i in range(1, n + 1):
for j in range(1, m + 1):
if a[i][j]:
l, r, u, d = lr[i][j - 1], lr[i][-1] - lr[i][j], ud[i - 1][j], ud[-1][j] - ud[i][j]
ans += u * r + r * d + d * l + l * u
print(ans)
```
| 99,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Submitted Solution:
```
n,m=map(int,input().split())
c,r=[0]*n,[0]*m
vals=[]
for i in range(n):
s=input()
vals.append(s)
for j in range(m):
if(s[j]=='*'):
c[i]+=1
r[j]+=1
ans=0
for i in range(n):
for j in range(m):
if(vals[i][j]=='*'):
ans+=(c[i]-1)*(r[j]-1)
print(ans)
```
Yes
| 99,046 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Submitted Solution:
```
import sys
data = []
line1 = True
asterisks = []
cols = []
for line in sys.stdin:
if line1:
line1 = False
dim = line[:-1].split(" ")
for i in range(int(dim[1])):
cols.append(0)
else:
row = []
for i, c in enumerate(line):
if c == "*":
row.append(i+1)
cols[i] += 1
asterisks.append(row)
sum = 0
for row in asterisks:
if len(row) >= 2:
vertices = []
for i, item in enumerate(row):
sum += (cols[item-1] - 1) * (len(row) - 1)
print(sum)
```
Yes
| 99,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Submitted Solution:
```
n, m = map(int, input().split())
grid = [input() for _ in range(n)]
a = [[0 for _ in range(m)] for i in range(n)]
b = [[0 for _ in range(m)] for i in range(n)]
for i in range(n):
for j in range(m):
a[i][j] = a[i][j - 1] + (grid[i][j] == '*')
if i:
b[i][j] = b[i - 1][j]
b[i][j] += grid[i][j] == '*'
ans = 0
for i in range(n):
for j in range(m):
if grid[i][j] == '*':
l = r = u = d = 0
if j:
l = a[i][j - 1]
r = a[i][-1] - a[i][j]
if i:
u = b[i - 1][j]
d = b[-1][j] - b[i][j]
ans += (l + r) * (u + d)
print(ans)
```
Yes
| 99,048 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a n Γ m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
Input
The first line contains two positive integer numbers n and m (1 β€ n, m β€ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.
Output
Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Examples
Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
Submitted Solution:
```
n, m = map(int, input().split())
# temp = []
arr = []
r = [0]*n
c = [0]*m
for i in range(n):
arr.append(input())
triangle = 0
for i in range(n):
for j in range(m):
if arr[i][j] == '*':
r[i] += 1
c[j] += 1
for i in range(n):
for j in range(m):
if arr[i][j] == '*':
triangle += (r[i] - 1) * (c[j] - 1)
print(triangle)
```
Yes
| 99,049 |
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. Now he is busy with a top secret case, the details of which are not subject to disclosure.
However, he needs help conducting one of the investigative experiment. There are n pegs put on a plane, they are numbered from 1 to n, the coordinates of the i-th of them are (xi, 0). Then, we tie to the bottom of one of the pegs a weight on a tight rope of length l (thus, its coordinates will be equal to (xi, - l), where i is the number of the used peg). Then the weight is pushed to the right, so that it starts to rotate counterclockwise. At the same time, if the weight during rotation touches some of the other pegs, it then begins to rotate around that peg. Suppose that each peg itself is very thin and does not affect the rope length while weight is rotating around it.
<image>
More formally, if at some moment the segment of the rope contains one or more pegs in addition to the peg around which the weight is rotating, the weight will then rotate around the farthermost one of them on a shorter segment of a rope. In particular, if the segment of the rope touches some peg by its endpoint, it is considered that the weight starts to rotate around that peg on a segment of the rope of length 0.
At some moment the weight will begin to rotate around some peg, without affecting the rest of the pegs. Andrewid interested in determining the number of this peg.
Andrewid prepared m queries containing initial conditions for pushing the weight, help him to determine for each of them, around what peg the weight will eventually rotate.
Input
The first line contains integers n and m (1 β€ n, m β€ 2Β·105) β the number of pegs and queries.
The next line contains n integers x1, x2, ..., xn ( - 109 β€ xi β€ 109) β the coordinates of the pegs. It is guaranteed that the coordinates of all the pegs are distinct integers.
Next m lines contain the descriptions of the queries of pushing the weight, each consists of two integers ai (1 β€ ai β€ n) and li (1 β€ li β€ 109) β the number of the starting peg and the length of the rope.
Output
Print m lines, the i-th line should contain the number of the peg around which the weight will eventually rotate after the i-th push.
Examples
Input
3 2
0 3 5
2 3
1 8
Output
3
2
Input
4 4
1 5 7 15
1 4
2 15
3 16
1 28
Output
2
4
3
1
Note
Picture to the first sample test:
<image>
Picture to the second sample test:
<image>
Note that in the last query weight starts to rotate around the peg 1 attached to a rope segment of length 0.
Submitted Solution:
```
n,m=input().split()
n=int(n)
m=int(m)
s=input()
x=[int(i) for i in s.split()]
ans=[]
for j in range(m):
a,l=input().split()
a=int(a)-1
l=int(l)
while(True):
while((a+1<n) and(l>=abs(x[a+1]-x[a]))):
l=l-(abs(x[a+1]-x[a]))
a=a+1
while((a-1>=0) and (l>=abs(x[a]-x[a-1]))):
l=l-abs(x[a]-x[a-1])
a=a-1
if(a==0):
if(l<abs(x[1]-x[0])):
break
elif(a==n-1):
if(abs(x[n-1]-x[n-2])>l):
break
else:
if(l<abs(x[a]-x[a-1]) and l<abs(x[a+1]-x[a])):
break
ans.append(a+1)
for j in ans:
print(j)
```
No
| 99,050 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Tags: implementation, math, sortings
Correct Solution:
```
__author__ = 'User'
n, k = map(int, input().split())
arr = list(map(int, input().split()))
mx = [0] * n
score = 0
for i in range(n):
if arr[i] != 100:
mx[i] = (10 - arr[i] % 10, i)
else:
mx[i] = (-1, i)
score += arr[i] // 10
mx.sort()
i = 0
#print(mx, k)
#print(score)
while i < n and k >= mx[i][0]:
if mx[i][0] != -1:
k -= mx[i][0]
arr[mx[i][1]] += mx[i][0]
score += 1
i += 1
#print(arr, k)
#print(score)
if i == n:
i = 0
k -= k % 10
while k >= 10 and i < n:
if arr[i] != 100:
d = 100 - arr[i]
if k >= d:
k -= d
#arr[i] += d
#print("d", d)
score += d // 10
else:
#arr[i] += k
score += k // 10
k = 0
i += 1
print(score)
#print(arr)
```
| 99,051 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Tags: implementation, math, sortings
Correct Solution:
```
n,k=map(int,input().split())
ki=[0]*11
su=0
for x in input().split():
t=int(x)
ki[10-t%10]+=1
su+=t//10
for i in range(1,10):
t=min(k//i,ki[i])
su+=t
k-=t*i
t=k//10
su+=min(t,n*10-su)
print(su)
```
| 99,052 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Tags: implementation, math, sortings
Correct Solution:
```
def rating(lst):
return sum([a // 10 for a in lst])
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(key=lambda x : x % 10, reverse=True)
for i in range(n):
if a[i] >= 100:
continue
if k <= 0:
break
left = 10 - a[i] % 10
if k >= left:
a[i] += left
k -= left
if k > 0:
for i in range(n):
if k <= 0:
break
left = 100 - a[i]
a[i] += min(k, left)
k -= left
print(rating(a))
```
| 99,053 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Tags: implementation, math, sortings
Correct Solution:
```
import math as m
def solve():
n, k = (int(i) for i in input().split())
ai = [int(i) for i in input().split()]
cnt = 0
if(k > 100 * len(ai) - sum(ai)):
k = 100 * len(ai) - sum(ai)
for i in range(len(ai)):
cnt += m.floor(ai[i] / 10)
ai[i] = ai[i] % 10
ai.sort(reverse=True)
for i in range(len(ai)):
diff = 10- ai[i]
if diff <= k:
k -= diff
cnt += 1
cnt += m.floor(k / 10)
return cnt
print(solve())
```
| 99,054 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Tags: implementation, math, sortings
Correct Solution:
```
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
arr = list()
for i in range(n):
arr.append(((10 - a[i] + (a[i] // 10 * 10)) % 10, a[i]))
arr.sort()
ans = 0
for i in range(n):
if arr[i][1] >= 100 or k - arr[i][0] < 0:
ans += arr[i][1] // 10
continue
k -= arr[i][0]
ans += (arr[i][1] + arr[i][0]) // 10
t = 10 * n - ans
ans += min(k // 10, t)
print(ans)
```
| 99,055 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Tags: implementation, math, sortings
Correct Solution:
```
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[];l=0
for i in a:
b.append(i%10)
l+=(i//10)
b.sort(reverse=True)
for i in range(n):
if k-(10-b[i])>=0:
l+=1;k-=(10-b[i])
print(min(10*n,l+(k//10)))
```
| 99,056 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Tags: implementation, math, sortings
Correct Solution:
```
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = A[:]
sum = 0
for i in range(N):
sum += B[i] // 10
B[i] = B[i] % 10
B.sort()
for i in range(N-1, -1, -1):
if(K <= 0):
break
if(B[i] == 0):
break
if(10 - B[i] > K):
break
K -= 10 - B[i]
sum += 1
res = sum + K//10
if(res > N*10):
res = N*10
print(res)
```
| 99,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Tags: implementation, math, sortings
Correct Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/581/C
n, k = map(int, input().split())
l_s = list(map(int, input().split()))
l_s.sort(key = lambda x: x % 10 if x != 100 else x, reverse = True)
t = 0
r = 0
index = 0
for i in l_s:
n_i = i
if i != 100:
n_i += min(k, 10 - i % 10)
k -= n_i - i
r += 100 - n_i
t += n_i // 10
t += min(r // 10, k // 10)
print(t)
```
| 99,058 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Submitted Solution:
```
import itertools
import math
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort(key = lambda x:(-x-1)%10 + 1)
for i in range(n):
step = (-a[i]-1)%10 + 1
if step == 10:
break
if k-step < 0:
break
k -= step
a[i] += step
add = sum(100 - x for x in a)
print(sum(x//10 for x in a) + min(k, add)//10)
```
Yes
| 99,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Submitted Solution:
```
import sys
def solve():
n,k, = rv()
a, = rl(1)
res = 0
count = [0] * 10
for i in range(n):
if a[i] < 100:
count[10 - (a[i] % 10) - 1] += 1
res += a[i] // 10
for i in range(10):
while count[i] > 0 and k >= i + 1:
res += 1
count[i] -= 1
k -= i + 1
already = res * 10
possible = n * 100
diff = possible - already
if diff > 0:
actual = min(diff, k)
res += actual // 10
print(res)
def prt(l): return print(' '.join(map(str, l)))
def rs(): return map(str, input().split())
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()
```
Yes
| 99,060 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Submitted Solution:
```
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(key = lambda x:10-(x%10))
for idx in range(n):
temp = 10-(a[idx]%10)
if k< temp:
break
if a[idx]+temp>100:
continue
a[idx]+= temp
k-= temp
a.sort()
idx = 0
while True:
if k<=0:
break
if a[idx]>=100:
break
prev = a[idx]
a[idx]= min(100,a[idx]+k)
k-= (a[idx]-prev)
idx = (idx+1)%n
ans = 0
for i in range(n):
ans+= a[i]//10
print(ans)
```
Yes
| 99,061 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
rating = 0
di = {}
for i in range(1,10):
di[i] = 0
for i in a:
rating += i // 10
if i % 10 != 0:
di[i % 10] += 1
#print(di)
for x in range(9, 0, -1):
poss = k // (10-x)
ans1 = min(poss, di[x])
rating += ans1
k -= ans1*(10-x)
while k >= 10:
rating += 1
k -= 10
print(min(rating, 10*n))
```
Yes
| 99,062 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Submitted Solution:
```
n, k = map(int, input().split())
point = list(map(int, input().split()))
MOD = [0] * 10
if k + sum(point) >= n * 100:
print(n * 10)
else:
ans = 0
for i in range(n):
ans += (point[i] // 10)
MOD[point[i] % 10] += 1
for j in range(9, -1, -1):
if k // (10 - j) >= MOD[j]:
ans += MOD[j]
k -= ((10 - j) * MOD[j])
else:
ans += (k // (10 - j))
break
print(ans)
```
No
| 99,063 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Submitted Solution:
```
import math
import copy
n,k = [int(x) for x in input().split(' ')]
A = [int(x) for x in input().split(' ')]
A.sort(reverse=True)
for i, a in enumerate(A):
if 10-a > k:
break
k -= 10-a
A[i] += 10-a
score = 0
for i, a in enumerate(A):
if k >= 10:
d = 100-A[i]
d = min(d, k)
d = d - (d%10)
A[i] += d
k -= d
score += math.floor(A[i]/10)
print(score)
```
No
| 99,064 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Submitted Solution:
```
n, k = map(int, input().split())
d = list(map(int, input().split()))
res = 0
m = len(d)
d = sorted(d, key=lambda x: int(str(x)[-1]))[::-1]
x = 0
while k > 0 and x != len(d):
if d[x] != 100:
k -= 10 - d[x] % 10
if k >= 0 and d[x] != 100:
d[x] += 10 - d[x] % 10
if d[x] == 100:
m -= 1
res += d[x] // 10
x += 1
if k > 0 and k // 100 <= m:
res += k // 10
elif k > 0:
res += m
print(res)
```
No
| 99,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ββof <image> for all i from 1 to n. The expression β xβ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 β€ n β€ 105, 0 β€ k β€ 107) β the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 β€ ai β€ 100), where ai characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer β the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.
Submitted Solution:
```
(n,k) = map(int,input().split())
L = list(map(int,input().split()))
L.sort(key = lambda x: x % 10, reverse =True)
index = 0
c = 0
while k > 0 and index < n:
if k >= 10 - (L[index]%10):
if index != n-1:
k -= (10 - L[index]%10)
L[index] += (10 - L[index]%10)
c += (L[index]//10)
else:
k -= (10 - L[index]%10)
L[index] += (10 - L[index]%10)
while k >= 10:
k -= 10
L[index] += 10
c += (L[index]//10)
else:
c += (L[index]//10)
break
index += 1
print(c)
```
No
| 99,066 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Tags: combinatorics, dfs and similar, dsu, math, number theory
Correct Solution:
```
MOD = 10**9+7
def f(a,b):
if b == 1:
return a%MOD
elif b % 2 == 0:
return f((a*a)%MOD,b//2)
else:
return (a*f((a*a)%MOD,b//2)) % MOD
p,k = map(int,input().split())
if k == 0:
print(f(p,p-1))
exit()
if k == 1:
print(f(p,p))
exit()
t = 1
a = k
while a != 1:
a = (a*k % p)
t += 1
n = (p-1)//t
print(f(p,n))
```
| 99,067 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Tags: combinatorics, dfs and similar, dsu, math, number theory
Correct Solution:
```
import math
p,k = map(int, input().split())
a = [0] * p
sets = 0
for i in range(p):
if ( a[i] == 0 ):
sets += 1
r = i
while ( a[r] == 0 ):
a[r] = 1
r = int(math.fmod(r * k,p))
if (k == 0):
sets = p
elif(k == 1):
sets = p+1
res = 1
big = 1000000007
for i in range(sets-1):
res = int(math.fmod(res * p,big))
print(int(res))
```
| 99,068 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Tags: combinatorics, dfs and similar, dsu, math, number theory
Correct Solution:
```
__author__ = 'MoonBall'
import sys
# sys.stdin = open('data/D.in', 'r')
T = 1
M = 1000000007
def process():
P, K = list(map(int, input().split()))
k = [K * x % P for x in range(P)]
# print(k)
# f(0) = k[f(0)]
# f(1) = k[f(4)]
# f(2) = k[f(3)]
# f(3) = k[f(2)]
# f(4) = k[f(1)]
if not K:
print(pow(P, P - 1, M))
return
if K == 1:
print(pow(P, P, M))
return
f = [0] * P
c = [0] * P
ans = 1
for i in range(P):
if f[i]: continue
cnt = 1
u = i
f[u] = 1
while not f[k[u]]:
u = k[u]
f[u] = 1
cnt = cnt + 1
c[cnt] = c[cnt] + 1
# print(c)
for i in range(2, P):
if c[i] != 0:
cnt = i * c[i] + 1
ans = ans * pow(cnt, c[i], M) % M
print(ans)
for _ in range(T):
process()
```
| 99,069 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Tags: combinatorics, dfs and similar, dsu, math, number theory
Correct Solution:
```
import math
def expmod(base, expon, mod):
ans = 1
for i in range(1, expon + 1):
ans = (ans * base) % mod
return ans
p, k = input().split()
s = 10 ** 9 + 7
k = int(k)
p = int(p)
ord = 1
done = 0
if k == 0:
z = p - 1
if k == 1:
z = p
else:
for i in range(2,p + 1):
if done == 0:
if (p-1) % i == 0:
if expmod(k, i, p) == 1:
ord = i
done = 1
z = int((p-1) / ord)
rem = expmod(p, z, s)
print(int(rem))
```
| 99,070 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Tags: combinatorics, dfs and similar, dsu, math, number theory
Correct Solution:
```
def m_pow(x, y, m):
if y == 0:
return 1
if (y & 1):
return m_pow(x, y - 1, m) * x % m
else:
t = m_pow(x, y >> 1, m)
return t * t % m
#
(p, k) = map(int, input().split())
used = [0] * p
if k == 0:
print(m_pow(p, p - 1, 1000000007))
else:
c = 1 if k == 1 else 0
for x in range(1, p):
if not used[x]:
y = x
while not used[y]:
used[y] = True
y = k * y % p
c += 1
print(m_pow(p, c, 1000000007))
```
| 99,071 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Tags: combinatorics, dfs and similar, dsu, math, number theory
Correct Solution:
```
def main():
p, k = map(int, input().split())
s = 1
m = pow(10,9)+7
if k == 0:
s = pow(p,p-1,m)
elif k == 1:
s = pow(p,p,m)
else:
o = 1
n = k
while n != 1:
n = k*n %p
o += 1
c = (p-1)//o
s = pow(p,c,m)
print(s%m)
main()
# Made By Mostafa_Khaled
```
| 99,072 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Tags: combinatorics, dfs and similar, dsu, math, number theory
Correct Solution:
```
def divisors(n):
ans = set()
i = 1
while i * i <= n:
if n % i == 0:
ans.add(i)
ans.add(n // i)
i += 1
return sorted(list(ans))
mod = 10 ** 9 + 7
p, k = [int(x) for x in input().split()]
if k == 0:
print(pow(p, p - 1, mod))
elif k == 1:
print(pow(p, p, mod))
else:
for z in divisors(p - 1):
if ((p - 1) % z == 0) and (pow(k, z, p) == 1):
print(pow(p, (p - 1) // z, mod))
break
```
| 99,073 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Tags: combinatorics, dfs and similar, dsu, math, number theory
Correct Solution:
```
from sys import stdin
c = 10**9+7
p, k = stdin.readline().rstrip().split(' ')
p = int(p); k = int(k)
if k==0:
print(pow(p, p-1, c))
elif k==1:
print(pow(p, p, c))
else:
n = k
order = 1
while n != 1:
n = (n*k) % p
order += 1
loops = (p-1) // order
print(pow(p, loops, c))
```
| 99,074 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Submitted Solution:
```
p,k = map(int,input().split())
m = 10**9+7
if k == 0:
print(pow(p,p-1,m))
elif k == 1:
print(pow(p,p,m))
else:
used = [0]*p
res = 0
for i in range(1, p):
a = i
if used[a] == 0:
res += 1
while used[a] == 0:
used[a] = 1
a = k * a % p
print(pow(p, res, m))
```
Yes
| 99,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Submitted Solution:
```
def main():
p, k = map(int, input().split())
s = 1
m = pow(10,9)+7
if k == 0:
s = pow(p,p-1,m)
elif k == 1:
s = pow(p,p,m)
else:
o = 1
n = k
while n != 1:
n = k*n %p
o += 1
c = (p-1)//o
s = pow(p,c,m)
print(s%m)
main()
```
Yes
| 99,076 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Submitted Solution:
```
from sys import stdin
import sys
sys.setrecursionlimit(10**6)
n,k=map(int,stdin.readline().strip().split())
def dfs( n):
visited[n]=True
while not visited[adj[n]]:
n=adj[n]
visited[n]=True
mod=10**9+7
adj=[-1 for i in range(n+1)]
visited=[False for i in range(n+1)]
for i in range(n):
adj[i]=(i*k)%n
pairs=0
for i in range(1,n):
if not visited[i]:
dfs(i)
pairs+=1
if k==1:
print(pow(n,n,mod))
else:
print(pow(n,pairs,mod))
```
Yes
| 99,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Submitted Solution:
```
p, k = map(int, input().split())
M = 1000000007
if k == 0: print(pow(p, p - 1, M)), exit(0)
if k == 1: print(pow(p, p, M)), exit(0)
cnt, x = 0, 1
while 1:
cnt -= -1
x = (k * x) % p
if x == 1: break
print(pow(p, (p - 1) // cnt, M))
```
Yes
| 99,078 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Submitted Solution:
```
p, k = map(int, input().split())
a = [0 for i in range(p)]
count = 0
i = 0
NUM = 1000000007
def nextnum(i):
return i*k % p
while i<p:
while i<p and a[i]!=0:
i+=1
if i>=p:
break
count += 1
t = i
a[t] = count
t = nextnum(t)
a[t] = count
while t!=i and t!=0:
a[t] = count
t = nextnum(t)
ans = 1
for i in range(count-1):
ans = ans*p % NUM
print(ans)
```
No
| 99,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Submitted Solution:
```
from sys import stdin
p, k = stdin.readline().rstrip().split(' ')
p = int(p); k = int(k)
if k==0:
print(((p)**(p-1)) % (10**9+7))
else:
free = set(range(1, p))
loops = 0
while len(free) > 0:
n = free.pop()
l = (n*k)%p
while l != n:
free.remove(l)
l = (l*k) % p
loops += 1
print(p**loops % (10**9+7))
```
No
| 99,080 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Submitted Solution:
```
from fractions import gcd
from math import factorial
n,k = map(int,input().split())
if n==3:
print(3)
quit()
if n==5:
print(25)
if n==7:
print(49)
quit()
if n==11:
print((n-k)*factorial(n)+1)
```
No
| 99,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that
<image>
for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)
It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.
Input
The input consists of two space-separated integers p and k (3 β€ p β€ 1 000 000, 0 β€ k β€ p - 1) on a single line. It is guaranteed that p is an odd prime number.
Output
Print a single integer, the number of distinct functions f modulo 109 + 7.
Examples
Input
3 2
Output
3
Input
5 4
Output
25
Note
In the first sample, p = 3 and k = 2. The following functions work:
1. f(0) = 0, f(1) = 1, f(2) = 2.
2. f(0) = 0, f(1) = 2, f(2) = 1.
3. f(0) = f(1) = f(2) = 0.
Submitted Solution:
```
from math import ceil
def pow(x, n):
"""stripping the number *sexy music*"""
BIG_CHONKUS_PRIME = 1e9+7
ret = 1
num = x
while n > 0:
if n % 2:
ret *= num
ret %= BIG_CHONKUS_PRIME
num *= num
num %= BIG_CHONKUS_PRIME
n = n // 2
return int(ret)
def moo(p, k):
"""moodular magic"""
if k == 0:
return pow(p, p-1)
if k == 1:
return pow(p, p)
m = 1
temp = k
while m <= p:
m += 1
if temp == 1:
break
temp *= k
temp %= p
x = ceil((p - 1)/m)
return pow(p, x)
def main():
"""I/O, you know, it's main"""
p, k = tuple(map(int, input().split()))
print(moo(p, k))
main()
```
No
| 99,082 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ostap Bender recently visited frog farm and was inspired to create his own frog game.
Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board is cyclic, so cell number 1 goes right after the cell number m in the direction of movement. i-th frog during its turn can jump for ai cells.
Frogs move in turns, game starts with a move by frog 1. On its turn i-th frog moves ai cells forward, knocking out all the frogs on its way. If there is a frog in the last cell of the path of the i-th frog, that frog is also knocked out. After this the value ai is decreased by the number of frogs that were knocked out during this turn. If ai is zero or goes negative, then i-th frog doesn't make moves anymore.
After frog number 1 finishes its turn, frog number 2 starts to move, then frog number 3 and so on. After the frog number n makes its move, frog 1 starts to move again, then frog 2 and so on this process goes forever. If some frog was already knocked out from the board, we consider that it skips all its moves.
Help Ostap to identify, what frogs will stay on the board at the end of a game?
Input
First line of the input contains two integers n and m (1 β€ n β€ 100000, 1 β€ m β€ 109, n β€ m) β number of frogs and gameboard size, respectively.
Following n lines contains frogs descriptions β two integers pi and ai (1 β€ pi, ai β€ m) β the number of cell occupied by i-th frog initially and initial jump length. All pi are guaranteed to be distinct.
Output
In the first line output number of frogs on the final gameboard. In the second line output their numbers in any order.
Examples
Input
3 5
2 1
5 3
4 3
Output
1
3
Input
5 6
1 2
3 4
2 5
5 1
6 1
Output
2
1 4
Note
In the first sample first frog jumps 1 cell and finishes in cell number 3. Second frog jumps for 3 cells and finishes on cell number 3, knocking out frog number 1. Current jump length for frog number 2 is now 2. Third frog jumps to cell 2, then second frog jumps to cell 5. Third frog in turn finishes in cell 5 and removes frog 2 from the gameboard. Now, it's the only remaining frog in the game.
In the second sample first frog jumps 2 cells and knocks out frogs in cells 2 and 3. Its value ai is now 0. Then fourth frog jumps and knocks out fifth frog and its ai is now 0 too. These two frogs will remains on the gameboard forever.
Submitted Solution:
```
import collections
import math
n ,m = map(int, input().split())
A, f = [], 0
for i in range(n):
pos, a = map(int, input().split())
if not f and a == m:
f = i + i
A.append([i, pos % m, (pos + a) % m, a, 1])
if f:
print(1, f, sep='\n')
exit(0)
while True:
mi, mx = 1000000001, -1
B = []
for i in range(len(A)):
#print(A)
if A[i][4] == 0 or A[i][3] <= 0:
continue
for j in range(len(A)):
if i == j or A[j][4] == 0:
continue
#print('j: ', j, A, A[i][1] <= A[j][1] <= A[i][2], not(A[i][2] < A[j][1] < A[i][1]))
if A[i][1] <= A[j][1] <= A[i][2] or (A[i][2] <= A[j][1] and A[j][1] <= A[i][2]):
A[j][4] = 0
A[i][3] -= 1
A[i][1], A[i][2] = A[i][2], (A[i][2] + A[i][3]) % m
for i in range(len(A)):
if A[i][4]:
B.append(A[i])
if A[i][3] < mi:
mi = A[i][3]
if A[i][3] > mx:
mx = A[i][3]
A = B[:]
if mi == mx:
break
print(len(A))
print(' '.join(str(A[x][0] + 1) for x in range(len(A))))
```
No
| 99,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ostap Bender recently visited frog farm and was inspired to create his own frog game.
Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board is cyclic, so cell number 1 goes right after the cell number m in the direction of movement. i-th frog during its turn can jump for ai cells.
Frogs move in turns, game starts with a move by frog 1. On its turn i-th frog moves ai cells forward, knocking out all the frogs on its way. If there is a frog in the last cell of the path of the i-th frog, that frog is also knocked out. After this the value ai is decreased by the number of frogs that were knocked out during this turn. If ai is zero or goes negative, then i-th frog doesn't make moves anymore.
After frog number 1 finishes its turn, frog number 2 starts to move, then frog number 3 and so on. After the frog number n makes its move, frog 1 starts to move again, then frog 2 and so on this process goes forever. If some frog was already knocked out from the board, we consider that it skips all its moves.
Help Ostap to identify, what frogs will stay on the board at the end of a game?
Input
First line of the input contains two integers n and m (1 β€ n β€ 100000, 1 β€ m β€ 109, n β€ m) β number of frogs and gameboard size, respectively.
Following n lines contains frogs descriptions β two integers pi and ai (1 β€ pi, ai β€ m) β the number of cell occupied by i-th frog initially and initial jump length. All pi are guaranteed to be distinct.
Output
In the first line output number of frogs on the final gameboard. In the second line output their numbers in any order.
Examples
Input
3 5
2 1
5 3
4 3
Output
1
3
Input
5 6
1 2
3 4
2 5
5 1
6 1
Output
2
1 4
Note
In the first sample first frog jumps 1 cell and finishes in cell number 3. Second frog jumps for 3 cells and finishes on cell number 3, knocking out frog number 1. Current jump length for frog number 2 is now 2. Third frog jumps to cell 2, then second frog jumps to cell 5. Third frog in turn finishes in cell 5 and removes frog 2 from the gameboard. Now, it's the only remaining frog in the game.
In the second sample first frog jumps 2 cells and knocks out frogs in cells 2 and 3. Its value ai is now 0. Then fourth frog jumps and knocks out fifth frog and its ai is now 0 too. These two frogs will remains on the gameboard forever.
Submitted Solution:
```
f, gb = map(int, input().split())
frogs = []
for i in range(f):
pos, jump = map(int, input().split())
frogs.append([pos, jump])
for b in range(10000):
for i in range(len(frogs)):
if frogs[i][1] > 0:
a = 0
for x in range(frogs[i][1]):
frogs[i][0] += 1
if frogs[i][0] > gb:
frogs[i][0] = 1
for z in range(len(frogs)):
if z != i and frogs[z][0] == frogs[i][0] and frogs[z][1] > 0:
frogs[z][1] = -5
a += 1
frogs[i][1] -= a
if frogs[i][1] < 0:
frogs[i][1] = 0
ans = [0, []]
for i in range(len(frogs)):
if frogs[i][1] != -5:
ans[0] += 1
ans[1].append(str(i+1))
print(ans[0])
print(' '.join(ans[1]))
```
No
| 99,084 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ostap Bender recently visited frog farm and was inspired to create his own frog game.
Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board is cyclic, so cell number 1 goes right after the cell number m in the direction of movement. i-th frog during its turn can jump for ai cells.
Frogs move in turns, game starts with a move by frog 1. On its turn i-th frog moves ai cells forward, knocking out all the frogs on its way. If there is a frog in the last cell of the path of the i-th frog, that frog is also knocked out. After this the value ai is decreased by the number of frogs that were knocked out during this turn. If ai is zero or goes negative, then i-th frog doesn't make moves anymore.
After frog number 1 finishes its turn, frog number 2 starts to move, then frog number 3 and so on. After the frog number n makes its move, frog 1 starts to move again, then frog 2 and so on this process goes forever. If some frog was already knocked out from the board, we consider that it skips all its moves.
Help Ostap to identify, what frogs will stay on the board at the end of a game?
Input
First line of the input contains two integers n and m (1 β€ n β€ 100000, 1 β€ m β€ 109, n β€ m) β number of frogs and gameboard size, respectively.
Following n lines contains frogs descriptions β two integers pi and ai (1 β€ pi, ai β€ m) β the number of cell occupied by i-th frog initially and initial jump length. All pi are guaranteed to be distinct.
Output
In the first line output number of frogs on the final gameboard. In the second line output their numbers in any order.
Examples
Input
3 5
2 1
5 3
4 3
Output
1
3
Input
5 6
1 2
3 4
2 5
5 1
6 1
Output
2
1 4
Note
In the first sample first frog jumps 1 cell and finishes in cell number 3. Second frog jumps for 3 cells and finishes on cell number 3, knocking out frog number 1. Current jump length for frog number 2 is now 2. Third frog jumps to cell 2, then second frog jumps to cell 5. Third frog in turn finishes in cell 5 and removes frog 2 from the gameboard. Now, it's the only remaining frog in the game.
In the second sample first frog jumps 2 cells and knocks out frogs in cells 2 and 3. Its value ai is now 0. Then fourth frog jumps and knocks out fifth frog and its ai is now 0 too. These two frogs will remains on the gameboard forever.
Submitted Solution:
```
f, gb = map(int, input().split())
frogs = []
for i in range(f):
pos, jump = map(int, input().split())
frogs.append([pos, jump])
for b in range(100000):
for i in range(len(frogs)):
if frogs[i][1] > 0:
a = 0
for x in range(frogs[i][1]):
frogs[i][0] += 1
if frogs[i][0] > gb:
frogs[i][0] = 1
for z in range(len(frogs)):
if z != i and frogs[z][0] == frogs[i][0] and frogs[z][1] > 0:
frogs[z][1] = -5
a += 1
frogs[i][1] -= a
if frogs[i][1] < 0:
frogs[i][1] = 0
ans = [0, []]
for i in range(len(frogs)):
if frogs[i][1] != -5:
ans[0] += 1
ans[1].append(str(i+1))
print(ans[0])
print(' '.join(ans[1]))
```
No
| 99,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ostap Bender recently visited frog farm and was inspired to create his own frog game.
Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board is cyclic, so cell number 1 goes right after the cell number m in the direction of movement. i-th frog during its turn can jump for ai cells.
Frogs move in turns, game starts with a move by frog 1. On its turn i-th frog moves ai cells forward, knocking out all the frogs on its way. If there is a frog in the last cell of the path of the i-th frog, that frog is also knocked out. After this the value ai is decreased by the number of frogs that were knocked out during this turn. If ai is zero or goes negative, then i-th frog doesn't make moves anymore.
After frog number 1 finishes its turn, frog number 2 starts to move, then frog number 3 and so on. After the frog number n makes its move, frog 1 starts to move again, then frog 2 and so on this process goes forever. If some frog was already knocked out from the board, we consider that it skips all its moves.
Help Ostap to identify, what frogs will stay on the board at the end of a game?
Input
First line of the input contains two integers n and m (1 β€ n β€ 100000, 1 β€ m β€ 109, n β€ m) β number of frogs and gameboard size, respectively.
Following n lines contains frogs descriptions β two integers pi and ai (1 β€ pi, ai β€ m) β the number of cell occupied by i-th frog initially and initial jump length. All pi are guaranteed to be distinct.
Output
In the first line output number of frogs on the final gameboard. In the second line output their numbers in any order.
Examples
Input
3 5
2 1
5 3
4 3
Output
1
3
Input
5 6
1 2
3 4
2 5
5 1
6 1
Output
2
1 4
Note
In the first sample first frog jumps 1 cell and finishes in cell number 3. Second frog jumps for 3 cells and finishes on cell number 3, knocking out frog number 1. Current jump length for frog number 2 is now 2. Third frog jumps to cell 2, then second frog jumps to cell 5. Third frog in turn finishes in cell 5 and removes frog 2 from the gameboard. Now, it's the only remaining frog in the game.
In the second sample first frog jumps 2 cells and knocks out frogs in cells 2 and 3. Its value ai is now 0. Then fourth frog jumps and knocks out fifth frog and its ai is now 0 too. These two frogs will remains on the gameboard forever.
Submitted Solution:
```
import collections
import math
n ,m = map(int, input().split())
A, f = [], 0
for i in range(n):
pos, a = map(int, input().split())
#print(not f, a == m)
if (not f) and a == m:
f = i + 1
A.append([i, pos % m, (pos + a) % m, a, 1])
if f:
print(1, f, sep='\n')
exit(0)
while True:
mi, mx = 1000000001, -1
B = []
for i in range(len(A)):
#print(A)
if A[i][4] == 0 or A[i][3] <= 0:
continue
for j in range(len(A)):
if i == j or A[j][4] == 0:
continue
#print('j: ', j, A, A[i][1] <= A[j][1] <= A[i][2], not(A[i][2] < A[j][1] < A[i][1]))
if A[i][1] <= A[j][1] <= A[i][2] or (A[i][2] <= A[j][1] and A[j][1] <= A[i][2]):
A[j][4] = 0
A[i][3] -= 1
A[i][1], A[i][2] = A[i][2], (A[i][2] + A[i][3]) % m
for i in range(len(A)):
if A[i][4]:
B.append(A[i])
if A[i][3] < mi:
mi = A[i][3]
if A[i][3] > mx:
mx = A[i][3]
A = B[:]
if mi == mx:
break
print(len(A))
print(' '.join(str(A[x][0] + 1) for x in range(len(A))))
```
No
| 99,086 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Tags: math
Correct Solution:
```
a,b,c = map(int, input().split())
if a>b and c>0:
print('NO')
elif b>a and c<0:
print('NO')
elif a!=b and c==0:
print('NO')
elif a==b:
print('YES')
elif (b-a)==c or (b-a)%c==0:
print('YES')
else:
print('NO')
```
| 99,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Tags: math
Correct Solution:
```
def fx(a,b,c):
if (c==0 and a!=b) or (c>0 and a>b) or (c<0 and a<b):
return print("NO")
if (c==0 and a==b) or ((b-a)%c==0):
return print("Yes")
return print("NO")
a,b,c=input().split()
fx(int(a),int(b),int(c))
```
| 99,088 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Tags: math
Correct Solution:
```
inp = input('')
def returnstatus(inp):
firstelement, favnumber, diff = [int(i) for i in inp.split(' ')]
if diff == 0:
return 'YES' if firstelement == favnumber else 'NO'
return 'YES' if ((favnumber - firstelement)%diff == 0 and (favnumber - firstelement)/diff >=0) else 'NO'
print(returnstatus(inp))
```
| 99,089 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Tags: math
Correct Solution:
```
a, b, c = map(int, input().split(' '))
if ((a != b and c == 0) or (b > a and c < 0)):
print("NO")
elif ((a == b) or (b > a and c > 0 and ((b - a) % c == 0)) or (a > b and c < 0 and ((a - b) % c == 0))):
print("YES")
else:
print("NO")
```
| 99,090 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Tags: math
Correct Solution:
```
a,b,c=map(int,input().split())
if(b<a) and (c>0):
print("NO")
elif(b>a) and (c<0):
print("NO")
elif(c==0):
if (a==b):
print("YES")
else:
print("NO")
else:
b=b-a
if(b%c==0):
print("YES")
else:
print("NO")
```
| 99,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Tags: math
Correct Solution:
```
a, b, c = list(map(int, input().split()))
if c == 0:
print("YES" if a == b else "NO")
else:
print("YES" if (((b - a) % c == 0) and (((b - a) // c) >= 0)) else "NO")
```
| 99,092 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Tags: math
Correct Solution:
```
import math
inp = input()
a = int(inp.split()[0])
b = int(inp.split()[1])
c = int(inp.split()[2])
if c == 0:
if a == b:
print('YES')
else:
print('NO')
else:
flag = (b + c - a) / c
if flag > 0 and flag - math.floor(flag) == 0.0:
print('YES')
else:
print('NO')
```
| 99,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Tags: math
Correct Solution:
```
a,b,c = map(int,input().split())
if a == b:
print("YES")
elif a > b and c < 0 and (a-b)%c == 0:
print("YES")
elif a < b and c >0 and (b-a)%c == 0:
print("YES")
else:
print("NO")
```
| 99,094 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Submitted Solution:
```
a, b, c = map(int, input().split(' '))
if b > a and c > 0:
if (b-a) % c == 0:
print("YES")
else:
print("NO")
elif b <= a and c < 0:
if (a-b) % -c == 0:
print("YES")
else:
print("NO")
elif b == a:
print("YES")
else:
print("NO")
```
Yes
| 99,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Submitted Solution:
```
from sys import stdin
input = stdin.readline
a, b, c = map(int, input().split())
print(["NO", "YES"][ c > 0 and b >= a and not (b - a)%c or c < 0 and a >= b and not (b - a)%c or c == 0 and a == b])
```
Yes
| 99,096 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Submitted Solution:
```
if __name__ == "__main__":
#n, m = list(map(int, input().split()))
a, b, c = map(int, input().split())
if c == 0:
if a == b:
print("YES")
else:
print("NO")
elif (b - a) // c >= 0 and (b - a) % c == 0:
print("YES")
else:
print("NO")
```
Yes
| 99,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Submitted Solution:
```
a,b,c=map(int,input().split())
a
flag=0
if (b==a):
print ("YES")
elif(b<a)and (c>0):
print ("NO")
elif (b>a) and (c<0):
print ("NO")
elif (c==0):
print ("NO")
elif (c!=0) and (a%c==0) and (b%c==0):
print ("YES")
else:
if (c>0):
while (a<=b) and (flag==0):
if (a==b):
print ("YES")
flag=1
break
else:
a+=c
flag=0
if (flag==0):
print ("NO")
else:
while (a>=b) and (flag==0):
if (a==b):
print ("YES")
flag=1
break
else:
a+=c
flag=0
if (flag==0):
print ("NO")
```
Yes
| 99,098 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 β€ a, b, c β€ 109) β the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Examples
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
Note
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
Submitted Solution:
```
a,b,c = map(int,input().split())
if c!=0:
if b>a and (b-a)%c == 0:
print('YES')
else:
print('NO')
else:
if b==a:
print('YES')
else :
print('NO')
```
No
| 99,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.