message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | instruction | 0 | 57,619 | 14 | 115,238 |
Tags: implementation
Correct Solution:
```
entrada1 = list(map(int,input().split()))
entrada2 = list(map(int,input().split()))
sum = 0
for i in range(1,entrada1[0]+1):
sum = sum + i
if(sum >= entrada1[1]):
sum = i - (sum - entrada1[1])
print(entrada2[sum-1])
break
``` | output | 1 | 57,619 | 14 | 115,239 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | instruction | 0 | 57,620 | 14 | 115,240 |
Tags: implementation
Correct Solution:
```
import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
if __name__ == '__main__':
Y = lambda: list(map(int, input().split()))
P = lambda: map(int, input().split())
n, k = P()
s, i, a = 0, 1, Y()
while s + i < k:
s += i
i += 1
print(a[k - s - 1])
``` | output | 1 | 57,620 | 14 | 115,241 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | instruction | 0 | 57,621 | 14 | 115,242 |
Tags: implementation
Correct Solution:
```
list1 = list(map(int, input().split()))
n = list1[0]
k = list1[1]
robotsSequence = list(map(int, input().split()))
def my_function(n, k, robotsSequence):
for i in range(1, n + 1, 1):
length = i*(i + 1) / 2
if(length >= k):
retreat = length - k
index = n - 1 - (n - i) - retreat
return robotsSequence[int(index)]
print(my_function(n, k, robotsSequence))
``` | output | 1 | 57,621 | 14 | 115,243 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | instruction | 0 | 57,622 | 14 | 115,244 |
Tags: implementation
Correct Solution:
```
n, k = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().split()))
for i in range(1, n+1):
res = (1 + i) * i // 2
if res >= k:
k = k - (i - 1) * i // 2
print(a[k-1])
break
``` | output | 1 | 57,622 | 14 | 115,245 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | instruction | 0 | 57,623 | 14 | 115,246 |
Tags: implementation
Correct Solution:
```
n,k=[int(x) for x in input().split()]
s=[int(x) for x in input().split()]
i=0
while (((i+1)*(i+2))//2)<k:
i+=1
k-=(((i+1)*(i))//2)
print(s[k-1])
``` | output | 1 | 57,623 | 14 | 115,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | instruction | 0 | 57,624 | 14 | 115,248 |
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
ids = input().split()
F = [0, 1]
i = 1
while F[i] < k:
i += 1
F.append(F[i-1] + i)
print(ids[i-1 - (F[i] - k)])
``` | output | 1 | 57,624 | 14 | 115,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | instruction | 0 | 57,625 | 14 | 115,250 |
Tags: implementation
Correct Solution:
```
n,k = map(int,input().split(" "))
a = list(map(int, input().split(" ")))
k -= 1
no = int(((8*k+1)**0.5 - 1)*0.5)
idx = k - int((no**2 + no)*0.5)
print(a[idx])
``` | output | 1 | 57,625 | 14 | 115,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | instruction | 0 | 57,626 | 14 | 115,252 |
Tags: implementation
Correct Solution:
```
n,k= map(int,input().split())
a= list(map(int,input().split()))
i=1
while(i<k):
k-=i
i+=1
print(a[k-1])
``` | output | 1 | 57,626 | 14 | 115,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
Submitted Solution:
```
n,k = map(int,input().split())
idt = list(map(int,input().split()))
t,count =0,0
for i in range(1,n+1):
count+=i;t=i
if count>=k:
break
ans = t-(count-k)
print(idt[ans-1])
``` | instruction | 0 | 57,627 | 14 | 115,254 |
Yes | output | 1 | 57,627 | 14 | 115,255 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
Submitted Solution:
```
def inp():
return map(int, input().split())
def arr_inp():
return [int(x) for x in input().split()]
n, k = inp()
id, ans, tem = arr_inp(), 1, 0
for i in range(2, k + 1):
if ans >= k:
break
tem = ans
ans += i
print(id[k - tem - 1])
``` | instruction | 0 | 57,628 | 14 | 115,256 |
Yes | output | 1 | 57,628 | 14 | 115,257 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
Submitted Solution:
```
n,k=map(int,input().split())
m=list(map(int,input().split()))
a=round((2*k)**(1/2))
a=a-1
a=a*(a+1)//2
print(m[k-a-1])
``` | instruction | 0 | 57,629 | 14 | 115,258 |
Yes | output | 1 | 57,629 | 14 | 115,259 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
Submitted Solution:
```
from math import sqrt
n, k = map(int, input().split())
xs = [int(x) for x in input().split()]
k -= 1
def m(k):
return int((1 + sqrt(1 + 8*k)) / 2)
def b(k):
c = m(k)
return c*(c - 1) // 2
sol = xs[k - b(k)]
print (sol)
``` | instruction | 0 | 57,630 | 14 | 115,260 |
Yes | output | 1 | 57,630 | 14 | 115,261 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
i = 1
r = []
while len(r) < k:
r += a[:i]
i += 1
print(a[k - 1])
``` | instruction | 0 | 57,632 | 14 | 115,264 |
No | output | 1 | 57,632 | 14 | 115,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
Submitted Solution:
```
def fn():
yield 1
a=1
yield 1
b=1
while True:
yield a+b
a, b = b, a+b
n, k = map(int, input().split())
lst = tuple(map(int, input().split()))
fac = fn()
a = next(fac)
for i in range(n):
b = next(fac)
if a <= k <= b:
dl = b-a
break
a = b
print(lst[dl-1])
``` | instruction | 0 | 57,633 | 14 | 115,266 |
No | output | 1 | 57,633 | 14 | 115,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
l, r = 1, n
while l <= r:
m = (l + r) // 2
id1 = m * (m - 1) // 2
id2 = m * (m + 1) // 2
if k < id1:
r = m - 1
elif k > id2:
l = m + 1
else:
print(a[k - m * (m - 1) // 2 - 1])
break
``` | instruction | 0 | 57,634 | 14 | 115,268 |
No | output | 1 | 57,634 | 14 | 115,269 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | instruction | 0 | 57,693 | 14 | 115,386 |
Tags: binary search, brute force, dp, greedy, sortings
Correct Solution:
```
read = lambda: map(int, input().split())
n, k, p = read()
a = list(read())
b = list(read())
a.sort()
b.sort()
def cal(a, b):
return abs(a - b) + abs(b - p)
mi = 1e15
for _ in range(k - n + 1):
ma = 0
for __ in range(n):
te = cal(a[__], b[_ + __])
if te > ma:
ma = te
if ma < mi:
mi = ma
print(mi)
``` | output | 1 | 57,693 | 14 | 115,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | instruction | 0 | 57,694 | 14 | 115,388 |
Tags: binary search, brute force, dp, greedy, sortings
Correct Solution:
```
def good(n, k, p, a, b, x):
j = 0
c = 0
for i in range(n):
while j < k:
if abs(a[i] - b[j]) + abs(b[j] - p) <= x:
j += 1
c += 1
break
j += 1
return c == n
n, k, p = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
a.sort()
b.sort()
l = -1
r = 2 * 10 ** 9
'''
while r - l > 1:
m = (l + r) // 2
if good(n, k, p, a, b, m):
r = m
else:
l = m
print(r)
'''
dp = [[float('inf')] * (n + 1) for i in range(k + 1)]
dp[0][0] = 0
for i in range(k):
for j in range(n + 1):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
if j < n:
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], max(dp[i][j], abs(a[j] - b[i]) + abs(b[i] - p)))
print(dp[k][n])
``` | output | 1 | 57,694 | 14 | 115,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | instruction | 0 | 57,695 | 14 | 115,390 |
Tags: binary search, brute force, dp, greedy, sortings
Correct Solution:
```
n,k,p=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort()
ans = 1000000000000000
ans = int(ans)
for i in range(k-n+1):
tmp = 0
for j in range(n):
tmp = max(tmp,abs(a[j]-b[i+j])+abs(b[i+j]-p))
ans = min(ans,tmp)
print(ans)
``` | output | 1 | 57,695 | 14 | 115,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | instruction | 0 | 57,696 | 14 | 115,392 |
Tags: binary search, brute force, dp, greedy, sortings
Correct Solution:
```
"""
http://codeforces.com/problemset/problem/830/A
2 4 50
20 100
60 10 40 80 should output 50
"""
_, _, office = [int(i) for i in input().split()]
people = sorted(int(i) for i in input().split())
keys = sorted(int(i) for i in input().split())
assert len(people) <= len(keys)
min_time = min(max(abs(p - keys[ki + v]) + abs(keys[ki + v] - office)
for v, p in enumerate(people))
for ki in range(len(keys) - len(people) + 1))
print(min_time)
``` | output | 1 | 57,696 | 14 | 115,393 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | instruction | 0 | 57,697 | 14 | 115,394 |
Tags: binary search, brute force, dp, greedy, sortings
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def check(mid,a,b,n,k,p):
z = k-1
for i in range(n-1,-1,-1):
while z != -1 and abs(b[z]-a[i])+abs(b[z]-p) > mid:
z -= 1
if z == -1:
return 0
z -= 1
return 1
def main():
n,k,p = map(int,input().split())
a = sorted(map(int,input().split()))
b = sorted(map(int,input().split()))
hi,lo = 2*10**9,0
while hi >= lo:
mid = (hi+lo)//2
if check(mid,a,b,n,k,p):
hi = mid-1
fl = 0
else:
lo = mid+1
fl = 1
print(mid+fl)
#Fast IO Region
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")
if __name__ == '__main__':
main()
``` | output | 1 | 57,697 | 14 | 115,395 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | instruction | 0 | 57,698 | 14 | 115,396 |
Tags: binary search, brute force, dp, greedy, sortings
Correct Solution:
```
read = lambda: map(int, input().split())
n, k, p = read()
a, b = sorted(read()), sorted(read())
print(min(max(abs(b[i + d] - a[i]) + abs(b[i + d] - p) for i in range(n)) for d in range(k - n + 1)))
# Made By Mostafa_Khaled
``` | output | 1 | 57,698 | 14 | 115,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | instruction | 0 | 57,699 | 14 | 115,398 |
Tags: binary search, brute force, dp, greedy, sortings
Correct Solution:
```
from sys import stdin, stdout
n,k,p = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
a = sorted(a)
b = [int(x) for x in stdin.readline().rstrip().split()]
b = sorted(b)
ans = int(2e9+1)
for i in range(k-n+1):
tmp = 0
for j in range(n):
tmp = max(tmp,abs(a[j]-b[j+i])+abs(b[j+i]-p))
ans = min(ans,tmp)
print(ans)
``` | output | 1 | 57,699 | 14 | 115,399 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | instruction | 0 | 57,700 | 14 | 115,400 |
Tags: binary search, brute force, dp, greedy, sortings
Correct Solution:
```
n,k,p = map(int,input().split(" "))
a = [int(x) for x in input().split(" ")]
b = [int(x) for x in input().split(" ")]
a.sort()
b.sort()
result = []
for i in range(k):
max_time = 0
if k - i < n:
break
for ind in range(n):
tem=0
tem += abs(a[ind]-b[i+ind])
tem += abs(b[i+ind]-p)
if max_time < tem:
max_time = tem
result.append(max_time)
print(min(result))
``` | output | 1 | 57,700 | 14 | 115,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES | instruction | 0 | 58,120 | 14 | 116,240 |
Tags: implementation
Correct Solution:
```
queries = int(input())
for i in range(0, queries):
number = int(input())
permutation = input()
permutation_1 = permutation.split(" ")
permutation_array = []
for i in permutation_1:
permutation_array.append(int(i))
new_array_c =[]
new_array_ac =[]
for i in range(0, number):
if permutation_array[i] == number:
new_array_c.extend(permutation_array[i+1:number])
new_array_c.extend(permutation_array[0:i+1])
new_array_ac.extend(permutation_array[i:number])
new_array_ac.extend(permutation_array[0:i])
break
#print(new_array_c)
#print(new_array_ac)
sample_array_1 = []
sample_array_2 = []
for i in range(1,number+1):
sample_array_1.append(i)
sample_array_2.append(number+1-i)
if new_array_c == sample_array_1 or new_array_ac == sample_array_2:
print("YES")
else:
print("NO")
``` | output | 1 | 58,120 | 14 | 116,241 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES | instruction | 0 | 58,121 | 14 | 116,242 |
Tags: implementation
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
arr = [int(p) for p in input().split()]
ind = arr.index(1)
f = ind + 1
b = ind - 1
fs = [1]
bs = [1]
if f == len(arr):
f = 0
while arr[f] != 1:
if f == len(arr)-1:
fs.append(arr[f])
f = 0
continue
fs.append(arr[f])
f += 1
while arr[b] != 1:
bs.append(arr[b])
b -= 1
if sorted(bs) == bs or sorted(fs) == fs:
print('YES')
else:
print('NO')
``` | output | 1 | 58,121 | 14 | 116,243 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES | instruction | 0 | 58,122 | 14 | 116,244 |
Tags: implementation
Correct Solution:
```
q = int(input())
for query in range(q):
n = int(input())
p = [int(x) for x in input().split(' ')]
i = p.index(1)
if p[i:] + p[:i] == [j for j in range(1, n + 1)]:
ans = 'YES'
elif p[:i+1][::-1] + p[n - 1:i:-1] == [j for j in range(1, n + 1)]:
ans = 'YES'
else:
ans = 'NO'
print(ans)
``` | output | 1 | 58,122 | 14 | 116,245 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES | instruction | 0 | 58,123 | 14 | 116,246 |
Tags: implementation
Correct Solution:
```
q = int(input())
for t in range(q):
n = int (input())
a = [int(x) for x in input().split()]
a = a*2
index = a.index(1)
ans = 'NO'
if a[index:index+n] == list(range(1,n+1)) :
ans = "YES"
index = a.index(n)
if a[index:index+n] == list(range(1,n+1))[::-1] :
ans = "YES"
print(ans)
``` | output | 1 | 58,123 | 14 | 116,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES | instruction | 0 | 58,124 | 14 | 116,248 |
Tags: implementation
Correct Solution:
```
import sys
q = int(sys.stdin.readline())
for _ in range(q):
n = int(sys.stdin.readline())
p = list(map(int, sys.stdin.readline().split()))
start = 0
for i in range(n):
if p[i] == 1:
start = i
jung = True
cnt = True
for j in range(start, n):
if j == n - 1:
last = 0
if p[j] == n:
if p[0] != 1:
jung = False
break
else:
last = p[j]
if abs(last - p[0]) == 1:
for k in range(start-1):
if abs(p[k] - p[k+1]) > 1:
jung = False
break
else:
jung = False
break
else:
if abs(p[j] - p[j+1]) > 1:
jung = False
break
for j in range(start, -1, -1):
if j == 0:
first = 0
if p[j] == n:
if p[n-1] != 1:
cnt = False
break
else:
first = p[j]
if abs(first - p[n-1]) == 1:
for k in range(n-1, start+1, -1):
if abs(p[k] - p[k-1]) > 1:
cnt = False
break
else:
cnt = False
break
else:
if abs(p[j] - p[j-1]) > 1:
cnt = False
break
if jung or cnt:
print("YES")
else:
print("NO")
``` | output | 1 | 58,124 | 14 | 116,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES | instruction | 0 | 58,125 | 14 | 116,250 |
Tags: implementation
Correct Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
a=[int(x) for x in input().split()]
b=0
c=0
for i in range(n-1):
if(abs(a[i+1]-a[i])==1):
b+=1
elif(abs(a[i+1]-a[i])==n-1):
c+=1
if((b==n-1 and c==0) or (b==n-2 and c==1)):
print('YES')
else:
print('NO')
``` | output | 1 | 58,125 | 14 | 116,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES | instruction | 0 | 58,126 | 14 | 116,252 |
Tags: implementation
Correct Solution:
```
def solve():
n = int(input())
arr = list(map(int, input().split()))
for i in range(1, n):
if abs(arr[i] - arr[i - 1]) != 1:
if abs(arr[-1] - arr[0]) != 1:
return "NO"
else:
i += 1
while i < n:
if abs(arr[i] - arr[i - 1]) != 1:
return 'NO'
i += 1
return 'YES'
q = int(input())
for _ in range(q):
print(solve())
"""
1
5
1 3 4 5 2
"""
``` | output | 1 | 58,126 | 14 | 116,253 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES | instruction | 0 | 58,127 | 14 | 116,254 |
Tags: implementation
Correct Solution:
```
t = int(input())
for u in range(0, t):
n = int(input())
a = []
s = input()
for i in s.split():
a.append(int(i))
f = 1
for i in range(0, n):
if a[i] == 1:
j = i
for c in range(1, n + 1):
if c != a[j]:
f = 0
break
j = (j + 1) % n
if f == 1:
break
f = 1
j = i
for c in range(1, n + 1):
if c != a[j]:
f = 0
break
j = (j - 1 + n) % n
break
if f:
print("YES")
else:
print("NO")
``` | output | 1 | 58,127 | 14 | 116,255 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
######################################################################
# Write your code here
import sys
from math import *
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = lambda : [float(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
#from collections import defaultdict as df
import heapq
#heapq.heapify(li) heappush(li,4) heappop(li)
#import random
#random.shuffle(list)
infinite = float('inf')
#######################################################################
t=int(input())
for _ in range(t):
n=int(input())
l=RI()
index=-1
for i in range(n):
if(l[i]==1):
index=i
break
#print(index)
if(index!=-1):
flag=0
for i in range(n-1):
if(l[(i+index)%n]-l[(index+i+1)%n]!=-1):
flag=1
if(flag==0):
print("YES")
continue
flag=0
index+=1
for i in range(n-1):
if(l[(i+index)%n]-l[(i+1+index)%n]!=1):
flag=1
if(flag==0):
print("YES")
continue
print("NO")
``` | instruction | 0 | 58,128 | 14 | 116,256 |
Yes | output | 1 | 58,128 | 14 | 116,257 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
from collections import deque
I = lambda: map(int,input().split())
for i in range(int(input())):
res = 0
n = int(input())
a = list(I())
a = deque(a)
a.append(a[0])
a.appendleft(a[-2])
#print(a)
for j in range(1,n):
if a[j] == n: e2 = 1
else: e2 = a[j] + 1
if a[j] == 1: e1 = n
else: e1 = a[j] - 1
if (a[j-1] in [e1, e2]) and (a[j+1] in [e1, e2]):
pass
else:
res = 1
break
print('YNEOS'[res::2])
``` | instruction | 0 | 58,129 | 14 | 116,258 |
Yes | output | 1 | 58,129 | 14 | 116,259 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
o=int(input())
for j in range(0,o):
n=int(input())
p=input().rstrip().split(' ')
if len(p)==1:
print("YES")
else:
V=-1;
for i in range(0,len(p)-1):
if abs(int(p[i])-1) == int(p[i+1]):
continue;
elif abs(int(p[i])+1) == int(p[i+1]):
continue;
else:
V=i+1;
break;
if V==-1:
print("YES")
else:
T=p[V:len(p)]
B=p[0:V]
C=T+B;
N=list(C)
N.sort(key=int)
F=0;
for i in range(0,len(N)):
if N[i] == C[i]:
continue;
else:
F=1;
break;
if F==0:
print("YES")
else:
N.reverse();
for i in range(0,len(N)):
if N[i]==C[i]:
continue;
else:
F=2;
break;
if F!=2:
print("YES")
else:
print("NO")
``` | instruction | 0 | 58,130 | 14 | 116,260 |
Yes | output | 1 | 58,130 | 14 | 116,261 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
#import sys
#sys.stdin =open("input16.txt")
t=int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))
f=0
i=0
while(i<n):
if abs(l[i]-l[i-1])>1:
f=f+1
i=i+1
if(f<2):
print('YES')
else:
print('NO')
``` | instruction | 0 | 58,131 | 14 | 116,262 |
Yes | output | 1 | 58,131 | 14 | 116,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
n = int(input())
i = 0
flag = False
while i < n:
m = int(input())
if m==1:
print("YES")
i+=1
continue
a = list(map(int, input().split()))
j = 0
while a[j] != 1:
j += 1
b = []
for k in range(m - j):
b.append(a[j + k])
for k in range(j):
b.append(a[k])
for j in range(m - 1):
if b[j] < b[j + 1]:
flag = True
else:
flag = False
break
if flag == True:
i+=1
print("YES")
continue
else:
j = 0
while a[j] != m:
j += 1
b = []
for k in range(m - j):
b.append(a[j + k])
for k in range(j):
b.append(a[k])
for j in range(m - 1):
if b[j] > b[j + 1]:
flag = True
else:
flag = False
break
if flag==True:
print("YES")
else:
print("NO")
i+=1
``` | instruction | 0 | 58,132 | 14 | 116,264 |
No | output | 1 | 58,132 | 14 | 116,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
for t in range(int(input())):
a = int(input())
b = list(map(int,input().strip().split()))
count = 0
rcount = 0
for i in range (a-1):
if(b[i] + 1 != b[i+1]):
count += 1
elif(b[i]-1 !=b[i+1]):
rcount += 1
if(rcount >= 2 and count >= 2):
print("NO")
else:
print("YES")
``` | instruction | 0 | 58,133 | 14 | 116,266 |
No | output | 1 | 58,133 | 14 | 116,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
q = int(input())
for i in range(q):
n = int(input())
tr = "".join([str(i + 1) for i in range(n)])
p = "".join(input().split())
p = p + p + p
if tr in p or tr in p[::-1]:
print("YES")
else:
print("NO")
``` | instruction | 0 | 58,134 | 14 | 116,268 |
No | output | 1 | 58,134 | 14 | 116,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing β the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).
For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.
Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 200) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 200) β the number of students.
The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 β€ p_i β€ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).
Output
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
Example
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
q = int(input())
results = []
for x in range(q):
n = int(input())
students = [int(i) for i in input().split()]
if n < 2:
print("YES")
continue
start = students.index(1)
isClockwise = 1 if students[(start + 1) % n] == 2 else -1
ind = start + isClockwise
if ind >= n:
ind -= n
result = True
while students[ind] != 1:
print(ind)
if students[ind - isClockwise] != students[ind] - 1:
result = False
break
ind += isClockwise
if ind >= n:
ind -= n
print("YES" if result else "NO")
``` | instruction | 0 | 58,135 | 14 | 116,270 |
No | output | 1 | 58,135 | 14 | 116,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n piranhas with sizes a_1, a_2, β¦, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
* The piranha eats the second piranha and a becomes [\underline{8}].
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (2 β€ n β€ 3 β
10^5) β the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9), where a_i is the size of the i-th piranha.
It is guaranteed that the sum of n does not exceed 3 β
10^5 (β n β€ 3 β
10^5).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
Input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
Output
3
-1
4
3
3
1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. | instruction | 0 | 58,221 | 14 | 116,442 |
Tags: constructive algorithms, greedy
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
aux = [0 for i in range(n)]
for i in range(n):
if i>0 and arr[i] > arr[i-1]:
aux[i] = 1
if i<n-1 and arr[i] > arr[i+1]:
aux[i] = 1
m = max(arr)
ans = -1
for i in range(n):
if arr[i] == m and aux[i] == 1:
ans = i+1
break
print(ans)
``` | output | 1 | 58,221 | 14 | 116,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n piranhas with sizes a_1, a_2, β¦, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
* The piranha eats the second piranha and a becomes [\underline{8}].
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (2 β€ n β€ 3 β
10^5) β the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9), where a_i is the size of the i-th piranha.
It is guaranteed that the sum of n does not exceed 3 β
10^5 (β n β€ 3 β
10^5).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
Input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
Output
3
-1
4
3
3
1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. | instruction | 0 | 58,222 | 14 | 116,444 |
Tags: constructive algorithms, greedy
Correct Solution:
```
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
t=int(input())
for i in range(t):
n=int(input())
a=lnii()
if len(set(a))==1:
print(-1)
continue
mv=max(a)
for i in range(n):
if a[i]==mv:
if i-1>=0 and a[i-1]!=mv:
print(i+1)
break
if i+1<n and a[i+1]!=mv:
print(i+1)
break
``` | output | 1 | 58,222 | 14 | 116,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n piranhas with sizes a_1, a_2, β¦, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
* The piranha eats the second piranha and a becomes [\underline{8}].
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (2 β€ n β€ 3 β
10^5) β the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9), where a_i is the size of the i-th piranha.
It is guaranteed that the sum of n does not exceed 3 β
10^5 (β n β€ 3 β
10^5).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
Input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
Output
3
-1
4
3
3
1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. | instruction | 0 | 58,223 | 14 | 116,446 |
Tags: constructive algorithms, greedy
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
m=max(l)
ml=[]
for i in range(n):
if(l[i]==m):
ml.append(i)
ans=-1
if(ml[0]!=0):
ans=ml[0]+1
else:
for i in ml:
if(i!=n-1 and l[i]!=l[i+1]):
ans=i+1
break
print(ans)
``` | output | 1 | 58,223 | 14 | 116,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n piranhas with sizes a_1, a_2, β¦, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
* The piranha eats the second piranha and a becomes [\underline{8}].
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (2 β€ n β€ 3 β
10^5) β the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9), where a_i is the size of the i-th piranha.
It is guaranteed that the sum of n does not exceed 3 β
10^5 (β n β€ 3 β
10^5).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
Input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
Output
3
-1
4
3
3
1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. | instruction | 0 | 58,224 | 14 | 116,448 |
Tags: constructive algorithms, greedy
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
n = max(a)
k = 0
for i in range(len(a)):
if a[i]==n:
if i==0:
if a[i+1]<n:
k+=1
break
elif i==len(a)-1:
if a[i-1]<n:
k+=1
break
else:
if a[i+1]<n or a[i-1]<n:
k+=1
break
if k!=0:
print(i+1)
else:
print(-1)
``` | output | 1 | 58,224 | 14 | 116,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n piranhas with sizes a_1, a_2, β¦, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
* The piranha eats the second piranha and a becomes [\underline{8}].
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (2 β€ n β€ 3 β
10^5) β the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9), where a_i is the size of the i-th piranha.
It is guaranteed that the sum of n does not exceed 3 β
10^5 (β n β€ 3 β
10^5).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
Input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
Output
3
-1
4
3
3
1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. | instruction | 0 | 58,225 | 14 | 116,450 |
Tags: constructive algorithms, greedy
Correct Solution:
```
def main():
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
M = max(a)
occs = a.count(M)
if occs == n:
print(-1)
else:
if a[0] == M and a[1] != M:
print(1)
continue
if a[-1] == M and a[-2] != M:
print(n)
continue
for j in range(1, n - 1):
if a[j] == M and (a[j - 1] != M or a[j + 1] != M):
print(j + 1)
break
main()
``` | output | 1 | 58,225 | 14 | 116,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n piranhas with sizes a_1, a_2, β¦, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
* The piranha eats the second piranha and a becomes [\underline{8}].
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (2 β€ n β€ 3 β
10^5) β the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9), where a_i is the size of the i-th piranha.
It is guaranteed that the sum of n does not exceed 3 β
10^5 (β n β€ 3 β
10^5).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
Input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
Output
3
-1
4
3
3
1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. | instruction | 0 | 58,226 | 14 | 116,452 |
Tags: constructive algorithms, greedy
Correct Solution:
```
for t in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
if len(set(p)) == 1:
print(-1)
continue
m = max(p)
index = p.index(m)
if index == 0 and p[1] == p[0]:
index += 1
while len(set([p[index-1], p[index], p[index+1]])) == 1:
index += 1
print(index + 1)
``` | output | 1 | 58,226 | 14 | 116,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n piranhas with sizes a_1, a_2, β¦, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
* The piranha eats the second piranha and a becomes [\underline{8}].
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (2 β€ n β€ 3 β
10^5) β the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9), where a_i is the size of the i-th piranha.
It is guaranteed that the sum of n does not exceed 3 β
10^5 (β n β€ 3 β
10^5).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
Input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
Output
3
-1
4
3
3
1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. | instruction | 0 | 58,227 | 14 | 116,454 |
Tags: constructive algorithms, greedy
Correct Solution:
```
t = int(input())
for i in range(t):
n = int(input())
l = list(map(int,input().split()))
m = max(l)
for j in range(n):
if l[j] == m:
b1 = False
b2 = False
if j >= 1:
if l[j-1] != m:
b1 = True
if j < n-1:
if l[j+1] != m:
b2 = True
if b1 or b2:
print(j+1)
break
else:
print(-1)
``` | output | 1 | 58,227 | 14 | 116,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n piranhas with sizes a_1, a_2, β¦, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
* The piranha eats the second piranha and a becomes [\underline{8}].
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (2 β€ n β€ 3 β
10^5) β the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9), where a_i is the size of the i-th piranha.
It is guaranteed that the sum of n does not exceed 3 β
10^5 (β n β€ 3 β
10^5).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
Input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
Output
3
-1
4
3
3
1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. | instruction | 0 | 58,228 | 14 | 116,456 |
Tags: constructive algorithms, greedy
Correct Solution:
```
def get_dom(a, n):
mx = max(a)
for i in range(n):
if a[i] != mx:
for j in range(i, -1, -1):
if a[j] == mx:
return j + 1
for j in range(i, n):
if a[j] == mx:
return j + 1
return -1
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
print(get_dom(a, n))
``` | output | 1 | 58,228 | 14 | 116,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 β€ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line.
Input
The single line of the input contains two integers n and m (1 β€ n, m β€ 100), separated by a space.
Output
Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them.
Examples
Input
3 3
Output
GBGBGB
Input
4 2
Output
BGBGBB
Note
In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | instruction | 0 | 58,309 | 14 | 116,618 |
Tags: greedy
Correct Solution:
```
import sys,os,io,time,copy,math
from functools import lru_cache
if os.path.exists('input.txt'):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def main():
#n=int(input())
#arr=list(map(int,input().split()))
n,m=map(int,input().split())
if n<m:
for i in range(n):
print('GB',end="")
for i in range(m-n):
print('G',end="")
print("")
elif n>m:
for i in range(m):
print('BG',end="")
for i in range(n-m):
print('B',end="")
print("")
else:
for i in range(n):
print('GB',end="")
print("")
main()
``` | output | 1 | 58,309 | 14 | 116,619 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 β€ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line.
Input
The single line of the input contains two integers n and m (1 β€ n, m β€ 100), separated by a space.
Output
Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them.
Examples
Input
3 3
Output
GBGBGB
Input
4 2
Output
BGBGBB
Note
In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | instruction | 0 | 58,310 | 14 | 116,620 |
Tags: greedy
Correct Solution:
```
import os.path
import sys
if os.path.exists('input.txt'):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n,m=[int(x) for x in input().split(' ')]
x=min(n,m)
#print(x)
if n<m:
ans=x*"GB"
else:
ans=x*'BG'
n=n-x
m=m-x
#print(n,m)
if n!=0:
ans+=n*'B'
if m!=0:
ans+=m*'G'
print((ans))
``` | output | 1 | 58,310 | 14 | 116,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 β€ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line.
Input
The single line of the input contains two integers n and m (1 β€ n, m β€ 100), separated by a space.
Output
Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them.
Examples
Input
3 3
Output
GBGBGB
Input
4 2
Output
BGBGBB
Note
In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal.
Submitted Solution:
```
import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
"""
author - Sayan Bose
Brooklyn 99 is love!
"""
b, g = map(int, input().split())
f = 1
while b > 0 or g > 0:
if f:
f = 0
if b:
b -= 1
print('B', end='')
else:
g -= 1
print('G', end='')
else:
f = 1
if g:
g -= 1
print('G' ,end='')
else:
b -= 1
print('B', end='')
``` | instruction | 0 | 58,311 | 14 | 116,622 |
No | output | 1 | 58,311 | 14 | 116,623 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.