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.
Diana loves playing with numbers. She's got n cards with positive integer numbers a_i written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers a_i written on them.
Diana is happy when the product of the numbers ends with her favorite digit d. Now she is curious what cards she should pick so that the product of the numbers on them is the largest possible and the last decimal digit of the product is d. Please, help her.
Input
The first line contains the integers n and d (1β€ nβ€ 10^5, 0β€ dβ€ 9). The second line contains n integers a_i (1β€ a_iβ€ 1000).
Output
On the first line, print the number of chosen cards k (1β€ kβ€ n). On the next line, print the numbers written on the chosen cards in any order.
If it is impossible to choose a subset of cards with the product that ends with the digit d, print the single line with -1.
Examples
Input
6 4
4 11 8 2 1 13
Output
5
1 2 4 11 13
Input
3 1
2 4 6
Output
-1
Input
5 7
1 3 1 5 3
Output
-1
Input
6 3
8 9 4 17 11 5
Output
3
9 11 17
Input
5 6
2 2 2 2 2
Output
4
2 2 2 2
Note
In the first example, 1 Γ 2 Γ 4 Γ 11 Γ 13 = 1144, which is the largest product that ends with the digit 4. The same set of cards without the number 1 is also a valid answer, as well as a set of 8, 11, and 13 with or without 1 that also has the product of 1144.
In the second example, all the numbers on the cards are even and their product cannot end with an odd digit 1.
In the third example, the only possible products are 1, 3, 5, 9, 15, and 45, none of which end with the digit 7.
In the fourth example, 9 Γ 11 Γ 17 = 1683, which ends with the digit 3.
In the fifth example, 2 Γ 2 Γ 2 Γ 2 = 16, which ends with the digit 6.
Submitted Solution:
```
#coding:utf-8
'''
Created on 2021εΉ΄4ζ6ζ₯
@author: lzh
'''
import math
n, d = map(int, input().split())
arr = [int(_) for _ in input().split()]
dp = [[0 for _ in range(0, 10)] for _ in range(n + 1)]
path = [[(0, 0, 0) for _ in range(0, 10)] for _ in range(n + 1)]
for i in range(n):
dp[i + 1][arr[i]%10] = math.log(arr[i])
path[i + 1][arr[i]%10] = (i, arr[i]%10, 1)
for i in range(n) :
for j in range(10):
val = dp[i][j] + math.log(arr[i])
if dp[i + 1][(j * arr[i])%10] < val:
dp[i + 1][(j * arr[i])%10] = val
path[i + 1][(j * arr[i])%10] = (i, j, 1)
val = dp[i][j]
if dp[i + 1][j] < val:
dp[i + 1][j] = val
path[i + 1][j] = (i, j , 0)
ans = []
while n > 0 :
if path[n][d][2] == 1:
ans.append(arr[n - 1])
n,d = path[n][d][:2]
if len(ans) > 0:
print(len(ans))
print(' '.join(map(str, ans)))
else:
print(-1)
```
No
| 106,400 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Diana loves playing with numbers. She's got n cards with positive integer numbers a_i written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers a_i written on them.
Diana is happy when the product of the numbers ends with her favorite digit d. Now she is curious what cards she should pick so that the product of the numbers on them is the largest possible and the last decimal digit of the product is d. Please, help her.
Input
The first line contains the integers n and d (1β€ nβ€ 10^5, 0β€ dβ€ 9). The second line contains n integers a_i (1β€ a_iβ€ 1000).
Output
On the first line, print the number of chosen cards k (1β€ kβ€ n). On the next line, print the numbers written on the chosen cards in any order.
If it is impossible to choose a subset of cards with the product that ends with the digit d, print the single line with -1.
Examples
Input
6 4
4 11 8 2 1 13
Output
5
1 2 4 11 13
Input
3 1
2 4 6
Output
-1
Input
5 7
1 3 1 5 3
Output
-1
Input
6 3
8 9 4 17 11 5
Output
3
9 11 17
Input
5 6
2 2 2 2 2
Output
4
2 2 2 2
Note
In the first example, 1 Γ 2 Γ 4 Γ 11 Γ 13 = 1144, which is the largest product that ends with the digit 4. The same set of cards without the number 1 is also a valid answer, as well as a set of 8, 11, and 13 with or without 1 that also has the product of 1144.
In the second example, all the numbers on the cards are even and their product cannot end with an odd digit 1.
In the third example, the only possible products are 1, 3, 5, 9, 15, and 45, none of which end with the digit 7.
In the fourth example, 9 Γ 11 Γ 17 = 1683, which ends with the digit 3.
In the fifth example, 2 Γ 2 Γ 2 Γ 2 = 16, which ends with the digit 6.
Submitted Solution:
```
from math import prod
from itertools import combinations
from operator import itemgetter
def main():
n,d = list(map(int,input().split()))
a = list(map(int,input().split()))
if d%2==1:
a = [m for m in a if m%2==1]
p = [m%10 for m in a]
ind = [m for m in range(len(a))]
else:
p = [m%10 for m in a]
ind = [m for m in range(len(a))]
a.sort()
a.reverse()
for k in range(n,1,-1):
combi = list(combinations(ind,k))
for i in combi:
if prod(itemgetter(*i)(p)) % 10 == d:
return itemgetter(*i)(a)
return 0
l = main()
if l:
print(len(l))
print(*l)
else:
print(-1)
```
No
| 106,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Diana loves playing with numbers. She's got n cards with positive integer numbers a_i written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers a_i written on them.
Diana is happy when the product of the numbers ends with her favorite digit d. Now she is curious what cards she should pick so that the product of the numbers on them is the largest possible and the last decimal digit of the product is d. Please, help her.
Input
The first line contains the integers n and d (1β€ nβ€ 10^5, 0β€ dβ€ 9). The second line contains n integers a_i (1β€ a_iβ€ 1000).
Output
On the first line, print the number of chosen cards k (1β€ kβ€ n). On the next line, print the numbers written on the chosen cards in any order.
If it is impossible to choose a subset of cards with the product that ends with the digit d, print the single line with -1.
Examples
Input
6 4
4 11 8 2 1 13
Output
5
1 2 4 11 13
Input
3 1
2 4 6
Output
-1
Input
5 7
1 3 1 5 3
Output
-1
Input
6 3
8 9 4 17 11 5
Output
3
9 11 17
Input
5 6
2 2 2 2 2
Output
4
2 2 2 2
Note
In the first example, 1 Γ 2 Γ 4 Γ 11 Γ 13 = 1144, which is the largest product that ends with the digit 4. The same set of cards without the number 1 is also a valid answer, as well as a set of 8, 11, and 13 with or without 1 that also has the product of 1144.
In the second example, all the numbers on the cards are even and their product cannot end with an odd digit 1.
In the third example, the only possible products are 1, 3, 5, 9, 15, and 45, none of which end with the digit 7.
In the fourth example, 9 Γ 11 Γ 17 = 1683, which ends with the digit 3.
In the fifth example, 2 Γ 2 Γ 2 Γ 2 = 16, which ends with the digit 6.
Submitted Solution:
```
import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
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 input(): return sys.stdin.readline().rstrip("\r\n")
# n = 0
# m = 0
# n = int(input())
# li = [int(i) for i in input().split()]
# s = sorted(li)
"""
from dataclasses import dataclass
@dataclass
class point:
x: float
y: float
@dataclass
class line:
A: float
B: float
C: float
def gety(self, x):
return (self.A*x+self.C)/-self.B
def getx(self, y):
return (self.B*y+self.C)/-self.A
def k(self):
return -self.A/self.B
def b(self):
return -self.C/self.B
def dist(self, p: point):
return abs((self.A*p.x+self.B*p.y+self.C)/(self.A**2+self.B**2)**0.5)
def calc_line(u: point, v: point):
return line(A=u.y-v.y, B=v.x-u.x, C=u.y*(u.x-v.x)-u.x*(u.y-v.y))
def is_parallel(u: line, v: line) -> bool:
f1 = False
f2 = False
try:
k1 = u.k()
except:
f1 = True
try:
k2 = v.k()
except:
f2 = True
if f1 != f2:
return False
return f1 or k1 == k2
def seg_len(_from: point, _to: point):
return ((_from.x - _to.x)**2 + (_from.y - _to.y)**2) ** 0.5
def in_range(_from: point, _to: point, _point: point) -> bool:
if _from.x < _to.x:
if _from.y < _to.y:
return _from.x <= _point.x <= _to.x and _from.y <= _point.y <= _to.y
else:
return _from.x <= _point.x <= _to.x and _from.y >= _point.y >= _to.y
else:
if _from.y < _to.y:
return _from.x >= _point.x >= _to.x and _from.y <= _point.y <= _to.y
else:
return _from.x >= _point.x >= _to.x and _from.y >= _point.y >= _to.y
def intersect(u: line, v: line) -> point:
tx = (u.B*v.C-v.B*u.C)/(v.B*u.A-u.B*v.A)
if u.B!=0.0:
ty = -u.A*tx/u.B - u.C/u.B
else:
ty = -v.A*tx/v.B - v.C/v.B
return point(x=tx, y=ty)
def in_direction(_from: point, _to: point, _point: point) -> bool:
if _from.x < _to.x:
if _from.y < _to.y:
return _to.x < _point.x and _to.y < _point.y
else:
return _to.x < _point.x and _point.y <= _to.y
else:
if _from.y < _to.y:
return _to.x >= _point.x and _to.y < _point.y
else:
return _to.x >= _point.x and _point.y <= _to.y
"""
mo = int(1e9+7)
def exgcd(a, b):
if not b:
return 1, 0
y, x = exgcd(b, a % b)
y -= a//b * x
return x, y
def getinv(a, m):
x, y = exgcd(a, m)
return -1 if x == 1 else x % m
def comb(n, b):
res = 1
b = min(b, n-b)
for i in range(b):
res = res*(n-i)*getinv(i+1, mo) % mo
# res %= mo
return res % mo
def quickpower(a, n):
res = 1
while n:
if n & 1:
res = res * a % mo
n >>= 1
a = a*a % mo
return res
def dis(a, b):
return abs(a[0]-b[0]) + abs(a[1]-b[1])
def getpref(x):
if x > 1:
return (x)*(x-1) >> 1
else:
return 0
def orafli(upp):
primes = []
marked = [False for i in range(upp+3)]
prvs = [i for i in range(upp+3)]
for i in range(2, upp):
if not marked[i]:
primes.append(i)
for j in primes:
if i*j >= upp:
break
marked[i*j] = True
prvs[i*j] = j
if i % j == 0:
break
return primes, prvs
def lower_ord(c: str) -> int:
return ord(c)-97
def upper_ord(c: str) -> int:
return ord(c) - 65
def read_list():
return [int(i) for i in input().split()]
def read_int():
s = input().split()
if len(s) == 1:
return int(s[0])
else:
return map(int, s)
def ask(s):
print(f"? {s}", flush=True)
def answer(s):
print(f"{s}", flush=True)
import random
def solve():
n, d = read_int()
l = read_list()
# dp = [[0 for i in range(10)] for i in range(n)]
dp = {}
pv = []
for i in l:
cd = copy.deepcopy(dp)
cp = {}
for k, v in dp.items():
lg = math.log(i,2)
if v+lg >cd.get(k*i%10,1):
# prvcd = cd[k*i%10]
cp[v+lg] = v
cd[k*i%10] = v+lg
# cd[k*i%10] = max(cd.get(k*i%10, 1), v+math.log(i,2))
lg = math.log(i,2)
if lg > cd.get(i%10, 1):
cp[lg]=cd.get(i%10,1)
cd[i%10] = lg
pv.append(cp)
# cd[i%10] = max(cd.get(i%10, 1), math.log(i,2))
dp = cd
sel = []
if d not in dp:
print(-1)
else:
# print(dp[d])
# c = int(round(2**dp[d]))
# print(pv)
c = dp[d]
# rc = round(c,14)
while pv:
fac = pv.pop()
curfac = l.pop()
if c in fac:
sel.append(curfac)
c = fac[c]
# for i in l:
# if c%i==0:
# sel.append(i)
# c//=i
print(len(sel))
print(*sel)
# print(dp.get(d, -1))
# fi = open('C:\\cppHeaders\\CF2020.12.17\\test.data', 'r')
# def input(): return fi.readline().rstrip("\r\n")
# primes, prv = orafli(10001)
solve()
# t = int(input())
# for ti in range(t):
# print(f"Case #{ti+1}: ", end='')
# solve()
```
No
| 106,402 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Diana loves playing with numbers. She's got n cards with positive integer numbers a_i written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers a_i written on them.
Diana is happy when the product of the numbers ends with her favorite digit d. Now she is curious what cards she should pick so that the product of the numbers on them is the largest possible and the last decimal digit of the product is d. Please, help her.
Input
The first line contains the integers n and d (1β€ nβ€ 10^5, 0β€ dβ€ 9). The second line contains n integers a_i (1β€ a_iβ€ 1000).
Output
On the first line, print the number of chosen cards k (1β€ kβ€ n). On the next line, print the numbers written on the chosen cards in any order.
If it is impossible to choose a subset of cards with the product that ends with the digit d, print the single line with -1.
Examples
Input
6 4
4 11 8 2 1 13
Output
5
1 2 4 11 13
Input
3 1
2 4 6
Output
-1
Input
5 7
1 3 1 5 3
Output
-1
Input
6 3
8 9 4 17 11 5
Output
3
9 11 17
Input
5 6
2 2 2 2 2
Output
4
2 2 2 2
Note
In the first example, 1 Γ 2 Γ 4 Γ 11 Γ 13 = 1144, which is the largest product that ends with the digit 4. The same set of cards without the number 1 is also a valid answer, as well as a set of 8, 11, and 13 with or without 1 that also has the product of 1144.
In the second example, all the numbers on the cards are even and their product cannot end with an odd digit 1.
In the third example, the only possible products are 1, 3, 5, 9, 15, and 45, none of which end with the digit 7.
In the fourth example, 9 Γ 11 Γ 17 = 1683, which ends with the digit 3.
In the fifth example, 2 Γ 2 Γ 2 Γ 2 = 16, which ends with the digit 6.
Submitted Solution:
```
n, d = [int(s) for s in input().split(' ')]
a = [int(s) for s in input().split(' ')]
aDig = [[] for _ in range(10)]
for x in a:
aDig[x % 10].append(x)
for ad in aDig:
ad.sort()
c0 = len(aDig[0])
c5 = len(aDig[5])
c1379 = len(aDig[1]) + len(aDig[3]) + len(aDig[7]) + len(aDig[9])
c2468 = len(aDig[2]) + len(aDig[4]) + len(aDig[6]) + len(aDig[8])
def solveMod5(r3, r7, r9, m5):
prod, prodList = 0, []
for a in range(len(r3) + 1):
for b in range(len(r7) + 1):
for c in range(len(r9) + 1):
currList = []
if a:
currList += r3[-a:]
if b:
currList += r7[-b:]
if c:
currList += r9[-c:]
r = 1
for t in currList:
r *= t
if r % 5 == m5 and r > prod:
prod = r
prodList = currList
return prod, prodList
if d == 0:
if c0 or (c2468 and c5):
print(n)
print(*a)
else:
print(-1)
elif d == 5:
if c5:
print(c5 + c1379)
print(*[x for x in a if x & 1])
else:
print(-1)
else:
usedSurely = aDig[1]
if d % 2 == 0 and (len(aDig[2]) >= 7 or len(aDig[4]) >= 3 or len(aDig[6]) >= 1 or len(aDig[8]) >= 7):
for ev in [2, 4, 6, 8]:
aDig[(ev + 5) % 10] += aDig[ev]
d = (d + 5) % 10
# ---------------------------------------
for t in [3, 7]:
while len(aDig[t]) >= 7:
usedSurely += aDig[t][-4:]
for _ in range(4):
aDig[t].pop()
while len(aDig[9]) >= 3:
usedSurely += aDig[t][-2:]
for _ in range(2):
aDig[9].pop()
# ---------------------------------------
if d & 1:
d5 = d % 5
prod, prodList = solveMod5(aDig[3], aDig[7], aDig[9], d5)
if prod and len(prodList) + len(usedSurely):
print(len(prodList) + len(usedSurely))
print(*prodList, *usedSurely)
else:
print(-1)
else:
d5 = d % 5
prod, prodList = 0, []
for ev in [2, 4, 6, 8]:
if not len(aDig[ev]):
continue
save = aDig[ev][-1]
aDig[ev].pop()
dd5 = (d5 * pow(save, -1, 5)) % 5
currProd, currProdList = solveMod5(sorted(aDig[3] + aDig[8]), sorted(aDig[7] + aDig[2]),
sorted(aDig[9] + aDig[4]), dd5)
currProd *= save
currProdList.append(save)
if currProd > prod:
prod = currProd
prodList = currProdList
aDig[ev].append(save)
if prod and len(prodList) + len(usedSurely):
print(len(prodList) + len(usedSurely))
print(*prodList, *usedSurely)
else:
print(-1)
```
No
| 106,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar and Akmar are playing a game on a circular board with n (2 β€ n β€ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 β€ i β€ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, with Akmar going first. The letter must be placed on an empty cell. In addition, the letter cannot be placed adjacent to a cell containing the same letter.
A player loses when it is their turn and there are no more valid moves.
Output the number of possible distinct games where both players play optimally modulo 10^9+7. Note that we only consider games where some player has lost and there are no more valid moves.
Two games are considered distinct if the number of turns is different or for some turn, the letter or cell number that the letter is placed on were different.
A move is considered optimal if the move maximizes the player's chance of winning, assuming the other player plays optimally as well. More formally, if the player who has to move has a winning strategy, they have to make a move after which they will still have a winning strategy. If they do not, they can make any move.
Input
The only line will contain an integer n (2 β€ n β€ 10^6) β the number of cells on the board.
Output
Output a single integer β the number of possible distinct games where both players play optimally modulo 10^9+7.
Examples
Input
2
Output
4
Input
69420
Output
629909355
Input
42069
Output
675837193
Note
For the first sample case, the first player has 4 possible moves. No matter what the first player plays, the second player only has 1 possible move, so there are 4 possible games.
Tags: chinese remainder theorem, combinatorics, constructive algorithms, fft, games, geometry, math, meet-in-the-middle, string suffix structures
Correct Solution:
```
from sys import stdin
def getInt():
return int(stdin.readline().strip())
def bruteForce(n):
x = [[i,j] for i in range(3) for j in range(3) if i != j]
for k in range(2, n):
x = [a+[i] for a in x for i in range(3) if i != a[-1] and ((a[-1] != 0) or (i != a[-2]))]
x = [z for z in x if z[0] != z[-1] and ((z[0] != 0) or (z[1] != z[-1]))
and ((z[-1] != 0) or (z[0] != z[-2]))]
ans = 0
for p in x:
sc = len([z for z in p if z != 0])
k = 1
for i in range(1, sc + 1):
k *= i
ans += k
return ans
P = (10**9)+7
fcache = [1]
def factorial(n):
while len(fcache) <= n:
fcache.append((fcache[-1] * len(fcache)) % P)
return fcache[n]
def binom(n, k):
return (factorial(n)*pow(factorial(k) * factorial(n - k),P-2,P)) % P
def simpler(n):
ans = 0
i = (n % 2)
while (i * 2) <= n:
k = factorial(n - i)
if i == 0:
t = 1
else:
t = binom(n-i,i) + binom((n-2)-(i-1),i-1)
ans += 2 * k * t
i += 2
return ans % P
print(simpler(getInt()))
```
| 106,404 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar and Akmar are playing a game on a circular board with n (2 β€ n β€ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 β€ i β€ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, with Akmar going first. The letter must be placed on an empty cell. In addition, the letter cannot be placed adjacent to a cell containing the same letter.
A player loses when it is their turn and there are no more valid moves.
Output the number of possible distinct games where both players play optimally modulo 10^9+7. Note that we only consider games where some player has lost and there are no more valid moves.
Two games are considered distinct if the number of turns is different or for some turn, the letter or cell number that the letter is placed on were different.
A move is considered optimal if the move maximizes the player's chance of winning, assuming the other player plays optimally as well. More formally, if the player who has to move has a winning strategy, they have to make a move after which they will still have a winning strategy. If they do not, they can make any move.
Input
The only line will contain an integer n (2 β€ n β€ 10^6) β the number of cells on the board.
Output
Output a single integer β the number of possible distinct games where both players play optimally modulo 10^9+7.
Examples
Input
2
Output
4
Input
69420
Output
629909355
Input
42069
Output
675837193
Note
For the first sample case, the first player has 4 possible moves. No matter what the first player plays, the second player only has 1 possible move, so there are 4 possible games.
Tags: chinese remainder theorem, combinatorics, constructive algorithms, fft, games, geometry, math, meet-in-the-middle, string suffix structures
Correct Solution:
```
from sys import stdin, gettrace
if gettrace():
def inputi():
return input()
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
MOD = 1000000007
def main():
n = int(input())
factorial = [1]
for i in range(1, n+1):
factorial.append((factorial[-1] * i) % MOD)
res = 0
for i in range((n+1)//2+((n+1)//2)%2, n+1, 2):
if i == n:
res = (res + factorial[n])%MOD
else:
num1 = factorial[i]
denom1 = (factorial[n-i]*factorial[2*i -n])%MOD
num2 = factorial[i-1]
denom2 = (factorial[n-i-1]*factorial[2*i -n])%MOD
res = (res + (pow(denom1, MOD-2, MOD)*num1 + pow(denom2, MOD-2, MOD)*num2)*factorial[i])%MOD
print((res*2)%MOD)
if __name__ == "__main__":
main()
```
| 106,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar and Akmar are playing a game on a circular board with n (2 β€ n β€ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 β€ i β€ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, with Akmar going first. The letter must be placed on an empty cell. In addition, the letter cannot be placed adjacent to a cell containing the same letter.
A player loses when it is their turn and there are no more valid moves.
Output the number of possible distinct games where both players play optimally modulo 10^9+7. Note that we only consider games where some player has lost and there are no more valid moves.
Two games are considered distinct if the number of turns is different or for some turn, the letter or cell number that the letter is placed on were different.
A move is considered optimal if the move maximizes the player's chance of winning, assuming the other player plays optimally as well. More formally, if the player who has to move has a winning strategy, they have to make a move after which they will still have a winning strategy. If they do not, they can make any move.
Input
The only line will contain an integer n (2 β€ n β€ 10^6) β the number of cells on the board.
Output
Output a single integer β the number of possible distinct games where both players play optimally modulo 10^9+7.
Examples
Input
2
Output
4
Input
69420
Output
629909355
Input
42069
Output
675837193
Note
For the first sample case, the first player has 4 possible moves. No matter what the first player plays, the second player only has 1 possible move, so there are 4 possible games.
Tags: chinese remainder theorem, combinatorics, constructive algorithms, fft, games, geometry, math, meet-in-the-middle, string suffix structures
Correct Solution:
```
import sys
sys.stderr = sys.stdout
M = 10**9 + 7
def modinv(a):
r0 = a
r1 = M
s0 = 1
s1 = 0
t0 = 0
t1 = 1
while r1:
q = r0 // r1
r0, r1 = r1, r0 - q*r1
s0, s1 = s1, s0 - q*s1
t0, t1 = t1, t0 - q*t1
if s0 < M:
s0 += M
return s0
def choose(a, b, I):
b = min(b, a-b)
c = 1
for i in range(b):
c = (c * (a-i)) % M
c = (c * I[b-i]) % M
return c
def games(n):
I = [None] * (n+1)
for i in range(1, n+1):
I[i] = modinv(i)
s = 0
k0 = (n + 3) // 4
k1 = n // 2
c = choose(2*k0, n - 2*k0, I)
for i in range(2, 2*k0):
c = (c * i) % M
s = c
for k in range(k0, k1):
k_2 = k*2
for i in (k_2 + 2, k_2 + 1, k_2 + 1, k_2,
n - k_2, n - k_2 - 1):
c = (c * i) % M
k_4_n = k*4 - n
for j in (k_4_n + 1, k_4_n + 2, k_4_n + 3, k_4_n + 4):
c = (c * I[j]) % M
s = (s + c) % M
return (2 * n * s) % M
def main():
n = readint()
print(games(n))
##########
def readint():
return int(input())
def readinti():
return map(int, input().split())
def readintt():
return tuple(readinti())
def readintl():
return list(readinti())
def readinttl(k):
return [readintt() for _ in range(k)]
def readintll(k):
return [readintl() for _ in range(k)]
def log(*args, **kwargs):
print(*args, **kwargs, file=sys.__stderr__)
if __name__ == '__main__':
main()
```
| 106,406 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar and Akmar are playing a game on a circular board with n (2 β€ n β€ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 β€ i β€ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, with Akmar going first. The letter must be placed on an empty cell. In addition, the letter cannot be placed adjacent to a cell containing the same letter.
A player loses when it is their turn and there are no more valid moves.
Output the number of possible distinct games where both players play optimally modulo 10^9+7. Note that we only consider games where some player has lost and there are no more valid moves.
Two games are considered distinct if the number of turns is different or for some turn, the letter or cell number that the letter is placed on were different.
A move is considered optimal if the move maximizes the player's chance of winning, assuming the other player plays optimally as well. More formally, if the player who has to move has a winning strategy, they have to make a move after which they will still have a winning strategy. If they do not, they can make any move.
Input
The only line will contain an integer n (2 β€ n β€ 10^6) β the number of cells on the board.
Output
Output a single integer β the number of possible distinct games where both players play optimally modulo 10^9+7.
Examples
Input
2
Output
4
Input
69420
Output
629909355
Input
42069
Output
675837193
Note
For the first sample case, the first player has 4 possible moves. No matter what the first player plays, the second player only has 1 possible move, so there are 4 possible games.
Tags: chinese remainder theorem, combinatorics, constructive algorithms, fft, games, geometry, math, meet-in-the-middle, string suffix structures
Correct Solution:
```
import sys
input = sys.stdin.readline
n = int(input())
mod = 10 ** 9 + 7
F = [0] * (n + 1)
F[0] = 1
for i in range(1, n + 1):
F[i] = i * F[i - 1] % mod
iF = [0] * (n + 1)
iF[-1] = pow(F[-1], mod - 2, mod)
for i in range(n - 1, -1, -1):
iF[i] = iF[i + 1] * (i + 1) % mod
def C(n, k):
if k > n: return 0
return F[n] * iF[n - k] * iF[k] % mod
ans = 0
for x in range((n + 1) // 2, n + 1):
if x % 2: continue
if x < n: cur = (C(x, n - x) + C(x - 1, n - x - 1)) % mod
else: cur = 1
cur = (cur * 2 * F[x]) % mod
ans = (ans + cur) % mod
print(ans)
```
| 106,407 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar and Akmar are playing a game on a circular board with n (2 β€ n β€ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 β€ i β€ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, with Akmar going first. The letter must be placed on an empty cell. In addition, the letter cannot be placed adjacent to a cell containing the same letter.
A player loses when it is their turn and there are no more valid moves.
Output the number of possible distinct games where both players play optimally modulo 10^9+7. Note that we only consider games where some player has lost and there are no more valid moves.
Two games are considered distinct if the number of turns is different or for some turn, the letter or cell number that the letter is placed on were different.
A move is considered optimal if the move maximizes the player's chance of winning, assuming the other player plays optimally as well. More formally, if the player who has to move has a winning strategy, they have to make a move after which they will still have a winning strategy. If they do not, they can make any move.
Input
The only line will contain an integer n (2 β€ n β€ 10^6) β the number of cells on the board.
Output
Output a single integer β the number of possible distinct games where both players play optimally modulo 10^9+7.
Examples
Input
2
Output
4
Input
69420
Output
629909355
Input
42069
Output
675837193
Note
For the first sample case, the first player has 4 possible moves. No matter what the first player plays, the second player only has 1 possible move, so there are 4 possible games.
Submitted Solution:
```
n=int(input())
val=0
m=10^9+7
while n>1:
val=val+(2*n)
n-=1
print(val)
```
No
| 106,408 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar and Akmar are playing a game on a circular board with n (2 β€ n β€ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 β€ i β€ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, with Akmar going first. The letter must be placed on an empty cell. In addition, the letter cannot be placed adjacent to a cell containing the same letter.
A player loses when it is their turn and there are no more valid moves.
Output the number of possible distinct games where both players play optimally modulo 10^9+7. Note that we only consider games where some player has lost and there are no more valid moves.
Two games are considered distinct if the number of turns is different or for some turn, the letter or cell number that the letter is placed on were different.
A move is considered optimal if the move maximizes the player's chance of winning, assuming the other player plays optimally as well. More formally, if the player who has to move has a winning strategy, they have to make a move after which they will still have a winning strategy. If they do not, they can make any move.
Input
The only line will contain an integer n (2 β€ n β€ 10^6) β the number of cells on the board.
Output
Output a single integer β the number of possible distinct games where both players play optimally modulo 10^9+7.
Examples
Input
2
Output
4
Input
69420
Output
629909355
Input
42069
Output
675837193
Note
For the first sample case, the first player has 4 possible moves. No matter what the first player plays, the second player only has 1 possible move, so there are 4 possible games.
Submitted Solution:
```
import __pypy__
int_add = __pypy__.intop.int_add
int_sub = __pypy__.intop.int_sub
int_mul = __pypy__.intop.int_mul
mod=10**9+7
def make_mod_mul():
fmod_inv = 1.0 / mod
def mod_mul(a, b, c=0):
res = int_sub(int_add(int_mul(a, b), c), int_mul(mod, int(fmod_inv * a * b + fmod_inv * c)))
if res >= mod:
return res - mod
elif res < 0:
return res + mod
else:
return res
return mod_mul
mod_mul = make_mod_mul()
def mod_pow(x, y):
if y == 0:
return 1
res = 1
while y > 1:
if y & 1 == 1:
res = mod_mul(res, x)
x = mod_mul(x, x)
y >>= 1
return mod_mul(res, x)
max_n=10**6
fact, inv_fact = [0] * (max_n+1), [0] * (max_n+1)
fact[0] = 1
def make_nCr_mod():
global fact
global inv_fact
for i in range(max_n):
fact[i + 1] = mod_mul(fact[i],(i + 1))
inv_fact[-1] = mod_pow(fact[-1], mod - 2)
for i in reversed(range(max_n)):
inv_fact[i] = mod_mul(inv_fact[i + 1],(i + 1))
make_nCr_mod()
def nCr_mod(n, r):
global fact
global inv_fact
res = 1
while n or r:
a, b = n % mod, r % mod
if(a < b):
return 0
res = mod_mul(mod_mul(mod_mul(res,fact[a]),inv_fact[b]),inv_fact[a-b])
n //= mod
r //= mod
return res
import sys
input=sys.stdin.readline
n=int(input())
if(n%2==0):
ans=mod_mul(2,fact[n])
else:
ans=0
for r in range(2-(n%2),(n//2+1),2): #n-r must be divible by 2
ans+=mod_mul(mod_mul(nCr_mod(n-r-1,r-1),mod_pow(r,mod-2)),fact[n-r])
#n circular objects select r such that no two adjacent = n/r * (n-r-1)C(r-1)
print(mod_mul(ans,2*n))
```
No
| 106,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar and Akmar are playing a game on a circular board with n (2 β€ n β€ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 β€ i β€ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, with Akmar going first. The letter must be placed on an empty cell. In addition, the letter cannot be placed adjacent to a cell containing the same letter.
A player loses when it is their turn and there are no more valid moves.
Output the number of possible distinct games where both players play optimally modulo 10^9+7. Note that we only consider games where some player has lost and there are no more valid moves.
Two games are considered distinct if the number of turns is different or for some turn, the letter or cell number that the letter is placed on were different.
A move is considered optimal if the move maximizes the player's chance of winning, assuming the other player plays optimally as well. More formally, if the player who has to move has a winning strategy, they have to make a move after which they will still have a winning strategy. If they do not, they can make any move.
Input
The only line will contain an integer n (2 β€ n β€ 10^6) β the number of cells on the board.
Output
Output a single integer β the number of possible distinct games where both players play optimally modulo 10^9+7.
Examples
Input
2
Output
4
Input
69420
Output
629909355
Input
42069
Output
675837193
Note
For the first sample case, the first player has 4 possible moves. No matter what the first player plays, the second player only has 1 possible move, so there are 4 possible games.
Submitted Solution:
```
print(2)
```
No
| 106,410 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar and Akmar are playing a game on a circular board with n (2 β€ n β€ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 β€ i β€ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, with Akmar going first. The letter must be placed on an empty cell. In addition, the letter cannot be placed adjacent to a cell containing the same letter.
A player loses when it is their turn and there are no more valid moves.
Output the number of possible distinct games where both players play optimally modulo 10^9+7. Note that we only consider games where some player has lost and there are no more valid moves.
Two games are considered distinct if the number of turns is different or for some turn, the letter or cell number that the letter is placed on were different.
A move is considered optimal if the move maximizes the player's chance of winning, assuming the other player plays optimally as well. More formally, if the player who has to move has a winning strategy, they have to make a move after which they will still have a winning strategy. If they do not, they can make any move.
Input
The only line will contain an integer n (2 β€ n β€ 10^6) β the number of cells on the board.
Output
Output a single integer β the number of possible distinct games where both players play optimally modulo 10^9+7.
Examples
Input
2
Output
4
Input
69420
Output
629909355
Input
42069
Output
675837193
Note
For the first sample case, the first player has 4 possible moves. No matter what the first player plays, the second player only has 1 possible move, so there are 4 possible games.
Submitted Solution:
```
import __pypy__
int_add = __pypy__.intop.int_add
int_sub = __pypy__.intop.int_sub
int_mul = __pypy__.intop.int_mul
mod=10**9+7
def make_mod_mul():
fmod_inv = 1.0 / mod
def mod_mul(a, b, c=0):
res = int_sub(int_add(int_mul(a, b), c), int_mul(mod, int(fmod_inv * a * b + fmod_inv * c)))
if res >= mod:
return res - mod
elif res < 0:
return res + mod
else:
return res
return mod_mul
mod_mul = make_mod_mul()
def mod_pow(x, y):
if y == 0:
return 1
res = 1
while y > 1:
if y & 1 == 1:
res = mod_mul(res, x)
x = mod_mul(x, x)
y >>= 1
return mod_mul(res, x)
max_n=10**6
fact, inv_fact = [0] * (max_n+1), [0] * (max_n+1)
fact[0] = 1
def make_nCr_mod():
global fact
global inv_fact
for i in range(max_n):
fact[i + 1] = mod_mul(fact[i],(i + 1))
inv_fact[-1] = mod_pow(fact[-1], mod - 2)
for i in reversed(range(max_n)):
inv_fact[i] = mod_mul(inv_fact[i + 1],(i + 1))
make_nCr_mod()
def nCr_mod(n, r):
global fact
global inv_fact
res = 1
while n or r:
a, b = n % mod, r % mod
if(a < b):
return 0
res = mod_mul(mod_mul(mod_mul(res,fact[a]),inv_fact[b]),inv_fact[a-b])
n //= mod
r //= mod
return res
import sys
input=sys.stdin.readline
n=int(input())
if(n%2==0):
ans=mod_mul(2,fact[n])
else:
ans=0
for r in range(2-(n%2),(n//2+1),2): #n-r must be divible by 2
ans=(ans+mod_mul(mod_mul(mod_mul(nCr_mod(n-r-1,r-1),n),mod_pow(r,mod-2)),2*fact[n-r]))
#n circular objects select r such that no two adjacent = n/r * (n-r-1)C(r-1)
```
No
| 106,411 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Tags: math
Correct Solution:
```
MOD = 1000000007
def bib(x, y):
ans = 1
x = x % MOD
while y > 0:
if (y & 1 != 0): ans = (ans * x) % MOD
y = y >> 1
x = (x * x) % MOD
return ans % MOD
n = int(input())
ans = bib(2, 2 * n - 1) + bib(2, n - 1)
if (n == 0): print(1)
else: print(ans % MOD)
```
| 106,412 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Tags: math
Correct Solution:
```
n = int(input())
u1 = pow(2, n-1, 1000000007)
u2 = pow(2, 2*n-1, 1000000007)
u3 = (u1 + u2)%1000000007
print(int(u3%1000000007))
```
| 106,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Tags: math
Correct Solution:
```
sa=int(input())
mod=10**9+7
if sa==0:
print(1)
else:
print((pow(2, 2*sa-1, mod)+pow(2, sa-1, mod))%mod)
```
| 106,414 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Tags: math
Correct Solution:
```
n,m=int(input()),1000000007
n=pow(2,n,m)
print((((n%m)*((n+1)%m))//2)%m)
```
| 106,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Tags: math
Correct Solution:
```
def cal_pow(a, b):
if b == 0: return 1
res = cal_pow(a, b // 2)
res = res * res % 1000000007
if b % 2 == 1:
res = (res * a) % 1000000007
return res
n = int(input())
res = cal_pow(2, n)
print(((res * (res + 1) // 2)) % 1000000007)
```
| 106,416 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Tags: math
Correct Solution:
```
n = pow(2, int(input()), int(1e9 + 7))
print(((n + 1) // 2 * n + (n // 2, 0)[n % 2]) % int(1e9 + 7))
```
| 106,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Tags: math
Correct Solution:
```
import math
MOD = 1000000007
def mod_inverse(b,m):
g = math.gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def div_mod(a,b,m):
a = a % m
inv = mod_inverse(b,m)
if(inv == -1):
return None
else:
return (inv*a) % m
def sum_mod(a, b):
return (a + b) % MOD
def fast_power(base, power):
result = 1
while power > 0:
if power % 2 == 1:
result = (result * base) % MOD
power = power // 2
base = (base * base) % MOD
return result
years = int(input())
fst = fast_power(4, years)
snd = fast_power(2, years)
sum_num = sum_mod(fst, snd)
out = div_mod(sum_num, 2, MOD)
print(out)
```
| 106,418 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Tags: math
Correct Solution:
```
def fstexp(x,y):
if (y<=1):
return x**y%1000000007
if (y%2==1):
return ((((fstexp(x,y//2)%1000000007)**2)%1000000007)*(x%1000000007))%1000000007
return (((fstexp(x,y//2)%1000000007)**2)%1000000007)
x=int(input())
x=fstexp(2,x)
x=x%1000000007
print(int((((x**2)+x)//2)%1000000007))
```
| 106,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Submitted Solution:
```
n = int(input())
res = pow(2, n, 1000000007)
print((res+1)*res//2 % 1000000007)
```
Yes
| 106,420 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Submitted Solution:
```
n=int(input())
mod=1000000007
if n==0: print(1)
else: print ((pow(2,n-1,mod))*(pow(2,n,mod)+1)%mod)
```
Yes
| 106,421 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Submitted Solution:
```
n = int(input())
if n == 0:
print(1)
else:
print(((2 * pow(4, n - 1, 1000000007)) + pow(2, n - 1, 1000000007)) % 1000000007)
```
Yes
| 106,422 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Submitted Solution:
```
n = int(input())
x = pow(2, n-1, 1000000007)
y = (pow(2, n, 1000000007) + 1) % 1000000007
a = (x * y) % 1000000007
print(a)
```
Yes
| 106,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Submitted Solution:
```
mod = 1000000007
n = int(input())
h = pow(2, n, mod)
print(((h) * (h + 1) % mod)//2)
```
No
| 106,424 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Submitted Solution:
```
n=int(input())
print(n*(2*n+1))
```
No
| 106,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Submitted Solution:
```
MOD = 1000000007
def divide_mod(a, b):
return int((a / b) % MOD)
def fast_power(base, power):
"""
Returns the result of a^b i.e. a**b
We assume that a >= 1 and b >= 0
Remember two things!
- Divide power by 2 and multiply base to itself (if the power is even)
- Decrement power by 1 to make it even and then follow the first step
"""
result = 1
while power > 0:
# If power is odd
if power % 2 == 1:
result = (result * base) % MOD
# Divide the power by 2
power = power // 2
# Multiply base to itself
base = (base * base) % MOD
return result
years = int(input())
fst = fast_power(4, years)
snd = fast_power(2, years)
out = divide_mod((fst + snd), 2)
# for _ in range(years):
# up_partial = up
# down_partial = down
# up = up_partial * 3 - up_partial
# down = down_partial * 3 - down_partial
# down += up_partial
# up += down_partial
# print(up, down)
print(out)
```
No
| 106,426 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
<image>
Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.
Input
The first line contains a single integer n (0 β€ n β€ 1018) β the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print a single integer β the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).
Examples
Input
1
Output
3
Input
2
Output
10
Note
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
Submitted Solution:
```
def pow(x,y):
if y == 0:
return 1
elif y % 2 == 0:
return ((pow(x, y // 2) ** 2)) % (10 ** 9 + 7)
else:
return (pow(x, y - 1) * x) % (10 ** 9 + 7)
n = int(input())
print(((pow(2,n)+pow(4,n)) // 2) % (10 ** 9 + 7))
```
No
| 106,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Tags: constructive algorithms, greedy
Correct Solution:
```
n, d, l = map(int, input().split())
x, y = (n + 1) // 2 - l * (n // 2), l * ((n + 1) // 2) - n // 2
if x > d or y < d: print(-1)
elif l == 1: print('1 ' * n)
else:
a, b = str(l) + ' ', '1 '
u, v = (d - x) // (l - 1), (d - x) % (l - 1)
p = (a + b) * (u // 2)
if u % 2:
p += a
if v > 0: p += str(l - v) + ' '
elif v > 0: p += str(1 + v) + ' '
k = u + int(v > 0)
if k < n: p += a * (k % 2) + (b + a) * ((n - k - k % 2) // 2) + b * ((n - k - k % 2) % 2)
print(p)
```
| 106,428 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Tags: constructive algorithms, greedy
Correct Solution:
```
n,d,l=list(map(int,input().split()))
a=[0]*n
for i in range(n):
if i==n-1:
a[i]=d
else:
if d>=l:
a[i]=l
d=l-d
elif d<1:
a[i]=1
d=-d+1
else:
a[i]=d+1
d=1
if a[-1]>l or a[-1]<1:
print(-1)
else:
for i in range(n):
print(a[i],end=' ')
```
| 106,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Tags: constructive algorithms, greedy
Correct Solution:
```
nn=input()
a=[int(i) for i in nn.split()]
d=a[1]
l=a[2]
n=a[0]
oddn=int(n/2)+n%2
evenn=int(n/2)
a=[]
if d>(oddn*l-evenn) or d<(oddn-evenn*l):
print(-1)
else:
if n%2:
d-=1
for i in range(n):
a.append(int(1))
for i in range(n):
if i%2==0:
if d>0:
if d<l:
a[i]+=d
d-=d
else:
a[i]+=(l-1)
d-=(l-1)
else:
if d<0:
if d>(-l):
a[i]+=(-d)
d+=-d
else :
a[i]+=(l-1)
d+=(l-1)
for i in range(n):
print(a[i],end=" ")
```
| 106,430 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Tags: constructive algorithms, greedy
Correct Solution:
```
n,d,l=map(int,input().split())
ans=[]
for i in range(n-1):
if d<1:
ans.append(1)
d=1-d
else:
ans.append(l)
d=l-d
if 1<=d<=l:
print(*(ans+[d]))
else:
print(-1)
```
| 106,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Tags: constructive algorithms, greedy
Correct Solution:
```
n,d,l=map(int,input().split())
if d < (n-n//2) -(n//2)*l or d > (n-n//2)*l -(n//2):
print(-1)
else:
arr=[1]*n
sum1=l*(n-n//2)
sum2=n//2
for i in range(0,n,2):
arr[i]=l
i=0
j=1
while 1 :
if i<n:
if arr[i]==1:
i+=2
if j<n:
if arr[j]==l:
j+=2
if sum1-sum2==d:
break
elif i<n:
if sum1-sum2>d:
sum1-=1
arr[i]-=1
elif j<n:
if sum1-sum2>d:
sum2+=1
arr[j]+=1
print(*arr)
```
| 106,432 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Tags: constructive algorithms, greedy
Correct Solution:
```
n, d, l = map(int, input().split())
m1 = (n // 2) * (1 - l)
m2 = (n // 2) * (l - 1)
if n % 2 != 0:
m1 += 1
m2 += l
if not (m1 <= d <= m2):
print(-1)
exit()
x = d - m1
res = [1 if i % 2 == 0 else l for i in range(n)]
i = 0
while x > 0:
if i % 2 == 0:
res[i] += min(l-1, x)
else:
res[i] -= min(l-1, x)
if i + 2 < n:
i += 2
else:
i = 1
x -= min(l-1, x)
print(*res)
```
| 106,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Tags: constructive algorithms, greedy
Correct Solution:
```
r=[]
n,d,l=map(int,input().split())
for i in range(1,n):
k=1 if d<=0 else l
r.append(k)
d=k-d
if 1<=d<=l:print(*r+[d])
else:print(-1)
```
| 106,434 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Tags: constructive algorithms, greedy
Correct Solution:
```
from sys import stdin,stdout
nmbr=lambda:int(stdin.readline())
lst = lambda: list(map(int, input().split()))
for _ in range(1):#nmbr():
n,d,mx=lst()
ans=[1]*n
sm=0
for i in range(n):
if i&1:sm-=ans[i]
else:sm+=ans[i]
p=0
while p<n and sm!=d:
if p&1 and sm>d and ans[p]<mx:
ans[p]+=1
sm-=1
elif p&1==0 and sm<d and ans[p]<mx:
ans[p]+=1
sm+=1
else:p+=1
# print(ans)
if sm==d:print(*ans)
else:print(-1)
```
| 106,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Submitted Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import math
import os
import sys
from sys import stdin,stdout
from io import BytesIO, IOBase
from itertools import accumulate
from collections import deque
#sys.setrecursionlimit(10**5)
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
#sys.setrecursionlimit(10**6)
# 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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-----------------------------------------------------------------
def regularbracket(t):
p=0
for i in t:
if i=="(":
p+=1
else:
p-=1
if p<0:
return False
else:
if p>0:
return False
else:
return True
#-------------------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <= key):
count = mid+1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
#------------------------------reverse string(pallindrome)
def reverse1(string):
pp=""
for i in string[::-1]:
pp+=i
if pp==string:
return True
return False
#--------------------------------reverse list(paindrome)
def reverse2(list1):
l=[]
for i in list1[::-1]:
l.append(i)
if l==list1:
return True
return False
def mex(list1):
#list1 = sorted(list1)
p = max(list1)+1
for i in range(len(list1)):
if list1[i]!=i:
p = i
break
return p
def sumofdigits(n):
n = str(n)
s1=0
for i in n:
s1+=int(i)
return s1
def perfect_square(n):
s = math.sqrt(n)
if s==int(s):
return True
return False
#print(perfect_square(16))
#endregion-------------------------------------------
def soretd(s):
for i in range(1,len(s)):
if s[i-1]>s[i]:
return False
return True
#print(soretd("1"))
def luckynumwithequalnumberoffourandseven(x,n,a):
if x >= n and str(x).count("4") == str(x).count("7"):
a.append(x)
else:
if x < 1e12:
luckynumwithequalnumberoffourandseven(x * 10 + 4,n,a)
luckynumwithequalnumberoffourandseven(x * 10 + 7,n,a)
return a
#endregio------------------------------
"""
def main():
t = int(input())
for _ in range(t):
n,m = map(int,input().split())
l=[]
ans=[]
p=[]
for i in range(m):
arr = list(map(int,input().split()))
arr.pop(0)
p.append(arr)
for j in arr:
l.append(j)
f = (m+1)//2
#print(p)
l = sorted(l)
sett = set(l)
sett = list(sett)
#print(sett)
for i in sett:
if l.count(i)<=f:
ans+=[i]*l.count(i)
else:
ans+=[i]*(f)
print(ans)
if len(ans)>=n:
print("YES")
for i in range(m):
for j in range(len(p[i])):
if p[i][j] in ans:
print(p[i][j],end=" ")
ans.remove(p[i][j])
break
print()
else:
print("NO")
if __name__ == '__main__':
main()
"""
"""
def main():
for _ in range(int(input())):
n=int(input())
arr = list(map(int,input().split()))
d = max(arr)
ans=0
if arr==sorted(arr):
print(0)
continue
# ind1 = arr.index(d)
for i in range(n-1):
if arr[i]>arr[i+1]:
ans+=(arr[i]-arr[i+1])
print(ans)
if __name__ == '__main__':
main()
"""
def main():
n,d,l = map(int,input().split())
ans=[]
c=0
for i in range(n-1):
if d>0:
c=l
else:
c=1
ans.append(c)
d = c-d
ans.append(d)
# print(ans)
for i in ans:
if i<1 or i>l:
print(-1)
break
else:
print(*ans)
if __name__ == '__main__':
main()
```
Yes
| 106,436 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Submitted Solution:
```
def modify(a, target, limit):
pos = sum([a[i] for i in range(len(a)) if i % 2 == 0])
neg = sum([a[i] for i in range(len(a)) if i % 2 == 1])
total = pos-neg
if total == target:
return a
if total < target:
diff = target-total
for i in range(len(a)):
if i % 2 == 0:
if limit-a[i] >= diff:
a[i] += diff
return a
else:
diff -= limit-a[i]
a[i] = limit
if diff > 0:
return None
else:
diff = total - target
for i in range(len(a)):
if i % 2 == 1:
if limit-a[i] >= diff:
a[i] += diff
return a
else:
diff -= limit-a[i]
a[i] = limit
if diff > 0:
return None
n, d, l = [int(i) for i in input().split()]
numbers = [1 for i in range(n)]
mod = modify(numbers, d, l)
if mod is None:
print(-1)
else:
print(" ".join([str(i) for i in mod]))
```
Yes
| 106,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Submitted Solution:
```
# x1-x2+x3...+/-xn = d and 1<=xi<=l for all i
# n d l
# 3 3 2 => x1-x2+x3=2 1<=xi<=3 1-1+2
# n is even x1-x2+...x(m-1)-xm=d
n,d,l=map(int,input().split())
m=(n//2)*(1-l)
M=(n//2)*(l-1)
if n%2!=0:
m+=1
M+=l
if not (m<=d<=M):
print(-1)
else:
e = d-m
l2=[1 if i%2==0 else l for i in range(n)]
ci=0
while e>0:
if ci%2==0:
l2[ci]+=min(l-1,e)
else:
l2[ci]-=min(l-1,e)
if ci+2<n:
ci+=2
else:
ci=1
e-=min(l-1,e)
for e in l2:
print(e,end=' ')
```
Yes
| 106,438 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Submitted Solution:
```
def magic(n, d, l):
ans = [d]
flag = 0
for i in range(n - 1):
temp = ans[i]
if temp < 1:
ans[i] = 1
ans.append(1 - temp)
else:
ans[i] = l
ans.append(l - temp)
if not 1 <= ans[n - 1] <= l:
flag = 1
if flag == 0:
return ans
else:
return -1
if __name__=="__main__":
n, d, l = map(int, input().split())
magic = magic(n, d, l)
if magic != -1:
for i in range(n):
print(magic[i], end=" ")
else:
print(-1)
```
Yes
| 106,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Submitted Solution:
```
### CLaim :
### With a starting L,n there is an upper and Lower boundary for the number u can get on the finaL card
### And u can get any number within this range
##
### To get the maximum or the minimum number :
### If the sequence incLudes onLy (1,L,1,L,1,L,...) depending on the number (n) even or odd and the starting number (either 1 or L)
### U wiLL get the maximum or the minimum
##
### If the input (d)<=0 use Gettable_minimum
### else use Gettable_maximum
##
##
def Gettable(x,L,n,c,Taken):
if(n==2):
if(x<=L-1 and x>=1-L):
if(x>=1):
return Taken+[L,L-x]
else:
return Taken+[1,1-x]
else:
return False
if(c=='1'):
x=1-x
m=Gettable(x,L,n-1,'L',Taken+[1])
if(m!=False):
return m
elif(c=='L'):
x=L-x
m=Gettable(x,L,n-1,'1',Taken+[L])
if(m!=False):
return m
else:
x=L-x
m=Gettable(x,L,n-1,'1',Taken+[L])
if(m!=False):
return m
x=1-x
m=Gettable(x,L,n-1,'L',Taken+[1])
if(m!=False):
return m
return False
n,d,l=map(int,input().split())
##
##if(d<=0):
## if( not Gettable_minimum(d,l,n) ):
## print(-1)
## else:
## Ans=[1]
## d=d
## while(len(Ans)<n):
## Ans.append(1-d)
if(n==2):
if(d in range(1-l,1)):
print(1,1-d)
elif(d in range(1,l)):
print(l,l-d)
else:
print(-1)
else:
Ans=Gettable(l-d,l,n-1,'1',[l])
if(Ans!=False):
for i in range(n-1):
print(Ans[i],end=" ")
print(Ans[-1])
else:
Ans=Gettable(1-d,l,n-1,'L',[1])
if(Ans!=False):
for i in range(n-1):
print(Ans[i],end=" ")
print(Ans[-1])
else:
print(-1)
```
No
| 106,440 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Submitted Solution:
```
n,d,l=map(int,input().split())
ans=[]
temp=0
for i in range(n-1):
if d>1:
ans.append(l)
temp=l
else:
ans.append(1)
temp=1
#print(d,temp-d)
d=temp-d
if d>=1 and d<=l:
ans.append(d)
print(*ans)
else:
print(-1)
```
No
| 106,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Submitted Solution:
```
nn=input()
a=[int(i) for i in nn.split()]
d=a[1]
l=a[2]
n=a[0]
oddn=int(n/2)+1
evenn=int(n/2)
a=[]
if d>(oddn*l-evenn) or d<(oddn-evenn*l):
print(-1)
else:
if n%2:
d-=1
for i in range(n):
a.append(int(1))
for i in range(n):
if i%2==0:
if d>0:
if d<l:
a[i]+=d
d-=d
else:
a[i]+=(l-1)
d-=(l-1)
else:
if d<0:
if d>(-l):
a[i]+=(-d)
d+=-d
else :
a[i]+=(l-1)
d+=(l-1)
for i in range(n):
print(a[i],end=" ")
```
No
| 106,442 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.
Help Vasya to recover the initial set of cards with numbers.
Input
The single line contains three space-separated integers: n (2 β€ n β€ 100) β the initial number of cards on the table, d (|d| β€ 104) β the number on the card that was left on the table after all the magical actions, and l (1 β€ l β€ 100) β the limits for the initial integers.
Output
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
Examples
Input
3 3 2
Output
2 1 2
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
2 4 1 4 1
Submitted Solution:
```
### CLaim :
### With a starting L,n there is an upper and Lower boundary for the number u can get on the finaL card
### And u can get any number within this range
##
### To get the maximum or the minimum number :
### If the sequence incLudes onLy (1,L,1,L,1,L,...) depending on the number (n) even or odd and the starting number (either 1 or L)
### U wiLL get the maximum or the minimum
##
### If the input (d)<=0 use Gettable_minimum
### else use Gettable_maximum
##
##
def Gettable_maximum(d,L,n):
x=L-1
numbers_used=2
c=0
while(numbers_used<n):
if(c%2==0):
x=1-x
else:
x=L-x
c+=1
if(x>=d):
return True
numbers_used+=1
numbers_used=2
x=1-L
c=1
while(numbers_used<n):
if(c%2==0):
x=1-x
else:
x=L-x
c+=1
if(x>=d):
return True
numbers_used+=1
return False
def Gettable_minimum(d,L,n):
x=L-1
numbers_used=2
c=0
while(numbers_used<n):
if(c%2==0):
x=1-x
else:
x=L-x
c+=1
if(x<=d):
return True
numbers_used+=1
numbers_used=2
x=1-L
c=1
while(numbers_used<n):
if(c%2==0):
x=1-x
else:
x=L-x
c+=1
if(x<=d):
return True
numbers_used+=1
return False
##
n,d,l=map(int,input().split())
##
##if(d<=0):
## if( not Gettable_minimum(d,l,n) ):
## print(-1)
## else:
## Ans=[1]
## d=d
## while(len(Ans)<n):
## Ans.append(1-d)
Ans=[]
done=False
if(d>l and not Gettable_maximum(d,l,n)):
print(-1)
elif(d<=0 and not Gettable_minimum(d,l,n)):
print(-1)
else:
while(len(Ans)<n):
if(d<=0):
Ans.append(1)
d=1-d
elif(d>l):
Ans.append(l)
d=l-d
elif(len(Ans)!=n-2):
Ans.append(l)
d=l-d
else:
Ans.append(l)
Ans.append(l-d)
for i in range(n-1):
print(Ans[i],end=" ")
print(Ans[-1])
```
No
| 106,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Tags: greedy, implementation, sortings
Correct Solution:
```
import sys
import math
n, m, k = [int(x) for x in (sys.stdin.readline()).split()]
an = [int(x) for x in (sys.stdin.readline()).split()]
an.sort(reverse = True)
res = 0
i = 0
while(m > k):
if(i < n):
k -= 1
k += an[i]
i += 1
else:
break
res += 1
if(m <= k):
print(res)
else:
print(-1)
```
| 106,444 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Tags: greedy, implementation, sortings
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)
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")
#-------------------------------------------------------------------------
#mod = 9223372036854775807
class SegmentTree:
def __init__(self, data, default=-10**6, func=lambda a, b: max(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
class SegmentTree1:
def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
MOD=10**9+7
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod=10**9+7
omod=998244353
#-------------------------------------------------------------------------
prime = [True for i in range(50001)]
pp=[]
def SieveOfEratosthenes(n=50000):
# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
p = 2
while (p * p <= n):
# If prime[p] is not changed, then it is a prime
if (prime[p] == True):
# Update all multiples of p
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
for i in range(50001):
if prime[i]:
pp.append(i)
#---------------------------------running code------------------------------------------
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
if k>=m:
print(0)
else:
curr=k
count=0
for i in range (n):
curr+=a[i]-1
count+=1
if curr>=m:
break
if curr>=m:
print(count)
else:
print(-1)
```
| 106,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Tags: greedy, implementation, sortings
Correct Solution:
```
n,m,k=map(int,input().split())
l = list(map(int,input().split()))
l.sort(reverse=True)
# l.reverse()
# print(l)
if m<=k:
print(0)
quit()
for ii,c in enumerate(l):
k+=c-1
# print(k)
if k>=m:
print('{}'.format(ii+1))
quit()
print(-1)
```
| 106,446 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Tags: greedy, implementation, sortings
Correct Solution:
```
def sockets():
n, m, k = map(int, input().split())
a = map(int, input().split())
a = sorted(a, reverse=True)
if m <= k:
print(0)
return
i = 0
for x in a:
k += x - 1
i += 1
if m <= k:
print(i)
return
print(-1)
sockets()
```
| 106,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Tags: greedy, implementation, sortings
Correct Solution:
```
n, m, k = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
a.sort(reverse=True)
if m <= k:
print(0)
else:
ans = 0
x = m
while (True):
maxm = a.pop(0)
m = m - maxm
k = k - 1
ans += 1
if k >= m:
print(ans)
break
elif ans == n:
print(-1)
break
```
| 106,448 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Tags: greedy, implementation, sortings
Correct Solution:
```
n,m,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
if(m<k):
print("0")
else:
c=k
i=0
j=0
flag=0
while(c<m):
if(i==n):
flag=1
break
c=c-1
c=c+l[i]
i=i+1
j=j+1
if(flag==1):
print("-1")
else:
print(j)
```
| 106,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Tags: greedy, implementation, sortings
Correct Solution:
```
n,m,k=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
arr=arr+[k]
ans=0
s=0
while ans<n+1:
s+=arr[-ans-1]
if s>=m:
break
ans+=1
s-=1
if s>=m:
print(ans)
else:
print("-1")
```
| 106,450 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Tags: greedy, implementation, sortings
Correct Solution:
```
import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
if __name__ == '__main__':
n, m, k = list(map(int, input().strip().split()))
a, b, i = list(map(int, input().strip().split())), 0, 0
a.sort(reverse=True)
if m <= k:
print(b)
else:
while i < len(a):
if m <= k:
break
if k > 0:
k -= 1
elif m > 0:
m += 1
m -= a[i]
b += 1
i += 1
print("-1" if m > k else "{}".format(b))
```
| 106,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
for i in range(n + 1):
if i < n and k < m:
k += a[i] - 1
else:
break;
if k >= m:
print(i)
else:
print(-1)
```
Yes
| 106,452 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = map(int, input().split())
arr = [int(i) for i in input().split()]
i, res = 0, 0
arr = sorted(arr, reverse=True)
while i < n and k < m:
k += arr[i] - 1
res += 1
i += 1
print(-1 if k < m else res)
```
Yes
| 106,453 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n,m,k = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x=x[::-1]
if m<=k:
print(0)
else:
d=0
f=1
for i in x:
k+=i-1
d+=1
if m<=k:
print(d)
f=0
break
if f :
print(-1)
```
Yes
| 106,454 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = map(int, input().split());
a = list(map(int, input().split()));
a.sort(reverse = True);
if sum(a)+k-n < m:
print(-1);
elif k >= m:
print(0);
else:
for i in range (1, n+1):
if sum(a[:i])+k-i >= m:
print(i)
break;
```
Yes
| 106,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n,m,k = map(int ,input().split())
t = list(map(int,input().split()))
t.sort()
g=[1]*(k)
k-=1
f=0
l,h=0,0
j=n-1
while True:
if k>=0 and j>=0:
g[k]+=t[j]-1
j-=1
k-=1
l+=1
if sum(g)>=m:
print(l)
h+=1
break
if k<0 and j>=0:
k=len(g)-1
if k<0 and j<0:
if sum(g)<m:
break
else:
print(l)
break
if h==0:
print(-1)
```
No
| 106,456 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
# cook your dish here
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)
#print(a)
c=0
devices = k
i=0
while(devices<m and i<n):
c+=1
devices+=a[i]
if(devices<n):
print(-1)
else:
print(c)
```
No
| 106,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
for i in range(n):
if k < m:
k += a.pop(0)
else:
break;
if k >= m:
print(i)
else:
print(-1)
```
No
| 106,458 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
c = 0
while k < m and c < n:
k += a[c] - 1
c += 1
if c > 0 and k >= m:
print(c)
else:
print(-1)
```
No
| 106,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Tags: geometry
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
def main():
pass
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")
def binary(n):
return (bin(n).replace("0b", ""))
def decimal(s):
return (int(s, 2))
def pow2(n):
p = 0
while (n > 1):
n //= 2
p += 1
return (p)
def primeFactors(n):
l=[]
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
l.append(i)
n = n / i
if n > 2:
l.append(int(n))
return (l)
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
def maxPrimeFactors(n):
maxPrime = -1
while n % 2 == 0:
maxPrime = 2
n >>= 1
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime)
w,h,a=map(int,input().split())
if(a==0 or a==180):
print(w*h)
else:
w,h=max(w,h),min(w,h)
if(a>90):
a=180-a
a=(a*math.pi)/180
#print(h*(1+math.cos(a)),w*math.sin(a))
if(h*(1+math.cos(a))< w*math.sin(a)):
print(pow(h,2)/math.sin(a))
else:
#print("HEY")
#print(math.sin(a))
x=h-w*((math.cos(a)+1)/math.sin(a))
t=math.tan(a)-((math.cos(a)+1)*(math.cos(a)+1)/(math.cos(a)*math.sin(a)))
x=x/t
x=abs(x)
b2=w-x-(x/math.cos(a))
b2=abs(b2)
h2=b2/math.tan(a)
h2=abs(h2)
h1=h-h2-(h2/math.cos(a))
h1=abs(h1)
tbm=((x*h1)+(b2*h2))
#print(x,h1,h2,b2)
print((h*w)-tbm)
```
| 106,460 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Tags: geometry
Correct Solution:
```
#!/usr/bin/python3
from math import sin, cos, pi, atan2
w, h, a = tuple(map(int, input().split()))
if a in [0, 180]:
print(w * h)
elif a == 90:
print(min(w, h)**2)
else:
a *= pi / 180
w /= 2
h /= 2
base = [(w, h), (-w, h), (-w, -h), (w, -h)]
rot = [(x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)) for x, y in base]
pol = []
for i, j in zip(range(-1, 3), range(4)):
t = (w - rot[i][0]) / (rot[j][0] - rot[i][0])
if 0 <= t <= 1:
pol.append((w, rot[i][1] + (rot[j][1] - rot[i][1]) * t))
t = (-w - rot[i][0]) / (rot[j][0] - rot[i][0])
if 0 <= t <= 1:
pol.append((-w, rot[i][1] + (rot[j][1] - rot[i][1]) * t))
t = (h - rot[i][1]) / (rot[j][1] - rot[i][1])
if 0 <= t <= 1:
pol.append((rot[i][0] + (rot[j][0] - rot[i][0]) * t, h))
t = (-h - rot[i][1]) / (rot[j][1] - rot[i][1])
if 0 <= t <= 1:
pol.append((rot[i][0] + (rot[j][0] - rot[i][0]) * t, -h))
pol.sort(key=lambda x: atan2(*x))
print('%0.9f' % (sum([abs(pol[i][0] * pol[j][1] - pol[i][1] * pol[j][0]) for i, j in zip(range(-1, len(pol) - 1), range(len(pol)))]) / 2))
```
| 106,461 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Tags: geometry
Correct Solution:
```
import sys
import math
def read_input(input_path=None):
if input_path is None:
f = sys.stdin
else:
f = open(input_path, 'r')
w, h, a = map(int, f.readline().split())
return w, h, a
def sol(w, h, a):
if h > w:
w, h = h, w
if a > 90:
a = 90 - (a - 90)
a = math.radians(a)
if a < 2 * math.atan2(h, w):
area = w * h
s = (w / 2) - (h / 2 * math.tan(a / 2))
bigger_area = 0.5 * s * s * math.tan(a)
s = (h / 2) - (w / 2 * math.tan(a / 2))
lower_area = 0.5 * s * s * math.tan(a)
res = area - 2 * bigger_area - 2 * lower_area
else:
res = h * h / math.sin(a)
return [f"{res}"]
def solve(input_path=None):
return sol(*read_input(input_path))
def main():
for line in sol(*read_input()):
print(f"{line}")
if __name__ == '__main__':
main()
```
| 106,462 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Tags: geometry
Correct Solution:
```
import math
from decimal import *
getcontext().prec = 40
EPS = Decimal(0.000000000000000000001)
PI = Decimal(3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328)
def labs(x):
if x < 0:
return -x
return x
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def Add(self, p):
self.x += p.x
self.y += p.y
def Sub(self, p):
self.x -= p.x
self.y -= p.y
def Scale(self, v):
self.x *= v
self.y *= v
def Rotate(self, angle):
newX = self.x * Decimal(math.cos(angle)) - self.y * Decimal(math.sin(angle))
newY = self.x * Decimal(math.sin(angle)) + self.y * Decimal(math.cos(angle))
self.x = newX
self.y = newY
def Equals(self, p):
if Decimal(labs(p.x - self.x)) < EPS and Decimal(labs(p.y - self.y)) < EPS:
return True
return False
class Line:
def __init__(self, start, end):
self.start = start
self.end = end
def GetIntersection(self, l):
a = Point(self.start.x, self.start.y)
b = Point(self.end.x, self.end.y)
c = Point(l.start.x, l.start.y)
d = Point(l.end.x, l.end.y)
ab = Point(self.end.x, self.end.y)
cd = Point(l.end.x, l.end.y)
ab.Sub(a)
cd.Sub(c)
k = Decimal((cd.x * (a.y - c.y) + cd.y * (c.x - a.x)) / (ab.x * cd.y - ab.y * cd.x))
ab.Scale(k)
a.Add(ab)
return a
class Polygon:
def __init__(self, vertices):
self.vertices = vertices
def GetArea(self):
area = Decimal(0)
for i in range(0, len(self.vertices)):
area += self.vertices[i].x * self.vertices[(i + 1) % len(self.vertices)].y - self.vertices[(i + 1) % len(self.vertices)].x * self.vertices[i].y
return Decimal(labs(area)) / Decimal(2)
x, y, alpha = input().split()
x = Decimal(x)
y = Decimal(y)
if x < y:
tmp = x
x = y
y = tmp
alpha = Decimal(alpha)
singleArea = x * y
if alpha > 90:
alpha = Decimal(180) - alpha
if alpha == 0:
print(singleArea)
exit()
alpha = alpha * PI / Decimal(180)
a = Point(x / Decimal(2), y / Decimal(2))
b = Point(x / Decimal(2), -y / Decimal(2))
c = Point(-x / Decimal(2), -y / Decimal(2))
d = Point(-x / Decimal(2), y / Decimal(2))
e = Point(a.x, a.y)
f = Point(b.x, b.y)
g = Point(c.x, c.y)
h = Point(d.x, d.y)
e.Rotate(alpha)
f.Rotate(alpha)
g.Rotate(alpha)
h.Rotate(alpha)
ab = Line(a, b)
bc = Line(b, c)
cd = Line(c, d)
da = Line(d, a)
ef = Line(e, f)
fg = Line(f, g)
gh = Line(g, h)
he = Line(h, e)
area = 0
if a.Equals(f):
t1 = Polygon([he.GetIntersection(da), e, f])
t2 = Polygon([fg.GetIntersection(bc), g, h])
area = singleArea - t1.GetArea() - t2.GetArea()
elif f.y > a.y:
p1 = Polygon([he.GetIntersection(da), e, f, fg.GetIntersection(da)])
p2 = Polygon([fg.GetIntersection(bc), g, h, he.GetIntersection(bc)])
area = singleArea - p1.GetArea() - p2.GetArea()
else:
t1 = Polygon([da.GetIntersection(he), e, ef.GetIntersection(da)])
t2 = Polygon([ef.GetIntersection(ab), f, fg.GetIntersection(ab)])
t3 = Polygon([fg.GetIntersection(bc), g, gh.GetIntersection(bc)])
t4 = Polygon([gh.GetIntersection(cd), h, he.GetIntersection(cd)])
area = singleArea - t1.GetArea() - t2.GetArea() - t3.GetArea() - t4.GetArea()
print(area)
```
| 106,463 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Tags: geometry
Correct Solution:
```
from math import sin,cos,tan
PI = 3.141592653589793238463
[w,h,a] =[int(i) for i in input().split()]
if h > w:
h,w = w,h
if a > 90:
a = 180 - a
if a==0:
print(w*h)
else:
b = (a*PI)/180
w = w/2.0
h = h/2.0
if tan(b/2) >= h/w:
print (4*h*h/sin(b))
else:
ans = 4*w*h
m = -1 / tan(b)
c = w*sin(b) + w*cos(b) / tan(b)
ans = ans - (h - m*w - c)*(w - (h - c)/m)
m = tan(b)
c = h*cos(b) + h*sin(b)*tan(b)
ans = ans - (h + m*w - c)*((h - c)/m + w)
print (ans)
```
| 106,464 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Tags: geometry
Correct Solution:
```
from math import *
w,h,alpha = [int(x) for x in input().strip().split()]
if alpha > 90 : alpha = 180 - alpha
if w < h: w,h = h,w
c = cos(alpha * pi / 180.0)
s = sin(alpha * pi / 180.0)
t = tan(alpha * pi / 360.0)
print(h * h / s) if t > h / w else print( (w * h - (w * w + h * h) / 2 * tan(alpha * pi / 360.0)) / (c))
```
| 106,465 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Tags: geometry
Correct Solution:
```
from math import sin, cos, tan, atan, pi
def main():
w, h, a = map(int, input().split())
a = min(a, 180 - a) * pi / 180
if h > w:
h, w = w, h
if h * (1 + cos(a)) < w * sin(a):
res = h * h / sin(a)
else:
res = h * w - ((w - h * tan(a / 2)) ** 2 * tan(a) + (h - w * tan(a / 2)) ** 2 * tan(a)) / 4
print('{:.9f}'.format(res))
if __name__ == '__main__':
main()
# Made By Mostafa_Khaled
```
| 106,466 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Tags: geometry
Correct Solution:
```
mas = list(map(int, input().split()))
w = mas[0]
h = mas[1]
alf = mas[2]
import math
sina = abs(math.sin(alf/180*math.pi))
cosa = abs(math.cos(alf/180*math.pi))
sinb = h / ((w ** 2 + h ** 2) ** 0.5)
cosb = w / ((w ** 2 + h ** 2) ** 0.5)
sin2b = 2 * sinb * cosb
#print(w,h,alf)
if (sin2b >= sina):
#print(sina, cosa)
diskr = (cosa + 1) ** 2 - sina ** 2
disc = w * (cosa + 1) - h * (sina)
disf = h * (cosa + 1) - w * (sina)
c = disc / diskr
f = disf / diskr
res = w * h - (c ** 2 + f ** 2) * sina * cosa
elif(alf == 90):
res = min(w, h) ** 2
else:
res = min((h ** 2) / sina, (w ** 2) / sina)
print(res)
```
| 106,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
from math import cos, pi, sin, atan
W, H, b = map(float, input().split())
a = (b/180)*pi
if (W < H):
X = W
W = H
H = X
if (a > 0.5*pi):
a = 0.5*pi - (a - 0.5*pi)
opp = W*H
if (a == 0):
eindopp = W*H
else:
if a > (atan(H/W)*2):
Schuin = H/sin(a)
eindopp = Schuin*H
else:
y = -2*cos(a)-cos(a)**2-1+sin(a)**2
hks = (W*sin(a)-H*cos(a)-H)/y
hgs = (H-hks-hks*cos(a))/sin(a)
eindopp = opp - hks*sin(a)*hks*cos(a) - hgs*sin(a)*hgs*cos(a)
print(round(eindopp,9))
```
Yes
| 106,468 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
from math import sin,cos,tan,pi
[w,h,a] =[int(i) for i in input().split()]
if h > w:
h,w = w,h
if a > 90:
a = 180 - a
if a==0:
print(w*h)
else:
b = (a*pi)/180
w = w/2.0
h = h/2.0
if tan(b/2) >= h/w:
print (4*h*h/sin(b))
else:
ans = 4*w*h
m = -1 / tan(b)
c = w*sin(b) + w*cos(b) / tan(b)
ans = ans - (h - m*w - c)*(w - (h - c)/m)
m = tan(b)
c = h*cos(b) + h*sin(b)*tan(b)
ans = ans - (h + m*w - c)*((h - c)/m + w)
print (ans)
```
Yes
| 106,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
from math import *
from sys import stdin, stdout
io = stdin.readline().split()
w = float(io[0])
h = float(io[1])
a = float(io[2])
if (a > 90): a = 180 - a
if (a == 0) :
print(w * h)
elif (a == 90) :
print(min(w, h) ** 2)
else :
a = a * pi / 180.0
if (w < h) : w, h = h, w
corner_x = cos(a) * (w / 2.0) + sin(a) * (h / 2.0)
if (corner_x >= w / 2 ) :
x0 = w / 2.0 + (h / 2.0 - (h / 2.0) / cos(a)) * (cos(a) / sin(a))
y0 = h / 2.0 - (tan(a) * (- w / 2.0) + (h / 2.0) / cos(a))
x1 = w / 2.0 - (h / 2.0 - (w / 2.0) / sin(a)) * (-tan(a))
y1 = h / 2.0 - ((-cos(a) / sin(a)) * (w / 2.0) + (w / 2.0) / sin(a))
print(w * h - x1 * y1 - x0 * y0)
else :
y = tan(a) * (w / 2.0) - (h / 2.0) / cos(a) + h / 2.0
y0 = y - h
x0 = y * tan(pi / 2.0 - a)
print(w * h - (y0 * tan(pi / 2.0 - a) + x0) * h)
```
Yes
| 106,470 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
import math
w, h, a = map(int, input().strip().split())
if h > w:
w, h = h, w
if a > 90:
a = 90 - (a - 90)
a = math.radians(a)
if a < 2 * math.atan2(h, w):
area = w * h
s = (w / 2) - (h / 2 * math.tan(a / 2))
bigger_area = 0.5 * s * s * math.tan(a)
s = (h / 2) - (w / 2 * math.tan(a / 2))
lower_area = 0.5 * s * s * math.tan(a)
print(area - 2 * bigger_area - 2 * lower_area)
else:
print(h * h / math.sin(a))
```
Yes
| 106,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
mas = list(map(int, input().split()))
w = mas[0]
h = mas[1]
alf = mas[2]
import math
sina = abs(math.sin(alf/180*math.pi))
cosa = abs(math.cos(alf/180*math.pi))
sinb = h / ((w ** 2 + h ** 2) ** 0.5)
cosb = w / ((w ** 2 + h ** 2) ** 0.5)
sin2b = 2 * sinb * cosb
print(w,h,alf)
if (sin2b >= sina):
print(sina, cosa)
diskr = (cosa + 1) ** 2 - sina ** 2
disc = w * (cosa + 1) - h * (sina)
disf = h * (cosa + 1) - w * (sina)
c = disc / diskr
f = disf / diskr
res = w * h - (c ** 2 + f ** 2) * sina * cosa
elif(alf == 90):
res = min(w, h) ** 2
else:
res = min((h ** 2) / sina, (w ** 2) / sina)
print(res)
```
No
| 106,472 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
from math import cos,sin,pi,tan,atan
w,h,a=map(float,input().split())
if a==90:
print(w*w)
else:
a=a*pi/180
print ((w * h - (w * w + h * h) * tan(a / 2) / 2) / cos(a) if a < atan(h / w) * 2 else h * h / sin(a))
```
No
| 106,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
import math
w, h, a = map(int, input().strip().split())
# if h > w:
# w, h = h, w
#
# if a > 90:
# a = 90 - (a - 90)
a = math.radians(a)
if a < 2 * math.atan2(h, w):
area = w * h
s = (w / 2) - (h / 2 * math.tan(a / 2))
bigger_area = 0.5 * s * s * math.tan(a)
s = (h / 2) - (w / 2 * math.tan(a / 2))
lower_area = 0.5 * s * s * math.tan(a)
print(area - 2 * bigger_area - 2 * lower_area)
else:
print(h * h / math.sin(a))
```
No
| 106,474 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle Ξ±.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, Ξ± (1 β€ w, h β€ 106; 0 β€ Ξ± β€ 180). Angle Ξ± is given in degrees.
Output
In a single line print a real number β the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
#!/usr/bin/python3
from math import *
w,h,alpha = [int(x) for x in input().strip().split()]
if alpha == 0:
print(w*h)
exit(0)
if alpha > 90 : alpha = 180-alpha
if w < h: w,h = h,w
c = 1+cos(alpha*pi/180.0)
s = sin(alpha*pi/180.0)
x = (w/s - h/c)/(c/s - s/c)
y = (w/c - h/s)/(s/c - c/s)
print(h*h/s) if tan(alpha/2) > h/w else print(w*h - x*x*(c-1)*s - y*y*(c-1)*(s))
```
No
| 106,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Tags: brute force
Correct Solution:
```
n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
a=0
for i in range(n-1):
for j in range(i+1,n):
if(l[j]-l[i]<=m):
a+=1
else:
break
print(a*2)
```
| 106,476 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Tags: brute force
Correct Solution:
```
n, d = map(int, input().split())
c = list(map(int, input().split()))
counter = 0
for i in range(len(c)):
for j in range(i+1, len(c)):
if abs(c[i] - c[j]) <= d:
counter += 2
print(counter)
```
| 106,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Tags: brute force
Correct Solution:
```
x,y=[ int(a) for a in input().split()]
l=[int(b) for b in input().split()]
count=0
k=len(l)-1
for i in range(len(l)-1):
for j in range(i+1,len(l)):
if abs(l[j]-l[i])<=y:
count=count+1
print(count*2)
```
| 106,478 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Tags: brute force
Correct Solution:
```
import sys
def solution(n, d, a_arr):
count = 0
for i in range(len(a_arr)):
for j in range(len(a_arr)):
if i == j:
continue
diff = abs(a_arr[i]-a_arr[j])
#print(diff, d, count)
if diff <= d:
count += 1
return count
if __name__ == '__main__':
n = sys.stdin.readline()
while n:
n_in, d = n.split() # array length
a_arr = [int(i) for i in sys.stdin.readline().split()] # input array
print(solution(int(n_in), int(d), a_arr))
n = sys.stdin.readline()
```
| 106,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Tags: brute force
Correct Solution:
```
(n, d) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
result = 0
for i in range(len(a) - 1):
for j in range(i+1, len(a)):
if abs(a[i] - a[j]) <= d:
result += 2
print(result)
```
| 106,480 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Tags: brute force
Correct Solution:
```
n, d = [int(s) for s in input().split(' ')]
a = [int(s) for s in input().split(' ')]
a.sort()
pairs = 0
for i in range(n - 1):
for j in range(i + 1, n):
if a[j] - a[i] <= d:
pairs += 2
else:
break
print(pairs)
```
| 106,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Tags: brute force
Correct Solution:
```
##import math
a,b = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()
c = 0
for i in range(len(lis)):
#print (i)
for ii in range(len(lis)):
if(i == ii):
continue
if abs(lis[i]-lis[ii]) <= b:
c += 1
#print (ii, end = " ")
print(c)
```
| 106,482 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Tags: brute force
Correct Solution:
```
'''
Amirhossein Alimirzaei
Telegram : @HajLorenzo
Instagram : amirhossein_alimirzaei
University of Bojnourd
'''
# Be Kasif tarin halat momken neveshtam hal kon :DDDD
N = list(map(int, input().split()))
L = sorted(list(map(int, input().split())))
C = 0
for _ in range(N[0] - 1):
I=_+1
while(True):
if (L[_] <= L[I] and abs(L[_]-L[I])<=N[1]):
C+=2
else:
break
I+=1
if(I>=N[0]):
break
print(C)
```
| 106,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Submitted Solution:
```
import os
import sys
debug = True
if debug and os.path.exists("input.in"):
input = open("input.in", "r").readline
else:
debug = False
input = sys.stdin.readline
def inp():
return (int(input()))
def inlt():
return (list(map(int, input().split())))
def insr():
s = input()
return (list(s[:len(s) - 1]))
def invr():
return (map(int, input().split()))
test_count = 1
if debug:
test_count = inp()
for t in range(test_count):
if debug:
print("Test Case #", t + 1)
# Start code here
n, d = invr()
A = inlt()
ans = 0
for i in range(n):
for j in range(n):
if i == j:
continue
if abs(A[i] - A[j]) <= d:
ans += 1
print(ans)
```
Yes
| 106,484 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Submitted Solution:
```
n, d = map(int, input().split())
a = list(map(int, input().split()))
ans = sum(1 for i in range(n) for j in range(n) if i != j and abs(a[i] - a[j]) <= d)
print(ans)
```
Yes
| 106,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Submitted Solution:
```
n, d = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(n):
if i != j and abs(l[i] - l[j]) <= d:
ans += 1
print(ans)
```
Yes
| 106,486 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Submitted Solution:
```
inp = input().split()
n = int(inp[0])
d = int(inp[1])
heights = input().split()
heights = [int(i) for i in heights]
heights.sort()
ans = 0
for i in range(0, n):
for j in range(i+1, n):
if heights[j] - heights[i] <= d:
ans += 2
else:
break
print(ans)
```
Yes
| 106,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Submitted Solution:
```
n, d = map(int, input().split())
data = list(map(int, input().split()))
count = 0
current = data[0]
for i in data[1:]:
if abs(i - current) <= 10:
count += 1
current = i
print(count * 2)
```
No
| 106,488 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Submitted Solution:
```
n , d = map(int,input().split())
h = list(map(int,input().split()))
h.sort()
cnt = 0
l = 0
r = 1
while(l<r) :
if h[r]-h[l] <=d :
cnt = cnt + 2
r = r + 1
else :
l = l + 1
r = l + 1
if l == n :
break
if r == n :
break
print(cnt)
```
No
| 106,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Submitted Solution:
```
a,b=map(int,input().split())
c=list(map(int,input().split()))
l=[]
for i in range(a):
for j in range(a):
if c[i]-c[j]<=b:
l.append(1)
print(len(l)-(a+1)*2)
```
No
| 106,490 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6
Submitted Solution:
```
count=0
n,d=map(int, input().split())
s=[]+list(map(int, input().split()))
for i in range(n):
for j in range(n):
if s[i]-s[j]<=d and i!=j:
count +=1
print(count//2)
```
No
| 106,491 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.
The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission β ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!
Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket β because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li β€ x β€ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.
Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.
In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.
Input
The first line contains the number of universities t, (1 β€ t β€ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 β€ ni, li, ri β€ 109; li β€ ri).
Output
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
Examples
Input
2
5 2 3
6 4 5
Output
Yes
No
Note
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Tags: constructive algorithms, implementation, math
Correct Solution:
```
T=int(input())
while T>0:
T-=1
n,l,r=map(int,input().split())
t = n//l
if t*r>=n:
print("Yes")
else:
print("No")
```
| 106,492 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.
The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission β ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!
Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket β because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li β€ x β€ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.
Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.
In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.
Input
The first line contains the number of universities t, (1 β€ t β€ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 β€ ni, li, ri β€ 109; li β€ ri).
Output
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
Examples
Input
2
5 2 3
6 4 5
Output
Yes
No
Note
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Tags: constructive algorithms, implementation, math
Correct Solution:
```
# https://codeforces.com/problemset/problem/397/B
import sys
sys.setrecursionlimit(1500)
inst_num = int(input())
#reading data
n = 0
l = 0
r = 0
def payment_possible(total, l, r):
max_coins = int(total/l)
if r * max_coins >= total:
return True
else:
return False
if total < coins[0]:
return False
return False
for i in range(0, inst_num):
line_data = input().split()
n = int(line_data[0])
l = int(line_data[1])
r = int(line_data[2])
if n > 0 and l == 1:
print("Yes")
continue
if n >= l and n <= r:
print("Yes")
continue
if payment_possible(n, l, r):
print("Yes")
else:
print("No")
"""
if sum > 0 and l == 1:
return True
if sum >= l and sum <= r:
return True
if sum == 0:
return True
if sum > 0 and r < l:
return False
new_sum = sum - (r * int(sum / r))
print(new_sum, r)
r -= 1
return payment_possible(new_sum, l, r)
"""
```
| 106,493 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.
The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission β ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!
Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket β because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li β€ x β€ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.
Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.
In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.
Input
The first line contains the number of universities t, (1 β€ t β€ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 β€ ni, li, ri β€ 109; li β€ ri).
Output
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
Examples
Input
2
5 2 3
6 4 5
Output
Yes
No
Note
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Tags: constructive algorithms, implementation, math
Correct Solution:
```
import sys; sys.setrecursionlimit(1000000)
def solve():
tests, = rv()
for test in range(tests):
n,l,r, = rv()
largestused = (n + r - 1) // r
totalnum = largestused * r
mostcansubtract = largestused * (r - l)
lowerbound = totalnum - mostcansubtract
if lowerbound <= n:
print("Yes")
else:
print("No")
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()
```
| 106,494 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.
The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission β ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!
Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket β because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li β€ x β€ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.
Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.
In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.
Input
The first line contains the number of universities t, (1 β€ t β€ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 β€ ni, li, ri β€ 109; li β€ ri).
Output
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
Examples
Input
2
5 2 3
6 4 5
Output
Yes
No
Note
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Tags: constructive algorithms, implementation, math
Correct Solution:
```
def possible(numbers):
return int(numbers[0])//int(numbers[1])!=0 and int(numbers[0])%int(numbers[1])//(int(numbers[0])//int(numbers[1]))<=int(numbers[2])-int(numbers[1]) and int(numbers[0])%int(numbers[1])%int(numbers[0])//int(numbers[1])+int(numbers[0])%int(numbers[1])%(int(numbers[0])//int(numbers[1]))<=(int(numbers[2])-int(numbers[1]))*(int(numbers[0])//int(numbers[1])-int(numbers[0])//int(numbers[2]))
for i in range(0,int(input())):
print('Yes' if possible(input().split(' ')) else 'No')
```
| 106,495 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.
The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission β ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!
Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket β because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li β€ x β€ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.
Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.
In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.
Input
The first line contains the number of universities t, (1 β€ t β€ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 β€ ni, li, ri β€ 109; li β€ ri).
Output
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
Examples
Input
2
5 2 3
6 4 5
Output
Yes
No
Note
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Tags: constructive algorithms, implementation, math
Correct Solution:
```
# from dust i have come, dust i will be
t=int(input())
while t>0:
t-=1
n,l,r=map(int,input().split())
k=n//l
if r*k>=n:
print('Yes')
else:
print('No')
```
| 106,496 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.
The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission β ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!
Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket β because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li β€ x β€ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.
Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.
In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.
Input
The first line contains the number of universities t, (1 β€ t β€ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 β€ ni, li, ri β€ 109; li β€ ri).
Output
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
Examples
Input
2
5 2 3
6 4 5
Output
Yes
No
Note
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Tags: constructive algorithms, implementation, math
Correct Solution:
```
class CodeforcesTask397BSolution:
def __init__(self):
self.result = ''
self.t = 0
self.queries = []
def read_input(self):
self.t = int(input())
for _ in range(self.t):
self.queries.append([int(x) for x in input().split(" ")])
def process_task(self):
res = []
for query in self.queries:
k = query[0] // query[1]
res.append("Yes" if k * query[2] >= query[0] else "No")
self.result = "\n".join(res)
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask397BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
```
| 106,497 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.
The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission β ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!
Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket β because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li β€ x β€ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.
Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.
In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.
Input
The first line contains the number of universities t, (1 β€ t β€ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 β€ ni, li, ri β€ 109; li β€ ri).
Output
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
Examples
Input
2
5 2 3
6 4 5
Output
Yes
No
Note
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Tags: constructive algorithms, implementation, math
Correct Solution:
```
for i in range(int(input())):
n, l, r = map(int, input().split())
print('No' if (n // l) * r < n else 'Yes')
```
| 106,498 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.
The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission β ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!
Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket β because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li β€ x β€ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.
Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.
In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.
Input
The first line contains the number of universities t, (1 β€ t β€ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 β€ ni, li, ri β€ 109; li β€ ri).
Output
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
Examples
Input
2
5 2 3
6 4 5
Output
Yes
No
Note
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Tags: constructive algorithms, implementation, math
Correct Solution:
```
def possible(numbers):
if int(numbers[0])//int(numbers[1])!=0 and int(numbers[0])%int(numbers[1])//(int(numbers[0])//int(numbers[1]))<=int(numbers[2])-int(numbers[1]) and (int(numbers[0])%int(numbers[1])%(int(numbers[0])//int(numbers[1])) == 0 or int(numbers[0])%int(numbers[1])%int(numbers[0])//int(numbers[1])+int(numbers[0])%int(numbers[1])%(int(numbers[0])//int(numbers[1]))<=(int(numbers[2])-int(numbers[1]))*(int(numbers[0])//int(numbers[1])-int(numbers[0])//int(numbers[2]))):
return 'Yes'
return 'No'
for i in range(0,int(input())):
numbers=input().split(' ')
if i == -1 and int(numbers[0])!=2 and int(numbers[0])!=912247143:
print(numbers)
print(possible(numbers))
```
| 106,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.