message stringlengths 2 433k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 113 108k | cluster float64 12 12 | __index_level_0__ int64 226 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i... | instruction | 0 | 91,762 | 12 | 183,524 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n = int(input())
a = [int(_) for _ in input().split()]
freq = {}
for item in a:
if item in freq:
freq[item] += 1
else:
freq[item] = 1
most_occ = max(freq, key=lambda x: freq[x])
index_center = a.index(most_occ)
print(len(a) - a.cou... | output | 1 | 91,762 | 12 | 183,525 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i... | instruction | 0 | 91,763 | 12 | 183,526 |
Tags: constructive algorithms, greedy
Correct Solution:
```
N = int(input())
A = [int(a) for a in input().split()]
B = [0] * (2*10**5+10)
for a in A:
B[a] += 1
ma = 0
mai = 0
for i in range(len(B)):
if B[i] > ma:
ma = B[i]
maa = i
for i in range(N):
if A[i] == maa:
mai = i
b... | output | 1 | 91,763 | 12 | 183,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i... | instruction | 0 | 91,764 | 12 | 183,528 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import collections
n = int(input())
a = input().split(" ")
count = collections.Counter()
at = []
for el in a:
count[el] += 1
at.append(int(el))
a = at
k = max(count, key=count.get)
tk = int(k)
print(n - count[k])
pos = 0
con = 0
tcon = 0
arcon = 0
whil... | output | 1 | 91,764 | 12 | 183,529 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i... | instruction | 0 | 91,765 | 12 | 183,530 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
from collections import Counter
c=Counter(l)
a=0
for x,y in c.most_common(1):
a=x
l1=[]
for i in range(n):
if l[i]==a:
l1.append(i)
l2=[]
if l1[0]!=0:
for i in range(l1[0]-1,-1,-1):
if... | output | 1 | 91,765 | 12 | 183,531 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i... | instruction | 0 | 91,766 | 12 | 183,532 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import collections
def solve():
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
max_count = sorted(c.values(), reverse=True)[0]
max_key = [k for k in c.keys() if c[k] == max_count][0]
pivot = A.index(max_key)
... | output | 1 | 91,766 | 12 | 183,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i... | instruction | 0 | 91,767 | 12 | 183,534 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import string, copy
def solution(n, nums):
counts = {}
for i in nums:
if i not in counts:
counts[i] = 0
counts[i] += 1
tmp = [(k, v) for k, v in counts.items()]
tmp.sort(key=lambda x:x[1])
v = tmp[-1][0]
s... | output | 1 | 91,767 | 12 | 183,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i... | instruction | 0 | 91,768 | 12 | 183,536 |
Tags: constructive algorithms, greedy
Correct Solution:
```
from collections import Counter
def solve():
n = int(input())
arr = list(map(int, input().split(" ")))
highest_freq_items = Counter(arr).most_common(1)[0]
highest_freq = highest_freq_items[1]
highest_freq_num = highest_freq_items[0]
if (n - highest_fre... | output | 1 | 91,768 | 12 | 183,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (i... | instruction | 0 | 91,769 | 12 | 183,538 |
Yes | output | 1 | 91,769 | 12 | 183,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (i... | instruction | 0 | 91,770 | 12 | 183,540 |
Yes | output | 1 | 91,770 | 12 | 183,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (i... | instruction | 0 | 91,771 | 12 | 183,542 |
Yes | output | 1 | 91,771 | 12 | 183,543 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (i... | instruction | 0 | 91,772 | 12 | 183,544 |
Yes | output | 1 | 91,772 | 12 | 183,545 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (i... | instruction | 0 | 91,773 | 12 | 183,546 |
No | output | 1 | 91,773 | 12 | 183,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (i... | instruction | 0 | 91,774 | 12 | 183,548 |
No | output | 1 | 91,774 | 12 | 183,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (i... | instruction | 0 | 91,775 | 12 | 183,550 |
No | output | 1 | 91,775 | 12 | 183,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (i... | instruction | 0 | 91,776 | 12 | 183,552 |
No | output | 1 | 91,776 | 12 | 183,553 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between... | instruction | 0 | 91,812 | 12 | 183,624 |
Tags: binary search, constructive algorithms, greedy, sortings, ternary search, two pointers
Correct Solution:
```
n,k=map(int,input().split())
b=list(map(int,input().split()))
a=[];dic={}
for i in b:
try:
if dic[i]:
dic[i]+=1
except KeyError:
dic[i]=1
a.append(i)
a.sort()
... | output | 1 | 91,812 | 12 | 183,625 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between... | instruction | 0 | 91,813 | 12 | 183,626 |
Tags: binary search, constructive algorithms, greedy, sortings, ternary search, two pointers
Correct Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._... | output | 1 | 91,813 | 12 | 183,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between... | instruction | 0 | 91,814 | 12 | 183,628 |
Tags: binary search, constructive algorithms, greedy, sortings, ternary search, two pointers
Correct Solution:
```
import sys
input=sys.stdin.readline
import collections
from collections import defaultdict
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
freq=defaultdict(list)
for i in l:
... | output | 1 | 91,814 | 12 | 183,629 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between... | instruction | 0 | 91,815 | 12 | 183,630 |
Tags: binary search, constructive algorithms, greedy, sortings, ternary search, two pointers
Correct Solution:
```
from sys import stdin
input = iter(stdin.buffer.read().decode().splitlines()).__next__
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
left = 1
right = 1
while 1:
if left*... | output | 1 | 91,815 | 12 | 183,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between... | instruction | 0 | 91,816 | 12 | 183,632 |
Tags: binary search, constructive algorithms, greedy, sortings, ternary search, two pointers
Correct Solution:
```
n,k=map(int,input().strip().split())
a =list(map(int,input().strip().split()))
from collections import deque, Counter
temp = Counter(a)
a = deque(sorted(map(lambda x: [x,temp[x]], temp)))
# print(a)
while(... | output | 1 | 91,816 | 12 | 183,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between... | instruction | 0 | 91,817 | 12 | 183,634 |
Tags: binary search, constructive algorithms, greedy, sortings, ternary search, two pointers
Correct Solution:
```
# encoding: utf-8
from sys import stdin
n, k = [int(i) for i in stdin.readline().strip().split()]
a = [int(i) for i in stdin.readline().strip().split()]
a.sort()
i = 0
j = n - 1
a_min = a[i]
a_max = a[j]... | output | 1 | 91,817 | 12 | 183,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between... | instruction | 0 | 91,818 | 12 | 183,636 |
Tags: binary search, constructive algorithms, greedy, sortings, ternary search, two pointers
Correct Solution:
```
import sys
import math
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
l=0
r=n-1
while(l<r and k):
temp=((A[l+1]-A[l])*(l+1)+(A[r]-A[r-1])*(n-r))
if(k>=temp)... | output | 1 | 91,818 | 12 | 183,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between... | instruction | 0 | 91,819 | 12 | 183,638 |
Tags: binary search, constructive algorithms, greedy, sortings, ternary search, two pointers
Correct Solution:
```
import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int,minp().split())
def solve():
n, k = mints()
a = list(mints())
a.sort()
b = [... | output | 1 | 91,819 | 12 | 183,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Ca... | instruction | 0 | 91,822 | 12 | 183,644 |
Yes | output | 1 | 91,822 | 12 | 183,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Ca... | instruction | 0 | 91,825 | 12 | 183,650 |
No | output | 1 | 91,825 | 12 | 183,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Ca... | instruction | 0 | 91,827 | 12 | 183,654 |
No | output | 1 | 91,827 | 12 | 183,655 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ ... | instruction | 0 | 91,860 | 12 | 183,720 |
Tags: bitmasks, combinatorics, math
Correct Solution:
```
for t in range(int(input())):
d,m = [int(i) for i in input().split()]
tot = 0
p = 1
while p<=d:
p *= 2
p //= 2
while d>0:
tot += (d-p+1)*(tot+1)
tot %= m
d = p-1
p //= 2
print(tot)
``` | output | 1 | 91,860 | 12 | 183,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ ... | instruction | 0 | 91,861 | 12 | 183,722 |
Tags: bitmasks, combinatorics, math
Correct Solution:
```
a=[1]
for i in range(30):
a.append(a[-1]*2)
for t in range(int(input())):
d,m=map(int,input().split())
ans=1
z=d.bit_length()
for i in range(z):
if i!=z-1:
ans=(ans*((a[i+1]-1)-a[i]+2))%m
else:
ans=(ans... | output | 1 | 91,861 | 12 | 183,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ ... | instruction | 0 | 91,862 | 12 | 183,724 |
Tags: bitmasks, combinatorics, math
Correct Solution:
```
import sys
input = sys.stdin.readline
t=int(input())
D=[(1<<i)-1 for i in range(1,32)]
for tests in range(t):
d,m=map(int,input().split())
ANS=[1] # answer for 1, 3, 7, 15,
B=[0]
for i in range(1,32):
B.append(ANS[-1]+1)
ANS.... | output | 1 | 91,862 | 12 | 183,725 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ ... | instruction | 0 | 91,863 | 12 | 183,726 |
Tags: bitmasks, combinatorics, math
Correct Solution:
```
for i in range(int(input())):
d, m = map(int, input().split())
a, k, s = [], 1, 1
while s < d:
a.append(k)
k <<= 1
s += k
a.append(d - s + k)
dp = [1]
for j in range(len(a)):
dp.append((a[j] + 1) * dp[-1])
... | output | 1 | 91,863 | 12 | 183,727 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ ... | instruction | 0 | 91,864 | 12 | 183,728 |
Tags: bitmasks, combinatorics, math
Correct Solution:
```
t = int(input())
for _ in range(t):
d, m = map(int, input().split())
a = []
i = 0
while d > (1<<(i+1))-1:
a.append(1<<i)
i += 1
a.append((1<<i) - (1<<(i+1)) + d + 1)
#print(a)
ans = 1
for x in a:
ans *= x+1
ans %= m
print((ans-1)%m)
``` | output | 1 | 91,864 | 12 | 183,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ ... | instruction | 0 | 91,865 | 12 | 183,730 |
Tags: bitmasks, combinatorics, math
Correct Solution:
```
t = int(input())
for _ in range(t):
d, m = map(int, input().split())
a = []
i = 0
while d > (1<<(i+1))-1:
a.append(1<<i)
i += 1
a.append((1<<i) - (1<<(i+1)) + d + 1)
#print(a,(1<<i) - (1<<(i+1)),d+1)
ans = 1
for x in a:
ans *= x+1
ans %= m
#... | output | 1 | 91,865 | 12 | 183,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ ... | instruction | 0 | 91,866 | 12 | 183,732 |
Tags: bitmasks, combinatorics, math
Correct Solution:
```
q = int(input())
for i in range(q):
inp = input().split()
p = int(inp[0])
n = int(inp[1])
e = 1
a = 1
t = 0
while e*2 <= p:
t += e*a
e *= 2
a = t+1
t %= n
t += (p-e+1)*a
t %= n
print(t)
``` | output | 1 | 91,866 | 12 | 183,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ ... | instruction | 0 | 91,867 | 12 | 183,734 |
Tags: bitmasks, combinatorics, math
Correct Solution:
```
arr=[[1,1,1],[2,3,2],[4,11,6],[8,59,30],[16,539,270],[32,9179,4590],[64,302939,151470],[128,19691099,9845550],[256,2540151899,1270075950],[512,652819038299,326409519150],[1024,334896166647899,167448083323950],[2048,343268570814097499,171634285407048750],[4096,70... | output | 1 | 91,867 | 12 | 183,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\... | instruction | 0 | 91,876 | 12 | 183,752 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
from bisect import *
from collections import *
from math import gcd,ceil,sqrt,floor,inf
from heapq import *
from itertools import *
#from operator import add,mul,sub,xor,truediv,floordiv
from functools import *
#----------------------------------------... | output | 1 | 91,876 | 12 | 183,753 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\... | instruction | 0 | 91,877 | 12 | 183,754 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).s... | output | 1 | 91,877 | 12 | 183,755 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\... | instruction | 0 | 91,878 | 12 | 183,756 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import sys
input=sys.stdin.buffer.readline
t=int(input())
for _ in range(t):
n,k=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
arr.append(-1)
arr.append(-1)
if k not in arr:
print("no")
cont... | output | 1 | 91,878 | 12 | 183,757 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\... | instruction | 0 | 91,879 | 12 | 183,758 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
ans = []
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k not in a:
ans.append('no')
continue
if n == 1:
ans.append('yes' if a[0] == k else 'no')
continue
... | output | 1 | 91,879 | 12 | 183,759 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\... | instruction | 0 | 91,880 | 12 | 183,760 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
t = int(input())
for u in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k not in a:
print("no")
continue
if n == 1:
print("yes")
continue
if n == 2:
if (a[0] ... | output | 1 | 91,880 | 12 | 183,761 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\... | instruction | 0 | 91,881 | 12 | 183,762 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import sys
input = sys.stdin.readline
def do2(l):
for i in range(2,len(l) + 1):
if sum(l[i-2:i + 1]) > 0 or sum(l[i-2:i]) > 0:return 1
return 0
for _ in range(int(input())):
n,k = [int(i) for i in input().split()]
l = [int(i) for... | output | 1 | 91,881 | 12 | 183,763 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\... | instruction | 0 | 91,882 | 12 | 183,764 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k not in a:
print("no")
continue
res = False
for i, x in enumerate(a):
... | output | 1 | 91,882 | 12 | 183,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\... | instruction | 0 | 91,883 | 12 | 183,766 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
def ri(): return int(input())
def ria(): return list(map(int, input().split()))
def solve(n, k, a):
flag = False
for i in range(n):
if a[i] < k:
a[i] = 0
elif a[i] > k:
a[i] = 2
else:
... | output | 1 | 91,883 | 12 | 183,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times:
1. choose three integers i, j and x (1 ≤ i, j ≤ n; 0 ≤ x ≤ 10^9);
2. assign a_i := a_i - x... | instruction | 0 | 91,907 | 12 | 183,814 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
ans=[]
if sum(a)%n!=0:
print(-1)
continue
b=sum(a)//n
for i in range(1,n):
if a[i]%(i+1)==0:
ans.append([i+1,1,a[i]/... | output | 1 | 91,907 | 12 | 183,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times:
1. choose three integers i, j and x (1 ≤ i, j ≤ n; 0 ≤ x ≤ 10^9);
2. assign a_i := a_i - x... | instruction | 0 | 91,908 | 12 | 183,816 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def main():
for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
x = sum(arr)
i... | output | 1 | 91,908 | 12 | 183,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times:
1. choose three integers i, j and x (1 ≤ i, j ≤ n; 0 ≤ x ≤ 10^9);
2. assign a_i := a_i - x... | instruction | 0 | 91,909 | 12 | 183,818 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil,pi,sin,cos,acos,atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import in... | output | 1 | 91,909 | 12 | 183,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times:
1. choose three integers i, j and x (1 ≤ i, j ≤ n; 0 ≤ x ≤ 10^9);
2. assign a_i := a_i - x... | instruction | 0 | 91,910 | 12 | 183,820 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import math
t=int(input())
for _ in range(t):
n=int(input())
arr=list(map(int,input().split()))
a=sum(arr)
if a%n!=0:
print(-1)
else:
b=a//n
... | output | 1 | 91,910 | 12 | 183,821 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times:
1. choose three integers i, j and x (1 ≤ i, j ≤ n; 0 ≤ x ≤ 10^9);
2. assign a_i := a_i - x... | instruction | 0 | 91,911 | 12 | 183,822 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import math
import sys
input=sys.stdin.readline
from collections import Counter, defaultdict, deque
def f(n, a):
sa = sum(a)
if sa%n != 0:
return [-1]
stps = 0
#make each a[i] from i = 2 to n equal to multiple of i
#max value to add will b... | output | 1 | 91,911 | 12 | 183,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times:
1. choose three integers i, j and x (1 ≤ i, j ≤ n; 0 ≤ x ≤ 10^9);
2. assign a_i := a_i - x... | instruction | 0 | 91,912 | 12 | 183,824 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
operations = []
def operate(i, j, x, A):
global operations
A[i-1] -= i * x
A[j-1] += i * x
operations.append([i, j, x])
t = int(input())
for _ in range(t):
n = int(input())
A = [int(a) for a in input().split()]
s = sum(A)
... | output | 1 | 91,912 | 12 | 183,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times:
1. choose three integers i, j and x (1 ≤ i, j ≤ n; 0 ≤ x ≤ 10^9);
2. assign a_i := a_i - x... | instruction | 0 | 91,913 | 12 | 183,826 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
mean=sum(a)//n
if sum(a)%n!=0:
print(-1)
else:
print(3*(n-1))
for i in range(1, n):
if a[i]%(i+1)!=0:
... | output | 1 | 91,913 | 12 | 183,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times:
1. choose three integers i, j and x (1 ≤ i, j ≤ n; 0 ≤ x ≤ 10^9);
2. assign a_i := a_i - x... | instruction | 0 | 91,914 | 12 | 183,828 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.m... | output | 1 | 91,914 | 12 | 183,829 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.