message stringlengths 2 22.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 145 109k | cluster float64 9 9 | __index_level_0__ int64 290 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2 | instruction | 0 | 33,792 | 9 | 67,584 |
Tags: binary search, greedy, math
Correct Solution:
```
f = lambda: map(int, input().split())
A, B, n = f()
k = 0.5
for i in range(n):
l, t, m = f()
b = A / B + l - k
c = b - k - (m * t) / B
r = min(l + int((b * b - 2 * c) ** k - b), (t - A) // B + 1)
print(-1 if r < l else r)
# Made By Mostafa_Khaled
``` | output | 1 | 33,792 | 9 | 67,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2 | instruction | 0 | 33,793 | 9 | 67,586 |
Tags: binary search, greedy, math
Correct Solution:
```
a,b,n = map(int,input().split())
lis=[0]+[(a+ i*b) for i in range(1000001)]
for i in range(n):
ll,t,m = map(int,input().split())
l=ll
r=(t-a)//b+1
while l<=r:
mid = l+(r-l)//2
ter = mid-ll+1
su = ((ter)*(2*lis[ll] + (ter-1)*b))//2
if t*m>=su and lis[mid]<=t:
l=mid+1
else:
r=mid-1
# print(l,r)
if l==ll:
print(-1)
else:
print(l-1)
``` | output | 1 | 33,793 | 9 | 67,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2
Submitted Solution:
```
from math import *
inp=input()
a,b,c=inp.split()
a=float(a)
b=float(b)
c=float(c)
for i in range(0,int(c)):
l,t,m=input().split()
l=float(l)
t=float(t)
m=float(m)
hl=a+(l-1.0)*b
if hl>t:
print (-1)
continue
num=(t-hl)/b+1.0
terms=floor(num)
num=(b-2.0*hl+sqrt((2.0*hl-b)*(2.0*hl-b)-4.0*(b)*(-2.0*t*m)))/(2.0*b)
terms2=floor(num)
print (int((l+min(terms,terms2)-1)))
``` | instruction | 0 | 33,794 | 9 | 67,588 |
Yes | output | 1 | 33,794 | 9 | 67,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2
Submitted Solution:
```
R = lambda: map(int, input().split())
a, b, n = R()
for _ in range(n):
l, t, m = R()
ll, rr = l - 1, 10**6 + 7
sl = a + (l - 1) * b
while ll < rr:
mm = (ll + rr + 1) // 2
sr = a + (mm - 1) * b
slr = (sl + sr) * (mm - l + 1) // 2
if slr <= t * m and sr <= t:
ll = mm
else:
rr = mm - 1
if ll >= l:
print(ll)
else:
print(-1)
``` | instruction | 0 | 33,795 | 9 | 67,590 |
Yes | output | 1 | 33,795 | 9 | 67,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2
Submitted Solution:
```
from math import sqrt
inp = input()
l = list(map(int, inp.split(' ')))
A = l[0]
B = l[1]
n = l[2]
for i in range(n):
inp = input()
temp = list(map(int, inp.split(' ')))
l = temp[0]
t = temp[1]
m = temp[2]
imp = 0
a = B/2
b = (A - 1/2 * B)
c = -A * (l - 1) + 3*B*l/2 - B*l*l/2 - B - t*m
res1 = 0
if b*b - 4 * a * c > 0:
res1 = int((-b + sqrt(b*b - 4 * a*c) )/ (2 *a))
else:
imp = 1
res2 = 0
if (t - A - B*(-1))/B > 0:
res2 = int((t - A - B*(-1))/B)
else:
imp = 1
if res2 < l:
imp = 1
if not imp:
print(min(res1, res2))
else:
print(-1)
``` | instruction | 0 | 33,796 | 9 | 67,592 |
Yes | output | 1 | 33,796 | 9 | 67,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 15 01:59:52 2015
codeforces 299 Div 2 C
"""
import sys
def read_data():
A, B, n = map(int, input().split())
ltm = sys.stdin.readlines()
return A, B, ltm
def solve(A, B, ltm):
for line in ltm:
L, t, m = map(int, line.split())
print(max_r(L, t, m, A, B))
memo = dict()
def max_r(L, t, m, A, B):
global memo
if (L, t, m) in memo:
return memo[L, t, m]
r_upper = (t - A) // B + 2
if r_upper <= L:
memo[L, t, m] = -1
return -1
r_lower = L
threshold = t * m
while r_upper > r_lower + 1:
mid = (r_upper + r_lower) // 2
if (2 * A + B * (L + mid - 2)) * (mid - L + 1) // 2 <= threshold:
r_lower = mid
else:
r_upper = mid
memo[L, t, m] = r_lower
return r_lower
A, B, ltm = read_data()
solve(A, B, ltm)
``` | instruction | 0 | 33,797 | 9 | 67,594 |
Yes | output | 1 | 33,797 | 9 | 67,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2
Submitted Solution:
```
def sumi(i):
return a*(i-l+1)+b*(((i*(i-1))//2)- (((l-1)*(l-2))//2))
def final(a,b,n,l,t,m):
if l>=t:
return -1
k=(t-(a-b))//b
#print(k)
if (k<=m or sumi(k)<=(t*m)) :
if k>=l:
return k
else:
return -1
i=l
z=k
p=220
while(p):
mid=(i+z)//2
sum=sumi(mid)
#print(sum)
if sum>(t*m):
z=mid-1
else:
i=mid
#print(i)
p=p-1
return i
a,b,n=[int(i) for i in input().split()]
for i in range(n):
l,t,m=[int(i) for i in input().split()]
print(final(a,b,n,l,t,m))
``` | instruction | 0 | 33,798 | 9 | 67,596 |
No | output | 1 | 33,798 | 9 | 67,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 15 01:59:52 2015
codeforces 299 Div 2 C
"""
import sys
def read_data():
A, B, n = map(int, input().split())
ltm = sys.stdin.readlines()
return A, B, ltm
def solve(A, B, ltm):
for line in ltm:
L, t, m = map(int, line.split())
print(max_r(L, t, m, A, B))
def max_r(L, t, m, A, B):
r_upper = (t - A) // B + 2
if r_upper <= L:
return -1
r_lower = L
threshold = t * m - A
while r_upper > r_lower + 1:
mid = (r_upper + r_lower) // 2
if B * (L + mid - 2) * (mid - L + 1) // 2 <= threshold:
r_lower = mid
else:
r_upper = mid
return r_lower
A, B, ltm = read_data()
solve(A, B, ltm)
``` | instruction | 0 | 33,799 | 9 | 67,598 |
No | output | 1 | 33,799 | 9 | 67,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2
Submitted Solution:
```
import sys
A, B, n = map(int, (sys.stdin.readline()).split(' '))
def si(i):
return A + (i-1) * B
def accu(i, j):
return (si(i) + si(j)) * (j - i + 1) // 2
#print( [si(i) for i in range(1, 11)])
#print( accu(1, 10))
for c in range(0, n):
l, t, m = map(int, (sys.stdin.readline()).split(' '))
#the seq is monotoically increasing.
#if the seq[l] can't be eaten by t times, it's no answer
if si(l) > t:
print(-1)
continue
p = l
q = l + t
s = m*t
while p <= q:
mid = (p + q) // 2
if accu(l, mid) > s:
q = mid - 1
elif accu(l, mid) < s:
p = mid + 1
elif accu(l, mid) == s:
p = mid + 1
break
print(p - 1)
``` | instruction | 0 | 33,800 | 9 | 67,600 |
No | output | 1 | 33,800 | 9 | 67,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
<image>
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
Input
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
Output
For each query, print its answer in a single line.
Examples
Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2
Submitted Solution:
```
import sys
inp = list(map(int,input().split()))
A = inp[0]
B = inp[1]
n = inp[2]
for i in range(n):
inp = list(map(int,input().split()))
l = inp[0]
t = inp[1]
m = inp[2]
if A + (l-1)*B > t:
print(-1)
else:
# h = A + (i-1)*B determino el mayor que me puedo comer en t mordiscos (h=t)
pos = int(((t-A)/B)+1)
s = 0
j = l
hl = []
while (s < t*m):
hi = A + B*(j-1)
if (s+hi > t*m):
break
hl += [hi]
s += hi
j += 1
print(j-1)
``` | instruction | 0 | 33,801 | 9 | 67,602 |
No | output | 1 | 33,801 | 9 | 67,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
Input
5 1 3 2
Output
GBGBG
Input
7 2 2 5
Output
BBGBGBB
Input
4 3 4 0
Output
NO
Submitted Solution:
```
n, k, a, b = [int(i) for i in input().split()]
if a > b:
max_char = 'G'
min_char = 'B'
else:
max_char = 'B'
min_char = 'G'
maxab = max(a,b)
minab = min(a,b)
ans_string = ''
exit_flag = False
no_flag = False
while maxab != minab and minab > 0:
num_move = min(k, maxab - minab)
ans_string += (max_char* num_move + min_char)
maxab -= num_move
minab -= 1
n -= (num_move+1)
if maxab > k and minab == 0:
exit_flag = True
no_flag = True
print('NO')
break
if maxab > k and minab == 0 and not no_flag:
exit_flag = True
print('NO')
if not exit_flag:
if maxab == minab:
ans_string += (max_char + min_char )* maxab
minab = 0
maxab = 0
if maxab > 0:
ans_string += max_char * maxab
print(ans_string)
``` | instruction | 0 | 33,899 | 9 | 67,798 |
Yes | output | 1 | 33,899 | 9 | 67,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
Input
5 1 3 2
Output
GBGBG
Input
7 2 2 5
Output
BBGBGBB
Input
4 3 4 0
Output
NO
Submitted Solution:
```
n, k, a, b = map(int, input().split())
if a == b:
print('GB'*(n//2))
else:
maxx, minn = max(a,b), min(a,b)
if maxx / (minn+1) > k:
print('NO')
else:
x = maxx//(minn+1)
y = maxx - (minn+1)*x
if a > b:
x1 = 'G'
x2 = 'B'
else:
x1 = 'B'
x2 = 'G'
arr = [x1*x for i in range(minn + 1)]
for i in range(y):
arr[i]+= x1
print(x2.join(arr))
``` | instruction | 0 | 33,900 | 9 | 67,800 |
Yes | output | 1 | 33,900 | 9 | 67,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
Input
5 1 3 2
Output
GBGBG
Input
7 2 2 5
Output
BBGBGBB
Input
4 3 4 0
Output
NO
Submitted Solution:
```
n, k, a, b = map(int, input().split())
swapped = False
if a < b:
a, b = b, a
swapped = True
maxA = (b + 1) * k
if a > maxA:
print('NO')
exit()
ans = ''
restK = k
while a != b:
if restK == 0:
ans += 'B'
b -= 1
restK = k
continue
ans += 'G'
a -= 1
restK -= 1
while b > 0:
ans += 'BG'
b -= 1
a -= 1
if swapped:
ans = map(lambda c: 'G' if c == 'B' else 'B', ans)
ans = ''.join(list(ans))
print(ans)
``` | instruction | 0 | 33,901 | 9 | 67,802 |
Yes | output | 1 | 33,901 | 9 | 67,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
Input
5 1 3 2
Output
GBGBG
Input
7 2 2 5
Output
BBGBGBB
Input
4 3 4 0
Output
NO
Submitted Solution:
```
n,k,a,b=map(int,input().split())
if a==b:
print("GB"*a)
elif a<b:
if k*(a+1)<b:
print("NO")
else:
#b,a
ans=[[k,1] for _ in range(a)]+[[k,0]]
x=k*(a+1)
#x>=bをx==bにする
for i in range(a+1):
if x==b:break
if x-b>=k-1:
x-=(k-1)
ans[i][0]=1
else:
ans[i][0]-=(x-b)
break
tans=[]
for i in range(a+1):
tans.append("B"*ans[i][0])
tans.append("G"*ans[i][1])
print("".join(tans))
else:
if k*(b+1)<a:
print("NO")
else:
#a,b
ans=[[k,1] for _ in range(b)]+[[k,0]]
x=k*(b+1)
#x>=aをx==aにする
for i in range(b+1):
if x==a:break
if x-a>=k-1:
x-=(k-1)
ans[i][0]=1
else:
ans[i][0]-=(x-a)
break
tans=[]
for i in range(b+1):
tans.append("G"*ans[i][0])
tans.append("B"*ans[i][1])
print("".join(tans))
``` | instruction | 0 | 33,902 | 9 | 67,804 |
Yes | output | 1 | 33,902 | 9 | 67,805 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
Input
5 1 3 2
Output
GBGBG
Input
7 2 2 5
Output
BBGBGBB
Input
4 3 4 0
Output
NO
Submitted Solution:
```
n,k,a,b=[int(i) for i in input().split()]
ans=[]
if a>=b:
gr=[k]*(a//k)
if a%k>0:
gr.append(a%k)
if len(gr)>1:
if b//(len(gr)-1)<=k:
bl=[b//(len(gr)-1)]*(len(gr)-1)
bl.append(b%(len(gr)-1))
else:
bl=[k]*(len(gr)-1)
bl.append(b-k*(len(gr)-1))
else:
bl=[b]
for i in range(len(gr)):
ans.extend(['G']*gr[i])
ans.extend(['B']*bl[i])
else:
gr=[k]*(b//k)
if b%k>0:
gr.append(b%k)
if len(gr)>1:
if a//(len(gr)-1)<=k:
bl=[a//(len(gr)-1)]*(len(gr)-1)
bl.append(a%(len(gr)-1))
else:
bl=[k]*(len(gr)-1)
bl.append(a-k*(len(gr)-1))
else:
bl=[a]
for i in range(len(gr)):
ans.extend(['B']*gr[i])
ans.extend(['G']*bl[i])
ans=''.join(ans)
if 'G'*(k+1) in ans or 'B'*(k+1) in ans:
print('NO')
else:
print(ans)
``` | instruction | 0 | 33,903 | 9 | 67,806 |
No | output | 1 | 33,903 | 9 | 67,807 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
Input
5 1 3 2
Output
GBGBG
Input
7 2 2 5
Output
BBGBGBB
Input
4 3 4 0
Output
NO
Submitted Solution:
```
n, k, a, b = map(int, input().split())
if (max(a, b) - 1) // k > min(a, b):
print("NO")
exit()
s = ""
if a == 0:
print('B' * b)
exit()
elif b == 0:
print('G' * a)
exit()
if k == 1:
if a > b:
s += 'G'
f = 'BG'
else:
s += 'B'
f = 'GB'
s += f * min(a, b)
print(s)
exit()
if a > b:
g = k * 'G' + 'B'
f = "GB"
ass = 'G'
else:
g = k * 'B' + 'G'
f = "BG"
ass = 'B'
if (min(a, b) * k) - max(a, b) >= 0:
y = (min(a, b) * k - max(a, b) + 1) // (k - 1)
else:
y = (max(a, b) - (min(a, b) * k) - 1) // (k - 1)
s += g * (min(a, b) - y)
s += y * f
s += ass
print(s)
``` | instruction | 0 | 33,904 | 9 | 67,808 |
No | output | 1 | 33,904 | 9 | 67,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
Input
5 1 3 2
Output
GBGBG
Input
7 2 2 5
Output
BBGBGBB
Input
4 3 4 0
Output
NO
Submitted Solution:
```
from math import ceil as ceil
n,k,a,b = [int(i) for i in input().strip().split()]
if (min(a,b)+1)*k<max(a,b):
print("NO")
else:
l,m = "G","B"
if a>b:
l,m = m,l
a,b = max(a,b),min(a,b)
x = ceil(a/(b+1))
s = ""
while a>0 and b>0:
y = min(x,n)
s = s+m*y
a-=y
if not n:
break
s = s+l
b-=1
if a:
s=s+m*a
if b:
s=s+l*b
print(s)
``` | instruction | 0 | 33,905 | 9 | 67,810 |
No | output | 1 | 33,905 | 9 | 67,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
Input
5 1 3 2
Output
GBGBG
Input
7 2 2 5
Output
BBGBGBB
Input
4 3 4 0
Output
NO
Submitted Solution:
```
n, k, a, b = map(int, input().split())
f, s = 'G', 'B'
if b > a:
a, b = b, a
f, s = s, f
if a > (b + 1) * k:
print('NO')
else:
ans = [0] * (n + 1000)
ans[0] = k
a -= k
i = 1
while a > k:
b -= 1
a -= k
ans[i] = 1
ans[i + 1] = k
i += 2
l = i - 1
if a:
ans[i] = 1
ans[i + 1] = a
b -= 1
a = 0
l += 2
i = 1
while b > (k - ans[i]):
b -= (k - ans[i])
ans[i] = k
i += 2
ans[i] += b
l = max(l, i)
for i in range(l + 1):
if not (i % 2):
print(f * ans[i], end = '')
else:
print(s * ans[i], end = '')
``` | instruction | 0 | 33,906 | 9 | 67,812 |
No | output | 1 | 33,906 | 9 | 67,813 |
Provide a correct Python 3 solution for this coding contest problem.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | instruction | 0 | 33,952 | 9 | 67,904 |
"Correct Solution:
```
n = int(input())
m = list(map(int, input().split()))
k = [-1]*2*10*10*10*10*10
l = m[len(m)-1]-1
for i in range(0, n):
if k[m[n-i-1]-1] == -1:
k[l] = 0
k[m[n-i-1]-1] = 1
l = m[n-i-1]-1
print(l+1)
``` | output | 1 | 33,952 | 9 | 67,905 |
Provide a correct Python 3 solution for this coding contest problem.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | instruction | 0 | 33,953 | 9 | 67,906 |
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))[:n]
s=set()
for i in a[::-1]:
if i not in s:
s.add(i)
t=i
print(t)
``` | output | 1 | 33,953 | 9 | 67,907 |
Provide a correct Python 3 solution for this coding contest problem.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | instruction | 0 | 33,954 | 9 | 67,908 |
"Correct Solution:
```
def ma():
n=int(input())
b=list(map(int,input().split()))
k={b[-1]};last=b[-1]
for i in range(n-1,-1,-1):
if not (b[i] in k):
last=b[i];
k.add(b[i])
print(last)
ma()
``` | output | 1 | 33,954 | 9 | 67,909 |
Provide a correct Python 3 solution for this coding contest problem.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | instruction | 0 | 33,955 | 9 | 67,910 |
"Correct Solution:
```
n = int(input())
myd = {}
arr = [int(x) for x in input().split()]
for i in range(n):
myd[arr[i]] = i
print(arr[min(myd.values())])
``` | output | 1 | 33,955 | 9 | 67,911 |
Provide a correct Python 3 solution for this coding contest problem.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | instruction | 0 | 33,956 | 9 | 67,912 |
"Correct Solution:
```
#آخرین بازدید از اون کافه قبل آخرین بازدید از کافه های دیگر باشه
n=int(input())
l = [*map(int,input().split())]
tmp={}
Ans=None
for i in range(n-1,-1,-1):
if tmp.get(l[i],-1)==-1:
tmp[l[i]]=1
Ans=l[i]
else:
pass
print(Ans)
``` | output | 1 | 33,956 | 9 | 67,913 |
Provide a correct Python 3 solution for this coding contest problem.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | instruction | 0 | 33,957 | 9 | 67,914 |
"Correct Solution:
```
f = lambda: map(int, input().split())
n=int(input())
l=list(f())[::-1]
m=len(set(l))
dup=set()
for i in l:
dup.add(i)
if len(dup)==m:
print(i)
break
``` | output | 1 | 33,957 | 9 | 67,915 |
Provide a correct Python 3 solution for this coding contest problem.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | instruction | 0 | 33,958 | 9 | 67,916 |
"Correct Solution:
```
n=int(input())
s=list(map(int,input().split()))
d=[1000000000000]*(max(s)+4)
for i in range(n):
d[s[i]]=i
print(d.index(min(d)))
``` | output | 1 | 33,958 | 9 | 67,917 |
Provide a correct Python 3 solution for this coding contest problem.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | instruction | 0 | 33,959 | 9 | 67,918 |
"Correct Solution:
```
N = int(input())
times = {}
v = [int(x)-1 for x in input().split()]
for t, a in enumerate(v):
times[a] = t
mina, mint = next(iter(times.items()))
for a, t in times.items():
if t < mint:
mint = t
mina = a
print(mina+1)
``` | output | 1 | 33,959 | 9 | 67,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
Submitted Solution:
```
n = int(input())
dins = list(map(int, input().split()))
dd = dict()
for i in range(n):
dd[dins[i]] = i
tmin = min(dd.values())
for el in dd:
if dd[el] == tmin:
print(el)
break
``` | instruction | 0 | 33,960 | 9 | 67,920 |
Yes | output | 1 | 33,960 | 9 | 67,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
Submitted Solution:
```
import re
in1 = int(input())
in2 = re.split("\\s", input())
test = {}
count = 0
for x in in2:
test[x] = count
count += 1
print(min(test, key=test.get))
``` | instruction | 0 | 33,961 | 9 | 67,922 |
Yes | output | 1 | 33,961 | 9 | 67,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
Submitted Solution:
```
n = int(input())
data = list(map(int, input().split()))
d = dict()
if n == 1:
print(data[0])
exit()
d[data[-1]] = True
de = dict()
for i in range(n):
if data[i] not in de:
de[data[i]] = True
k = len(de)
for i in range(n - 2, -1, -1):
#print(d)
if data[i] not in d:
if len(d) == k - 1:
print(data[i])
exit()
else:
d[data[i]] = True
print(data[0])
``` | instruction | 0 | 33,962 | 9 | 67,924 |
Yes | output | 1 | 33,962 | 9 | 67,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
Submitted Solution:
```
"""
problem : https://codeforces.com/problemset/problem/886/B
auther : Jay Saha
handel : ponder_
date : 15/07/2020
"""
n = int(input())
visited = list(map(int, input().split()))
notVisied = set(visited)
for i in range(n - 1, -1, -1):
if len(notVisied) == 1:
break
if visited[i] in notVisied:
notVisied.remove(visited[i])
for elm in notVisied:
print(elm)
``` | instruction | 0 | 33,963 | 9 | 67,926 |
Yes | output | 1 | 33,963 | 9 | 67,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
Submitted Solution:
```
def main():
n = int(input())
s = str(input())
a = list(map(int, s.split()))
t = max(a)
m = 2*n - 1
k = 0
for i in range(t+1):
p = s.rfind(str(i))
if p > 0:
if p <= m:
m = p
k = i
print(k)
main()
``` | instruction | 0 | 33,964 | 9 | 67,928 |
No | output | 1 | 33,964 | 9 | 67,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
Submitted Solution:
```
n = int(input())
s = input()
answer = 0
pos = 0
k = n
for i in range(1, n+1):
pos = s.rfind(str(i))
if pos < k*2 and pos != -1:
k = pos
answer = s[pos]
print(answer)
``` | instruction | 0 | 33,965 | 9 | 67,930 |
No | output | 1 | 33,965 | 9 | 67,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
Submitted Solution:
```
n = int(input())
b = []
a = input().split()
if n % 2 == 0:
for i in range(0, n,2):
if a[i] in b:
b.remove(a[i])
b.append(a[i])
if a[i+1] in b:
b.remove(a[i+1])
b.append(a[i+1])
elif a[i+1] not in b:
b.append(a[i])
elif a[i] not in b:
b.append(a[i])
print(b[0])
if n % 2 != 0:
for i in range(0, n-1,2):
if a[i] in b:
b.remove(a[i])
b.append(a[i])
if a[i+1] in b:
b.remove(a[i+1])
b.append(a[i+1])
elif a[i+1] not in b:
b.append(a[i+1])
elif a[i] not in b:
b.append(a[i])
if a[n-1] in b:
b.remove(a[n-1])
b.append(a[n-1])
elif a[n-1] not in b:
b.append(a[n-1])
print(b[0])
``` | instruction | 0 | 33,966 | 9 | 67,932 |
No | output | 1 | 33,966 | 9 | 67,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
first = 0
ans=0
for i in range(n):
last = n-1
while i < last:
if a[i] == a[last]:
first = 0
break
else:
first = i
last = last-1
if i == last and first == i:
ans = (a[first])
break
if ans>0:
break
print(ans)
``` | instruction | 0 | 33,967 | 9 | 67,934 |
No | output | 1 | 33,967 | 9 | 67,935 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1 | instruction | 0 | 34,128 | 9 | 68,256 |
"Correct Solution:
```
A,B,C = [int(i) for i in input().split()]
if A == B == C and not A&1:
print(-1)
exit()
c = 0
while not (A&1 or B&1 or C&1):
A,B,C = (B+C)//2, (A+C)//2, (A+B)//2
c += 1
print(c)
``` | output | 1 | 34,128 | 9 | 68,257 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1 | instruction | 0 | 34,129 | 9 | 68,258 |
"Correct Solution:
```
a,b,c=map(int,input().split())
d=0
while(all([a%2==0,b%2==0,c%2==0])):
x=b//2+c//2
y=c//2+a//2
z=a//2+b//2
d+=1
a=x
b=y
c=z
if a==b==c:
d=-1
break
print(d)
``` | output | 1 | 34,129 | 9 | 68,259 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1 | instruction | 0 | 34,130 | 9 | 68,260 |
"Correct Solution:
```
a,b,c=map(int,input().split())
if a==b==c:
print(-int(not a%2))
else:
cnt=0
while not (a%2 or b%2 or c%2):
cnt+=1
a,b,c=(b+c)//2,(c+a)//2,(a+b)//2
print(cnt)
``` | output | 1 | 34,130 | 9 | 68,261 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1 | instruction | 0 | 34,131 | 9 | 68,262 |
"Correct Solution:
```
A,B,C=map(int,input().split())
ans=0
while A%2==0 and B%2==0 and C%2==0:
if A == B == C:
print(-1)
exit()
A1=A
B1=B
C1=C
A = B1/2+C1/2
B = A1/2+C1/2
C = A1/2+B1/2
ans +=1
print(ans)
``` | output | 1 | 34,131 | 9 | 68,263 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1 | instruction | 0 | 34,132 | 9 | 68,264 |
"Correct Solution:
```
#!/usr/bin/env python3
a, b, c = map(int, input().split())
o = 0
if a == b == c:print(a%2-1);exit()
while 1-any([a%2, b%2, c%2]):
a, b, c = (b+c)//2, (c+a)//2, (a+b)//2
o += 1
print(o)
``` | output | 1 | 34,132 | 9 | 68,265 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1 | instruction | 0 | 34,133 | 9 | 68,266 |
"Correct Solution:
```
A,B,C = list(map(int, input().split()))
if A==B==C:
if A%2==0:
answer = -1
else:
answer = 0
else:
answer = 0
while A%2==B%2==C%2==0:
A,B,C = (B+C)//2, (A+C)//2, (A+B)//2
answer += 1
print(answer)
``` | output | 1 | 34,133 | 9 | 68,267 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1 | instruction | 0 | 34,134 | 9 | 68,268 |
"Correct Solution:
```
import time
t1=time.time()
a,b,c=map(int,input().split())
cnt=0
while a%2==0 and b%2==0 and c%2==0:
a,b,c=b//2+c//2,a//2+c//2,a//2+b//2
cnt+=1
t2=time.time()
if t2-t1>1.97:
print(-1)
exit()
print(cnt)
``` | output | 1 | 34,134 | 9 | 68,269 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1 | instruction | 0 | 34,135 | 9 | 68,270 |
"Correct Solution:
```
A, B, C = map(int, input().split())
if A == B == C:
print(0 if A%2 else -1)
else:
cnt = 0
while A%2==0 and B%2==0 and C%2==0:
A, B, C = (B+C)//2, (C+A)//2, (A+B)//2
cnt += 1
print(cnt)
``` | output | 1 | 34,135 | 9 | 68,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1
Submitted Solution:
```
a,b,c = map(int,input().split())
count=0
while a%2==0 and b%2==0 and c%2==0:
if (b/2+c/2)==(a/2+c/2)==(a/2+b/2):
count=-1
break
a,b,c = b/2+c/2,a/2+c/2,a/2+b/2
count+=1
print(count)
``` | instruction | 0 | 34,136 | 9 | 68,272 |
Yes | output | 1 | 34,136 | 9 | 68,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1
Submitted Solution:
```
a,b,c=map(int, input().split())
d=0
while d<10**5:
if a%2==1 or b%2==1 or c%2==1:break
a,b,c=b/2+c/2,a/2+c/2,a/2+b/2
d+=1
else:d=-1
print(d)
``` | instruction | 0 | 34,137 | 9 | 68,274 |
Yes | output | 1 | 34,137 | 9 | 68,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1
Submitted Solution:
```
# my solution
*a, = map(int,input().split())
if any(map(lambda x: bin(x)[-1]== "1", a)):
print("0")
exit()
a = [bin(abs(a[i+1]-a[i]))[::-1].find('1') for i in range(2)]
print(max(a) if a[0]*a[1]<0 else min(a))
``` | instruction | 0 | 34,138 | 9 | 68,276 |
Yes | output | 1 | 34,138 | 9 | 68,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1
Submitted Solution:
```
a,b,c = map(int, input().split())
val = 0
if a == b == c and a%2 == 0 and b%2 == 0 and c%2 == 0:
print(-1)
else:
while a%2 == 0 and b%2 == 0 and c%2 == 0:
a,b,c = int((b+c)/2), int((a+c)/2), int((a+b)/2)
val += 1
print(val)
``` | instruction | 0 | 34,139 | 9 | 68,278 |
Yes | output | 1 | 34,139 | 9 | 68,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1
Submitted Solution:
```
# おっぱっぴー
A, B, C = map(int, input().split())
if A == B == C:
print(-1)
for i in range(10000):
if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
print(i)
break
A, B, C = B/2+C/2, A/2+C/2, A/2+B/2
``` | instruction | 0 | 34,140 | 9 | 68,280 |
No | output | 1 | 34,140 | 9 | 68,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1
Submitted Solution:
```
a,b,c=map(int,input().split())
if a==b==c:
print(-1)
else:
cnt=0
while a%2==b%2==c%2==0:
total=a+b+c
a=total//2-a//2
b=total//2-b//2
c=total//2-c//2
cnt+=1
print(cnt)
``` | instruction | 0 | 34,141 | 9 | 68,282 |
No | output | 1 | 34,141 | 9 | 68,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1
Submitted Solution:
```
def resolve():
a, b, c = map(int, input().split())
ans = 0
if a == b and b == a and c == a:
print(-1)
else:
while True:
if a%2 != 0 or b%2 != 0 or c%2 != 0:
print(ans)
break
a_a = b//2 + c//2
a_b = a//2 + c//2
a_c = a//2 + c//2
a = a_a
b = a_b
c = a_c
ans += 1
resolve()
``` | instruction | 0 | 34,142 | 9 | 68,284 |
No | output | 1 | 34,142 | 9 | 68,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
* 1 ≤ A,B,C ≤ 10^9
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print `-1` instead.
Examples
Input
4 12 20
Output
3
Input
14 14 14
Output
-1
Input
454 414 444
Output
1
Submitted Solution:
```
a, b, c = map(int, input().split())
count = 0
if a == b == c:
print(-1)
else:
for _ in range(100000):
_a, _am = divmod(a, 2)
_b, _bm = divmod(b, 2)
_c, _cm = divmod(c, 2)
if _am or _bm or _cm:
print(count)
break
else:
a = _b + _c
b = _a + _c
c = _a + _b
count += 1
else:
print(-1)
``` | instruction | 0 | 34,143 | 9 | 68,286 |
No | output | 1 | 34,143 | 9 | 68,287 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.