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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.
We know that each server takes one second to recompress a one minute fragment. Thus, any server takes m seconds to recompress a m minute video.
We know the time when each of the n videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time s, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video.
For each video find the moment it stops being recompressed.
Input
The first line of the input contains integers n and k (1 β€ n, k β€ 5Β·105) β the number of videos and servers, respectively.
Next n lines contain the descriptions of the videos as pairs of integers si, mi (1 β€ si, mi β€ 109), where si is the time in seconds when the i-th video appeared and mi is its duration in minutes. It is guaranteed that all the si's are distinct and the videos are given in the chronological order of upload, that is in the order of increasing si.
Output
Print n numbers e1, e2, ..., en, where ei is the time in seconds after the servers start working, when the i-th video will be recompressed.
Examples
Input
3 2
1 5
2 5
3 5
Output
6
7
11
Input
6 1
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6 3
Output
1000000001
2000000001
3000000001
4000000001
5000000001
5000000004
Submitted Solution:
```
from sys import stdin, stdout
lines = stdin.readlines()
from random import random
from time import time
"""
n = 500000
k = 33279
lines = [( str(n)+' '+str(k) )]
for i in range(n):
x = int(random()*100000)
y = 1000000000 + int(random()*10000)
lines.append( str(x)+' '+str(y) )
"""
t1 = time()
n, k = int(lines[0].split()[0]), int(lines[0].split()[1])
a = [int(x.split()[0]) for x in lines[1:]]
b = [int(x.split()[1]) for x in lines[1:]]
import heapq
heap = []
#heap = PriorityQueueSet()
free_servers = k
answers = []
#global_minimum = 0
heap = [a[i]+b[i] for i in range(k)]
answers = heap[:]
heapq.heapify(heap)
"""
answers = []
for i in range(k):
will_load = int(a[i]+b[i])
heap.push(will_load, str(will_load))
answers.append(will_load)
"""
for i in range(k,n):
cur_min = int(heapq.heappop(heap))
will_load = int(max(cur_min, a[i])+b[i]) #11111111
heapq.heappush(heap, will_load)
#print(will_load)
answers.append(will_load)
t2 = time()
#print(t2-t1)
stdout.write('\n'.join([str(x) for x in answers]))
``` | instruction | 0 | 81,212 | 14 | 162,424 |
Yes | output | 1 | 81,212 | 14 | 162,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.
We know that each server takes one second to recompress a one minute fragment. Thus, any server takes m seconds to recompress a m minute video.
We know the time when each of the n videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time s, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video.
For each video find the moment it stops being recompressed.
Input
The first line of the input contains integers n and k (1 β€ n, k β€ 5Β·105) β the number of videos and servers, respectively.
Next n lines contain the descriptions of the videos as pairs of integers si, mi (1 β€ si, mi β€ 109), where si is the time in seconds when the i-th video appeared and mi is its duration in minutes. It is guaranteed that all the si's are distinct and the videos are given in the chronological order of upload, that is in the order of increasing si.
Output
Print n numbers e1, e2, ..., en, where ei is the time in seconds after the servers start working, when the i-th video will be recompressed.
Examples
Input
3 2
1 5
2 5
3 5
Output
6
7
11
Input
6 1
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6 3
Output
1000000001
2000000001
3000000001
4000000001
5000000001
5000000004
Submitted Solution:
```
def minVid( mas ):
global minN
global minI
minN = 100000000000
minI = -1
for i in range( len( mas )):
if ms[ i ][ 0 ] <= minN and ms[ i ][ 2 ] == 0:
minN = ms[ i ][ 0 ]
minI = i
return None;
def minServ( mas ):
global notUsed
global minNS
global minIS
minNS = 10000000000
minIS = -1
for i in range( len( mas ) ):
if srv[ i ] <= minN:
minNS = srv[ i ]
minIS = i
return None;
movies, servers = map( int, input( ).split( ) )
ms = [0] * movies
for i in range( movies ):
ms[i] = [0] * 3
srv = [0] * servers
for i in range( movies ):
a, b = map( int, input( ).split( ) )
ms[ i ][ 0 ] = a
ms[ i ][ 1 ] = b
done = [ ]
d = 0
while d < movies:
minVid( ms )
minServ( srv )
ms[minI][2] = ms[minI][0] + ms[minI][1]
if ms[minI][0] <= srv[minIS]:
ms[minI][2] += srv[minIS] - ms[minI][0] + 1
srv[minIS] += ms[minI][1]
done.append( minI )
d += 1
for i in range( movies ):
print (ms[i][2])
``` | instruction | 0 | 81,213 | 14 | 162,426 |
No | output | 1 | 81,213 | 14 | 162,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.
We know that each server takes one second to recompress a one minute fragment. Thus, any server takes m seconds to recompress a m minute video.
We know the time when each of the n videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time s, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video.
For each video find the moment it stops being recompressed.
Input
The first line of the input contains integers n and k (1 β€ n, k β€ 5Β·105) β the number of videos and servers, respectively.
Next n lines contain the descriptions of the videos as pairs of integers si, mi (1 β€ si, mi β€ 109), where si is the time in seconds when the i-th video appeared and mi is its duration in minutes. It is guaranteed that all the si's are distinct and the videos are given in the chronological order of upload, that is in the order of increasing si.
Output
Print n numbers e1, e2, ..., en, where ei is the time in seconds after the servers start working, when the i-th video will be recompressed.
Examples
Input
3 2
1 5
2 5
3 5
Output
6
7
11
Input
6 1
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6 3
Output
1000000001
2000000001
3000000001
4000000001
5000000001
5000000004
Submitted Solution:
```
def notUsed( a, mas ):
for i in range( len(mas) ):
if a == mas[ i ]:
return False
return True
def minVid( mas ):
global notUsed
global minN
global minI
for i in range( len( mas )):
if ms[ i ][ 0 ] <= minN and notUsed( i, done ):
minN = ms[ i ][ 0 ]
minI = i
return None;
def minServ( mas ):
global notUsed
global minNS
global minIS
for i in range( len( mas )):
if srv[ i ] < minN:
minNS = srv[ i ]
minIS = i
return None;
movies, servers = map( int, input( ).split( ) )
ms = [0] * movies
for i in range( movies ):
ms[i] = [0] * 3
srv = [0] * servers
for i in range( movies ):
a, b = map( int, input( ).split( ) )
ms[ i ][ 0 ] = a
ms[ i ][ 1 ] = b
done = [ -1 ]
minN = 10000000000
minI = -1
minNS = 10000000000
minIS = -1
d = 0
k = 0
while d < movies:
minVid( ms )
minServ( srv )
ms[minI][2] = ms[minI][0] + ms[minI][1]
if ms[minI][0] <= srv[minIS]:
ms[minI][2] += srv[minIS] - ms[minI][0] + 1
srv[minIS] += ms[minI][1]
done.append( minI )
d += 1
minN = 10000000000
minI = -1
minNS = 10000000000
minIS = -1
for i in range( movies ):
print (ms[i][2])
``` | instruction | 0 | 81,214 | 14 | 162,428 |
No | output | 1 | 81,214 | 14 | 162,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.
We know that each server takes one second to recompress a one minute fragment. Thus, any server takes m seconds to recompress a m minute video.
We know the time when each of the n videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time s, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video.
For each video find the moment it stops being recompressed.
Input
The first line of the input contains integers n and k (1 β€ n, k β€ 5Β·105) β the number of videos and servers, respectively.
Next n lines contain the descriptions of the videos as pairs of integers si, mi (1 β€ si, mi β€ 109), where si is the time in seconds when the i-th video appeared and mi is its duration in minutes. It is guaranteed that all the si's are distinct and the videos are given in the chronological order of upload, that is in the order of increasing si.
Output
Print n numbers e1, e2, ..., en, where ei is the time in seconds after the servers start working, when the i-th video will be recompressed.
Examples
Input
3 2
1 5
2 5
3 5
Output
6
7
11
Input
6 1
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6 3
Output
1000000001
2000000001
3000000001
4000000001
5000000001
5000000004
Submitted Solution:
```
__author__ = 'ruckus'
n, k = map(int, input().split())
nearest = []
l = k
while l:
s, m = map(int, input().split())
nearest.append(s+m)
print(nearest[len(nearest)-1])
l -= 1
n -= 1
if n <= 0:
break
fl = 0
if n > 0:
nearest.sort()
while n:
s, m = map(int, input().split())
j = (nearest[0] if nearest[0] > s else s) + m
print(j)
for i in range(k-1):
if j <= nearest[i+1]:
nearest[i] = j
fl = 1
break
nearest[i] = nearest[i+1]
if fl == 0:
nearest[len(nearest)-1] = j
n -= 1
``` | instruction | 0 | 81,215 | 14 | 162,430 |
No | output | 1 | 81,215 | 14 | 162,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.
We know that each server takes one second to recompress a one minute fragment. Thus, any server takes m seconds to recompress a m minute video.
We know the time when each of the n videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time s, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video.
For each video find the moment it stops being recompressed.
Input
The first line of the input contains integers n and k (1 β€ n, k β€ 5Β·105) β the number of videos and servers, respectively.
Next n lines contain the descriptions of the videos as pairs of integers si, mi (1 β€ si, mi β€ 109), where si is the time in seconds when the i-th video appeared and mi is its duration in minutes. It is guaranteed that all the si's are distinct and the videos are given in the chronological order of upload, that is in the order of increasing si.
Output
Print n numbers e1, e2, ..., en, where ei is the time in seconds after the servers start working, when the i-th video will be recompressed.
Examples
Input
3 2
1 5
2 5
3 5
Output
6
7
11
Input
6 1
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6 3
Output
1000000001
2000000001
3000000001
4000000001
5000000001
5000000004
Submitted Solution:
```
from collections import deque
n,m=(int(x) for x in input().split(' '))
time=[0]*m
output=[0]*n
flags=[False]*n
que=deque()
p=0
for i in range(n):
t,l=(int(x) for x in input().split(' '))
for j in range(m):
if time[j]>=t-p:
time[j]-=t-p
else:
time[j]=0
for j in range(n):
if not flags[j] and output[j]!=0:
output[j]+=1
if 0 in time and not que:
output[i]=t+l
flags[i]=True
time[time.index(0)]=l
else:
while 0 in time and que:
ind1=time.index(0)
ind2=flags.index(False)
time[ind1]=que.popleft()
output[ind2]+=time[ind1]
flags[ind2]=True
output[i]=t
## for j in range(m):
## if time[j]>=t:
## time[j]-=t
## else:
## time[j]=0
## if 0 in time:
## output[i]+=l
## flags[i]=True
## time[time.index(0)]=l
## else:
que.append(l)
p=t
while False in flags:
time_left=min(time)
for i in range(m):
time[i]-=time_left
for i in range(n):
if not flags[i]:
output[i]+=time_left
while 0 in time and que:
ind1=time.index(0)
ind2=flags.index(False)
time[ind1]=que.popleft()
output[ind2]+=time[ind1]
flags[ind2]=True
for elem in output:
print(elem)
``` | instruction | 0 | 81,216 | 14 | 162,432 |
No | output | 1 | 81,216 | 14 | 162,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps. | instruction | 0 | 81,426 | 14 | 162,852 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
q, q1 = 0, 0
while q < 2*n-1:
if a[q] == a[q+1]:
q += 2
else:
for q2 in range(a[q+1:].index(a[q])+q+1, q+1, -1):
a[q2], a[q2-1] = a[q2-1], a[q2]
q1 += 1
q += 2
print(q1)
``` | output | 1 | 81,426 | 14 | 162,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps. | instruction | 0 | 81,427 | 14 | 162,854 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
arr = list(map(int,input().split()))
i=0
moves = 0
for i in range(0,len(arr)-1,2):
if arr[i]==arr[i+1]:
# i+=2
pass
else:
n_ind = arr[i+1:].index(arr[i])
arr.pop(n_ind+i+1)
arr.insert(i+1,arr[i])
moves += n_ind
# i+=2
print(moves)
``` | output | 1 | 81,427 | 14 | 162,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps. | instruction | 0 | 81,428 | 14 | 162,856 |
Tags: greedy, implementation, math
Correct Solution:
```
def swap(x1, x2, a):
temp = a[x1]
a[x1] = a[x2]
a[x2] = temp
def shift(fr, to, a):
for i in range(fr, to - 1, -1):
swap(i, i-1, a)
n = int(input())
a = [int(x) for x in input().split(' ')]
answer = 0
for i in range(n):
pos1 = 2*i
pos2 = a.index(a[pos1], pos1 + 1)
answer += pos2 - pos1 - 1
shift(pos2, pos1 + 1, a)
print(answer)
``` | output | 1 | 81,428 | 14 | 162,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps. | instruction | 0 | 81,429 | 14 | 162,858 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
ckn = list(map(int, input().split()))
res = 0
# print(ckn)
for p in range(n):
f = ckn.pop(0)
# print(f, ckn)
g_ind = ckn.index(f)
# print(g_ind)
res += g_ind
ckn.pop(g_ind)
# print(g_ind, ckn)
print(res)
``` | output | 1 | 81,429 | 14 | 162,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps. | instruction | 0 | 81,430 | 14 | 162,860 |
Tags: greedy, implementation, math
Correct Solution:
```
#Have copied from eugalt
f = lambda: list(map(int, input().split()))
n = int(input())
a = f()
k = 0
while a:
i = a.index(a.pop(0))
k += i
del a[i]
print(k)
``` | output | 1 | 81,430 | 14 | 162,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps. | instruction | 0 | 81,431 | 14 | 162,862 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
a = [*map(lambda x: int(x) - 1, input().split())]
"""count = [1] * n
real_position = [[] for i in range(n)]
position = [0] * (2 * n)
for i in range(2*n):
position[i] = count[a[i]]
count[a[i]] = -1
real_position[a[i]].append(i)
#print(position)
sum = [i for i in position]
for i in range(1, 2*n):
sum[i] += sum[i - 1]
ans1 = 0
for i in range(n):
ans1 += (sum[real_position[i][1] - 1] - sum[real_position[i][0]])
#ans = -(ans // 2)
#print(ans)
ans = 0
for i in range(n):
ans += (real_position[i][1] - real_position[i][0] - 1)
print(ans - ans1)
"""
ans = 0
f = [True] * n
for i in range(2 * n - 1):
if f[a[i]]:
j = i + 1
while a[j] != a[i]:
if f[a[j]]:
ans += 1
j += 1
f[a[i]] = False
print(ans)
``` | output | 1 | 81,431 | 14 | 162,863 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps. | instruction | 0 | 81,432 | 14 | 162,864 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())*2
a = list(map(int, input().split()))
ans = 0
i = 0
while(i<n-1):
if a[i]!=a[i+1]:
j=i+1
flag=False
while(j<n):
if a[i]==a[j]:
flag=True
break
j+=1
if flag:
temp = a[j]
ans+=(j-(i+1))
a.insert(i+1, temp)
a.pop(j+1)
i+=2
print(ans)
``` | output | 1 | 81,432 | 14 | 162,865 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps. | instruction | 0 | 81,433 | 14 | 162,866 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
c = 0
while len(a) > 0:
x = a[0]
a.remove(x)
c+=a.index(x)
a.remove(x)
print(c)
``` | output | 1 | 81,433 | 14 | 162,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps.
Submitted Solution:
```
def count_inversions(lst):
return merge_count_inversion(lst)[1]
def merge_count_inversion(lst):
if len(lst) <= 1:
return lst, 0
middle = int( len(lst) / 2 )
left, a = merge_count_inversion(lst[:middle])
right, b = merge_count_inversion(lst[middle:])
result, c = merge_count_split_inversion(left, right)
return result, (a + b + c)
def merge_count_split_inversion(left, right):
result = []
count = 0
i, j = 0, 0
left_len = len(left)
while i < left_len and j < len(right):
if left[i] <= right[j]:
result.append(left[i])
i += 1
else:
result.append(right[j])
count += left_len - i
j += 1
result += left[i:]
result += right[j:]
return result, count
def f(n, nums):
sset = dict()
nums2 = []
k = 1
for i in nums:
if i in sset:
nums2.append(sset[i])
else:
nums2.append(k)
sset[i] = k
k += 1
return count_inversions(nums2)
n = int(input())
queues = [int(i) for i in input().split()]
print(f(n, queues))
``` | instruction | 0 | 81,434 | 14 | 162,868 |
Yes | output | 1 | 81,434 | 14 | 162,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps.
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
c = 0
for i in range(n):
if arr[0] != arr[1]:
index = arr[::-1].index(arr[0])
c += (len(arr)-1-index) - 1
del arr[len(arr)-1-index]
del arr[0]
else:
del arr[0]
del arr[0]
print(c)
``` | instruction | 0 | 81,435 | 14 | 162,870 |
Yes | output | 1 | 81,435 | 14 | 162,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps.
Submitted Solution:
```
#
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import math
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
try :
import numpy
dprint = print
dprint('debug mode')
except ModuleNotFoundError:
def dprint(*args, **kwargs):
pass
def makePair(z):
return [(z[i], z[i+1]) for i in range(0,len(z),2) ]
def memo(func):
cache={}
def wrap(*args):
if args not in cache:
cache[args]=func(*args)
return cache[args]
return wrap
@memo
def comb (n,k):
if k==0: return 1
if n==k: return 1
return comb(n-1,k-1) + comb(n-1,k)
N, = getIntList()
za = getIntList()
res = 0
for i in range(0,2*N , 2):
if za[0] == za[1]:
za = za[2:]
continue
g = za[0]
dprint(g)
t = za.index(g, 1)
res += t-1
za.remove(g)
za.remove(g)
dprint(za)
print(res)
``` | instruction | 0 | 81,436 | 14 | 162,872 |
Yes | output | 1 | 81,436 | 14 | 162,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps.
Submitted Solution:
```
n = int(input())
line = list(map(int, input().split(' ')))
st = {}
ed = {}
for x in range(2*n):
if line[x] in st:
ed[line[x]] = x
else:
st[line[x]] = x
ans = 0
for x in range(1, n+1):
for y in range(x+1, n+1):
u, v = x, y
if st[x] > st[y]:
u, v = v, u
if ed[v] < ed[u]:
ans = ans+2
elif st[v] < ed[u]:
ans = ans+1
print(ans)
``` | instruction | 0 | 81,437 | 14 | 162,874 |
Yes | output | 1 | 81,437 | 14 | 162,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps.
Submitted Solution:
```
n=int(input())
a=[int(x) for x in input().split()]
ans =0
for i in range(0, 2*n, 2):
for j in range(i+1,2*n):
if a[i] == a[j]:
for k in range(j-1,i+1):
t=a[k]
a[k]=a[k+1]
a[k+1]=t
ans+=1
break
print(ans)
``` | instruction | 0 | 81,438 | 14 | 162,876 |
No | output | 1 | 81,438 | 14 | 162,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps.
Submitted Solution:
```
from collections import defaultdict
n=int(input())
a=[int(x) for x in input().split()]
z=defaultdict(list)
for i in range(2*n):
z[a[i]].append(i)
an=0
for i in range(0,n-1,2):
if a[i]!=a[i+1]:
for j in range(z[a[i]][1],i+1,-1):
a[j],a[j-1]=a[j-1],a[j]
an+=1
print(an)
``` | instruction | 0 | 81,439 | 14 | 162,878 |
No | output | 1 | 81,439 | 14 | 162,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=a[::]
b.sort()
c = 0
for i in range(2*n):
if a[i]!=b[i]:
x=b.index(a[i])
if a[x]==a[i]:
a[x+1],a[i]=a[i],a[x+1]
c+=1
else:
a[x],a[i]=a[i],a[x]
c+=1
if c==0:
print(c)
else:
print(c+1)
``` | instruction | 0 | 81,440 | 14 | 162,880 |
No | output | 1 | 81,440 | 14 | 162,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.
Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.
Input
The first line contains a single integer n (1 β€ n β€ 100), the number of pairs of people.
The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 β€ i β€ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.
Output
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
Examples
Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3
Note
In the first sample case, we can transform 1 1 2 3 3 2 4 4 β 1 1 2 3 2 3 4 4 β 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 β 1 1 3 2 3 2 4 4 β 1 1 3 3 2 2 4 4 also works in the same number of steps.
The second sample case already satisfies the constraints; therefore we need 0 swaps.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
d={}
for j,i in enumerate(l):
if i in d:
d[i].append(j)
else:
d[i]=[j]
def change(w,i,val):
if d[w][0]==i:
d[w][0]+=val
return
d[w][1]+=val
def isdone():
global n
for i in range(n):
if l[2*i]!=l[2*i+1]:
return False
return True
i=0
m=0
while True:
if i>=n:
break
if l[i]!=l[i+1]:
ind=max(d[l[i]])
for j in range(ind,i+1,-1):
l[j],l[j-1]=l[j-1],l[j]
change(l[j-1],j,-1)
change(l[j],j-1,1)
m+=1
i+=2
print(m)
``` | instruction | 0 | 81,441 | 14 | 162,882 |
No | output | 1 | 81,441 | 14 | 162,883 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers.
The work material for the wreaths for all n citizens of Shortriver is cut from the longest flowered liana that grew in the town that year. Liana is a sequence a_1, a_2, ..., a_m, where a_i is an integer that denotes the type of flower at the position i. This year the liana is very long (m β₯ n β
k), and that means every citizen will get a wreath.
Very soon the liana will be inserted into a special cutting machine in order to make work material for wreaths. The machine works in a simple manner: it cuts k flowers from the beginning of the liana, then another k flowers and so on. Each such piece of k flowers is called a workpiece. The machine works until there are less than k flowers on the liana.
Diana has found a weaving schematic for the most beautiful wreath imaginable. In order to weave it, k flowers must contain flowers of types b_1, b_2, ..., b_s, while other can be of any type. If a type appears in this sequence several times, there should be at least that many flowers of that type as the number of occurrences of this flower in the sequence. The order of the flowers in a workpiece does not matter.
Diana has a chance to remove some flowers from the liana before it is inserted into the cutting machine. She can remove flowers from any part of the liana without breaking liana into pieces. If Diana removes too many flowers, it may happen so that some of the citizens do not get a wreath. Could some flowers be removed from the liana so that at least one workpiece would conform to the schematic and machine would still be able to create at least n workpieces?
Input
The first line contains four integers m, k, n and s (1 β€ n, k, m β€ 5 β
10^5, k β
n β€ m, 1 β€ s β€ k): the number of flowers on the liana, the number of flowers in one wreath, the amount of citizens and the length of Diana's flower sequence respectively.
The second line contains m integers a_1, a_2, ..., a_m (1 β€ a_i β€ 5 β
10^5) β types of flowers on the liana.
The third line contains s integers b_1, b_2, ..., b_s (1 β€ b_i β€ 5 β
10^5) β the sequence in Diana's schematic.
Output
If it's impossible to remove some of the flowers so that there would be at least n workpieces and at least one of them fullfills Diana's schematic requirements, output -1.
Otherwise in the first line output one integer d β the number of flowers to be removed by Diana.
In the next line output d different integers β the positions of the flowers to be removed.
If there are multiple answers, print any.
Examples
Input
7 3 2 2
1 2 3 3 2 1 2
2 2
Output
1
4
Input
13 4 3 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
-1
Input
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
9
1 2 3 4 5 9 11 12 13
Note
In the first example, if you don't remove any flowers, the machine would put out two workpieces with flower types [1, 2, 3] and [3, 2, 1]. Those workpieces don't fit Diana's schematic. But if you remove flower on 4-th place, the machine would output workpieces [1, 2, 3] and [2, 1, 2]. The second workpiece fits Diana's schematic.
In the second example there is no way to remove flowers so that every citizen gets a wreath and Diana gets a workpiece that fits here schematic.
In the third example Diana is the only citizen of the town and that means she can, for example, just remove all flowers except the ones she needs. | instruction | 0 | 81,769 | 14 | 163,538 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# import string
# characters = string.ascii_lowercase
# digits = string.digits
# setrecursionlimit(int(1e6))
# dir = [-1,0,1,0,-1]
# moves = 'NESW'
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt
def geti(): return map(int, input().strip().split())
def getl(): return list(map(int, input().strip().split()))
def getis(): return map(str, input().strip().split())
def getls(): return list(map(str, input().strip().split()))
def gets(): return input().strip()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')
def solve():
m, k, n, s = geti()
a = getl()
s = Counter(getl())
length = k + m - n * k
val = sum(s.values())
occur = dd(int)
ok = 0
i = 0
done = 0
start = 0
# print(length)
while i < m:
while done != length and i < m:
occur[a[i]] += 1
if occur[a[i]] == s[a[i]]:
ok += 1
done += 1
i += 1
# print(done, start, ok)
if ok == len(s):
res = []
need = length - k
for j in range(start, start + length):
if not need:
break
if occur[a[j]] > s[a[j]]:
occur[a[j]] -= 1
res.append(j+1)
need -= 1
print(len(res))
print(*res)
break
else:
waste = k
while waste:
if occur[a[start]] == s[a[start]]:
ok -= 1
occur[a[start]] -= 1
waste -= 1
start += 1
done -= 1
else:
print(-1)
# def check(length):
# occur = dd(int)
# ok = 0
# prev = 0
# start = m-1
# for i in range(m):
# if a[i] in s:
# start = i
# break
# prev += 1
# prev %= k
# for i in range(start, m):
# occur[a[i]] += 1
# if occur[a[i]] == s[a[i]]:
# ok += 1
# if ok == len(s):
# # print(start, prev, i)
# total = i - start + 1
# to_rem = total - k + prev
# if to_rem <= 0:
# return []
# if to_rem <= length:
# res = []
# for j in range(start-1, -1, -1):
# if prev:
# res.append(j + 1)
# prev -= 1
# to_rem -= 1
# else:
# break
# for j in range(start, i):
# if occur[a[j]] > s[a[j]]:
# res.append(j + 1)
# to_rem -= 1
# if not to_rem:
# break
# return res
# else:
# while start < i:
# occur[a[start]] -= 1
# prev += 1
# prev %= k
# start += 1
# if a[start-1] in s and occur[a[start-1]] < s[a[start-1]]:
# ok -= 1
# if a[start] in s:
# break
# # print(a[start:])
# # print(Counter(a[start:]))
# # print(s)
# return -1
#
# res = check(length)
# if res == -1:
# print(res)
# else:
# print(len(res))
# if res:
# print(*res)
if __name__=='__main__':
solve()
``` | output | 1 | 81,769 | 14 | 163,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers.
The work material for the wreaths for all n citizens of Shortriver is cut from the longest flowered liana that grew in the town that year. Liana is a sequence a_1, a_2, ..., a_m, where a_i is an integer that denotes the type of flower at the position i. This year the liana is very long (m β₯ n β
k), and that means every citizen will get a wreath.
Very soon the liana will be inserted into a special cutting machine in order to make work material for wreaths. The machine works in a simple manner: it cuts k flowers from the beginning of the liana, then another k flowers and so on. Each such piece of k flowers is called a workpiece. The machine works until there are less than k flowers on the liana.
Diana has found a weaving schematic for the most beautiful wreath imaginable. In order to weave it, k flowers must contain flowers of types b_1, b_2, ..., b_s, while other can be of any type. If a type appears in this sequence several times, there should be at least that many flowers of that type as the number of occurrences of this flower in the sequence. The order of the flowers in a workpiece does not matter.
Diana has a chance to remove some flowers from the liana before it is inserted into the cutting machine. She can remove flowers from any part of the liana without breaking liana into pieces. If Diana removes too many flowers, it may happen so that some of the citizens do not get a wreath. Could some flowers be removed from the liana so that at least one workpiece would conform to the schematic and machine would still be able to create at least n workpieces?
Input
The first line contains four integers m, k, n and s (1 β€ n, k, m β€ 5 β
10^5, k β
n β€ m, 1 β€ s β€ k): the number of flowers on the liana, the number of flowers in one wreath, the amount of citizens and the length of Diana's flower sequence respectively.
The second line contains m integers a_1, a_2, ..., a_m (1 β€ a_i β€ 5 β
10^5) β types of flowers on the liana.
The third line contains s integers b_1, b_2, ..., b_s (1 β€ b_i β€ 5 β
10^5) β the sequence in Diana's schematic.
Output
If it's impossible to remove some of the flowers so that there would be at least n workpieces and at least one of them fullfills Diana's schematic requirements, output -1.
Otherwise in the first line output one integer d β the number of flowers to be removed by Diana.
In the next line output d different integers β the positions of the flowers to be removed.
If there are multiple answers, print any.
Examples
Input
7 3 2 2
1 2 3 3 2 1 2
2 2
Output
1
4
Input
13 4 3 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
-1
Input
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
9
1 2 3 4 5 9 11 12 13
Note
In the first example, if you don't remove any flowers, the machine would put out two workpieces with flower types [1, 2, 3] and [3, 2, 1]. Those workpieces don't fit Diana's schematic. But if you remove flower on 4-th place, the machine would output workpieces [1, 2, 3] and [2, 1, 2]. The second workpiece fits Diana's schematic.
In the second example there is no way to remove flowers so that every citizen gets a wreath and Diana gets a workpiece that fits here schematic.
In the third example Diana is the only citizen of the town and that means she can, for example, just remove all flowers except the ones she needs. | instruction | 0 | 81,770 | 14 | 163,540 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
import sys
from collections import Counter
input = sys.stdin.buffer.readline
m,k,n,s = map(int,input().split())
a = list(map(int,input().split()))
b = Counter(map(int,input().split()))
counts = Counter()
unsatisfied = len(b)
to_remove = m+1
mn_len = m+1
remove_idx = -1
j = 0
for i in range(m):
while j < m and unsatisfied != 0:
counts[a[j]] += 1
if counts[a[j]] == b[a[j]]:
unsatisfied -= 1
j += 1
if unsatisfied == 0:
curr_remove = i % k + max(0, j - i - k)
if curr_remove < to_remove:
to_remove = curr_remove
mn_len = j - i
remove_idx = i
if counts[a[i]] == b[a[i]]:
unsatisfied += 1
counts[a[i]] -= 1
if m - to_remove < n*k:
print(-1)
else:
print(to_remove)
indexes = {}
for i in range(remove_idx,remove_idx + mn_len):
if a[i] in indexes:
indexes[a[i]].append(i+1)
else:
indexes[a[i]] = [i+1]
removed = list(range(1,remove_idx % k + 1))
to_remove -= remove_idx % k
for i in indexes:
if to_remove == 0:
break
else:
removed.extend(indexes[i][:min(len(indexes[i]) - b[i],to_remove)])
to_remove -= min(len(indexes[i]) - b[i],to_remove)
print(*removed)
``` | output | 1 | 81,770 | 14 | 163,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers.
The work material for the wreaths for all n citizens of Shortriver is cut from the longest flowered liana that grew in the town that year. Liana is a sequence a_1, a_2, ..., a_m, where a_i is an integer that denotes the type of flower at the position i. This year the liana is very long (m β₯ n β
k), and that means every citizen will get a wreath.
Very soon the liana will be inserted into a special cutting machine in order to make work material for wreaths. The machine works in a simple manner: it cuts k flowers from the beginning of the liana, then another k flowers and so on. Each such piece of k flowers is called a workpiece. The machine works until there are less than k flowers on the liana.
Diana has found a weaving schematic for the most beautiful wreath imaginable. In order to weave it, k flowers must contain flowers of types b_1, b_2, ..., b_s, while other can be of any type. If a type appears in this sequence several times, there should be at least that many flowers of that type as the number of occurrences of this flower in the sequence. The order of the flowers in a workpiece does not matter.
Diana has a chance to remove some flowers from the liana before it is inserted into the cutting machine. She can remove flowers from any part of the liana without breaking liana into pieces. If Diana removes too many flowers, it may happen so that some of the citizens do not get a wreath. Could some flowers be removed from the liana so that at least one workpiece would conform to the schematic and machine would still be able to create at least n workpieces?
Input
The first line contains four integers m, k, n and s (1 β€ n, k, m β€ 5 β
10^5, k β
n β€ m, 1 β€ s β€ k): the number of flowers on the liana, the number of flowers in one wreath, the amount of citizens and the length of Diana's flower sequence respectively.
The second line contains m integers a_1, a_2, ..., a_m (1 β€ a_i β€ 5 β
10^5) β types of flowers on the liana.
The third line contains s integers b_1, b_2, ..., b_s (1 β€ b_i β€ 5 β
10^5) β the sequence in Diana's schematic.
Output
If it's impossible to remove some of the flowers so that there would be at least n workpieces and at least one of them fullfills Diana's schematic requirements, output -1.
Otherwise in the first line output one integer d β the number of flowers to be removed by Diana.
In the next line output d different integers β the positions of the flowers to be removed.
If there are multiple answers, print any.
Examples
Input
7 3 2 2
1 2 3 3 2 1 2
2 2
Output
1
4
Input
13 4 3 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
-1
Input
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
9
1 2 3 4 5 9 11 12 13
Note
In the first example, if you don't remove any flowers, the machine would put out two workpieces with flower types [1, 2, 3] and [3, 2, 1]. Those workpieces don't fit Diana's schematic. But if you remove flower on 4-th place, the machine would output workpieces [1, 2, 3] and [2, 1, 2]. The second workpiece fits Diana's schematic.
In the second example there is no way to remove flowers so that every citizen gets a wreath and Diana gets a workpiece that fits here schematic.
In the third example Diana is the only citizen of the town and that means she can, for example, just remove all flowers except the ones she needs.
Submitted Solution:
```
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# import string
# characters = string.ascii_lowercase
# digits = string.digits
# setrecursionlimit(int(1e6))
# dir = [-1,0,1,0,-1]
# moves = 'NESW'
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt
def geti(): return map(int, input().strip().split())
def getl(): return list(map(int, input().strip().split()))
def getis(): return map(str, input().strip().split())
def getls(): return list(map(str, input().strip().split()))
def gets(): return input().strip()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')
def solve():
m, k, n, s = geti()
a = getl()
s = Counter(getl())
length = k + m - n * k
val = sum(s.values())
occur = dd(int)
ok = 0
i = 0
done = 0
start = 0
# print(length)
while i < m:
while done != length and i < m:
occur[a[i]] += 1
if occur[a[i]] == s[a[i]]:
ok += 1
done += 1
i += 1
# print(done, start, ok)
if ok == len(s):
res = []
need = length - k
for j in range(start, start + length):
if occur[a[j]] > s[a[j]]:
occur[a[j]] -= 1
res.append(j+1)
need -= 1
if not need:
break
print(len(res))
print(*res)
break
else:
waste = k
while waste:
if occur[a[start]] == s[a[start]]:
ok -= 1
occur[a[start]] -= 1
waste -= 1
start += 1
done -= 1
else:
print(-1)
# def check(length):
# occur = dd(int)
# ok = 0
# prev = 0
# start = m-1
# for i in range(m):
# if a[i] in s:
# start = i
# break
# prev += 1
# prev %= k
# for i in range(start, m):
# occur[a[i]] += 1
# if occur[a[i]] == s[a[i]]:
# ok += 1
# if ok == len(s):
# # print(start, prev, i)
# total = i - start + 1
# to_rem = total - k + prev
# if to_rem <= 0:
# return []
# if to_rem <= length:
# res = []
# for j in range(start-1, -1, -1):
# if prev:
# res.append(j + 1)
# prev -= 1
# to_rem -= 1
# else:
# break
# for j in range(start, i):
# if occur[a[j]] > s[a[j]]:
# res.append(j + 1)
# to_rem -= 1
# if not to_rem:
# break
# return res
# else:
# while start < i:
# occur[a[start]] -= 1
# prev += 1
# prev %= k
# start += 1
# if a[start-1] in s and occur[a[start-1]] < s[a[start-1]]:
# ok -= 1
# if a[start] in s:
# break
# # print(a[start:])
# # print(Counter(a[start:]))
# # print(s)
# return -1
#
# res = check(length)
# if res == -1:
# print(res)
# else:
# print(len(res))
# if res:
# print(*res)
if __name__=='__main__':
solve()
``` | instruction | 0 | 81,771 | 14 | 163,542 |
No | output | 1 | 81,771 | 14 | 163,543 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers.
The work material for the wreaths for all n citizens of Shortriver is cut from the longest flowered liana that grew in the town that year. Liana is a sequence a_1, a_2, ..., a_m, where a_i is an integer that denotes the type of flower at the position i. This year the liana is very long (m β₯ n β
k), and that means every citizen will get a wreath.
Very soon the liana will be inserted into a special cutting machine in order to make work material for wreaths. The machine works in a simple manner: it cuts k flowers from the beginning of the liana, then another k flowers and so on. Each such piece of k flowers is called a workpiece. The machine works until there are less than k flowers on the liana.
Diana has found a weaving schematic for the most beautiful wreath imaginable. In order to weave it, k flowers must contain flowers of types b_1, b_2, ..., b_s, while other can be of any type. If a type appears in this sequence several times, there should be at least that many flowers of that type as the number of occurrences of this flower in the sequence. The order of the flowers in a workpiece does not matter.
Diana has a chance to remove some flowers from the liana before it is inserted into the cutting machine. She can remove flowers from any part of the liana without breaking liana into pieces. If Diana removes too many flowers, it may happen so that some of the citizens do not get a wreath. Could some flowers be removed from the liana so that at least one workpiece would conform to the schematic and machine would still be able to create at least n workpieces?
Input
The first line contains four integers m, k, n and s (1 β€ n, k, m β€ 5 β
10^5, k β
n β€ m, 1 β€ s β€ k): the number of flowers on the liana, the number of flowers in one wreath, the amount of citizens and the length of Diana's flower sequence respectively.
The second line contains m integers a_1, a_2, ..., a_m (1 β€ a_i β€ 5 β
10^5) β types of flowers on the liana.
The third line contains s integers b_1, b_2, ..., b_s (1 β€ b_i β€ 5 β
10^5) β the sequence in Diana's schematic.
Output
If it's impossible to remove some of the flowers so that there would be at least n workpieces and at least one of them fullfills Diana's schematic requirements, output -1.
Otherwise in the first line output one integer d β the number of flowers to be removed by Diana.
In the next line output d different integers β the positions of the flowers to be removed.
If there are multiple answers, print any.
Examples
Input
7 3 2 2
1 2 3 3 2 1 2
2 2
Output
1
4
Input
13 4 3 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
-1
Input
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
9
1 2 3 4 5 9 11 12 13
Note
In the first example, if you don't remove any flowers, the machine would put out two workpieces with flower types [1, 2, 3] and [3, 2, 1]. Those workpieces don't fit Diana's schematic. But if you remove flower on 4-th place, the machine would output workpieces [1, 2, 3] and [2, 1, 2]. The second workpiece fits Diana's schematic.
In the second example there is no way to remove flowers so that every citizen gets a wreath and Diana gets a workpiece that fits here schematic.
In the third example Diana is the only citizen of the town and that means she can, for example, just remove all flowers except the ones she needs.
Submitted Solution:
```
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# import string
# characters = string.ascii_lowercase
# digits = string.digits
# setrecursionlimit(int(1e6))
# dir = [-1,0,1,0,-1]
# moves = 'NESW'
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt
def geti(): return map(int, input().strip().split())
def getl(): return list(map(int, input().strip().split()))
def getis(): return map(str, input().strip().split())
def getls(): return list(map(str, input().strip().split()))
def gets(): return input().strip()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')
def solve():
m, k, n, s = geti()
a = getl()
s = Counter(getl())
length = m - n * k
val = sum(s.values())
def check(length):
occur = dd(int)
ok = 0
prev = 0
start = m-1
for i in range(m):
if a[i] in s:
start = i
break
for i in range(start, m):
occur[a[i]] += 1
if occur[a[i]] == s[a[i]]:
ok += 1
if ok == len(s):
# print(start, prev, i)
total = i - start + 1
if total <= k:
return []
to_rem = total - k + prev
if to_rem <= length:
res = []
for j in range(start-1, -1, -1):
if prev:
res.append(j + 1)
prev -= 1
to_rem -= 1
else:
break
for j in range(start, i):
if occur[a[j]] > s[a[j]]:
res.append(j + 1)
to_rem -= 1
if not to_rem:
break
return res
else:
while start < i:
occur[a[start]] -= 1
prev += 1
prev %= k
start += 1
if a[start-1] in s and occur[a[start-1]] < s[a[start-1]]:
ok -= 1
break
return -1
res = check(length)
if res == -1:
print(res)
else:
print(len(res))
if res:
print(*res)
if __name__=='__main__':
solve()
``` | instruction | 0 | 81,772 | 14 | 163,544 |
No | output | 1 | 81,772 | 14 | 163,545 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers.
The work material for the wreaths for all n citizens of Shortriver is cut from the longest flowered liana that grew in the town that year. Liana is a sequence a_1, a_2, ..., a_m, where a_i is an integer that denotes the type of flower at the position i. This year the liana is very long (m β₯ n β
k), and that means every citizen will get a wreath.
Very soon the liana will be inserted into a special cutting machine in order to make work material for wreaths. The machine works in a simple manner: it cuts k flowers from the beginning of the liana, then another k flowers and so on. Each such piece of k flowers is called a workpiece. The machine works until there are less than k flowers on the liana.
Diana has found a weaving schematic for the most beautiful wreath imaginable. In order to weave it, k flowers must contain flowers of types b_1, b_2, ..., b_s, while other can be of any type. If a type appears in this sequence several times, there should be at least that many flowers of that type as the number of occurrences of this flower in the sequence. The order of the flowers in a workpiece does not matter.
Diana has a chance to remove some flowers from the liana before it is inserted into the cutting machine. She can remove flowers from any part of the liana without breaking liana into pieces. If Diana removes too many flowers, it may happen so that some of the citizens do not get a wreath. Could some flowers be removed from the liana so that at least one workpiece would conform to the schematic and machine would still be able to create at least n workpieces?
Input
The first line contains four integers m, k, n and s (1 β€ n, k, m β€ 5 β
10^5, k β
n β€ m, 1 β€ s β€ k): the number of flowers on the liana, the number of flowers in one wreath, the amount of citizens and the length of Diana's flower sequence respectively.
The second line contains m integers a_1, a_2, ..., a_m (1 β€ a_i β€ 5 β
10^5) β types of flowers on the liana.
The third line contains s integers b_1, b_2, ..., b_s (1 β€ b_i β€ 5 β
10^5) β the sequence in Diana's schematic.
Output
If it's impossible to remove some of the flowers so that there would be at least n workpieces and at least one of them fullfills Diana's schematic requirements, output -1.
Otherwise in the first line output one integer d β the number of flowers to be removed by Diana.
In the next line output d different integers β the positions of the flowers to be removed.
If there are multiple answers, print any.
Examples
Input
7 3 2 2
1 2 3 3 2 1 2
2 2
Output
1
4
Input
13 4 3 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
-1
Input
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
9
1 2 3 4 5 9 11 12 13
Note
In the first example, if you don't remove any flowers, the machine would put out two workpieces with flower types [1, 2, 3] and [3, 2, 1]. Those workpieces don't fit Diana's schematic. But if you remove flower on 4-th place, the machine would output workpieces [1, 2, 3] and [2, 1, 2]. The second workpiece fits Diana's schematic.
In the second example there is no way to remove flowers so that every citizen gets a wreath and Diana gets a workpiece that fits here schematic.
In the third example Diana is the only citizen of the town and that means she can, for example, just remove all flowers except the ones she needs.
Submitted Solution:
```
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# import string
# characters = string.ascii_lowercase
# digits = string.digits
# setrecursionlimit(int(1e6))
# dir = [-1,0,1,0,-1]
# moves = 'NESW'
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt
def geti(): return map(int, input().strip().split())
def getl(): return list(map(int, input().strip().split()))
def getis(): return map(str, input().strip().split())
def getls(): return list(map(str, input().strip().split()))
def gets(): return input().strip()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')
def solve():
m, k, n, s = geti()
a = getl()
s = Counter(getl())
length = k + m - n * k
val = sum(s.values())
occur = dd(int)
ok = 0
i = 0
done = 0
start = 0
# print(length)
while i < m:
while done != length and i < m:
occur[a[i]] += 1
if occur[a[i]] == s[a[i]]:
ok += 1
done += 1
i += 1
# print(done, starst, ok)
if ok == len(s):
res = []
need = length - k
for j in range(start, start + length):
if occur[a[j]] > s[a[j]]:
res.append(j+1)
need -= 1
if not need:
break
print(len(res))
print(*res)
break
else:
waste = k
while waste:
if occur[a[start]] == s[a[start]]:
ok -= 1
occur[a[start]] -= 1
waste -= 1
start += 1
done -= 1
else:
print(-1)
# def check(length):
# occur = dd(int)
# ok = 0
# prev = 0
# start = m-1
# for i in range(m):
# if a[i] in s:
# start = i
# break
# prev += 1
# prev %= k
# for i in range(start, m):
# occur[a[i]] += 1
# if occur[a[i]] == s[a[i]]:
# ok += 1
# if ok == len(s):
# # print(start, prev, i)
# total = i - start + 1
# to_rem = total - k + prev
# if to_rem <= 0:
# return []
# if to_rem <= length:
# res = []
# for j in range(start-1, -1, -1):
# if prev:
# res.append(j + 1)
# prev -= 1
# to_rem -= 1
# else:
# break
# for j in range(start, i):
# if occur[a[j]] > s[a[j]]:
# res.append(j + 1)
# to_rem -= 1
# if not to_rem:
# break
# return res
# else:
# while start < i:
# occur[a[start]] -= 1
# prev += 1
# prev %= k
# start += 1
# if a[start-1] in s and occur[a[start-1]] < s[a[start-1]]:
# ok -= 1
# if a[start] in s:
# break
# # print(a[start:])
# # print(Counter(a[start:]))
# # print(s)
# return -1
#
# res = check(length)
# if res == -1:
# print(res)
# else:
# print(len(res))
# if res:
# print(*res)
if __name__=='__main__':
solve()
``` | instruction | 0 | 81,773 | 14 | 163,546 |
No | output | 1 | 81,773 | 14 | 163,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I know for sure that either x or y did it!'
The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at least p of n coders agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?
Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting.
Input
The first line contains integers n and p (3 β€ n β€ 3Β·105; 0 β€ p β€ n) β the number of coders in the F company and the minimum number of agreed people.
Each of the next n lines contains two integers xi, yi (1 β€ xi, yi β€ n) β the numbers of coders named by the i-th coder. It is guaranteed that xi β i, yi β i, xi β yi.
Output
Print a single integer ββ the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets (1, 2) ΠΈ (2, 1) are considered identical.
Examples
Input
4 2
2 3
1 4
1 4
2 1
Output
6
Input
8 6
5 6
5 7
5 8
6 2
2 1
7 3
1 3
1 4
Output
1 | instruction | 0 | 82,063 | 14 | 164,126 |
Tags: data structures, graphs, implementation, two pointers
Correct Solution:
```
from collections import defaultdict
from bisect import bisect_left as lower
import sys
input = sys.stdin.readline
def put():
return map(int, input().split())
try:
n,m = put()
cnt, mp, ans = [0]*n, defaultdict(), [0]*n
for _ in range(n):
x,y = put()
x,y = x-1,y-1
key = (min(x,y), max(x,y))
if key in mp:
mp[key]+=1
else:
mp[key]=1
cnt[x]+=1
cnt[y]+=1
except:
print('lol')
for (x,y),val in mp.items():
if cnt[x]+cnt[y]>= m and cnt[x]+cnt[y]-val<m:
ans[x]-=1
ans[y]-=1
scnt = cnt.copy()
scnt.sort()
for i in range(n):
ans[i]+= n-lower(scnt, m-cnt[i])
if 2*cnt[i]>=m:
ans[i]-=1
print(sum(ans)//2)
``` | output | 1 | 82,063 | 14 | 164,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment. | instruction | 0 | 82,113 | 14 | 164,226 |
Tags: brute force, dsu, meet-in-the-middle, number theory
Correct Solution:
```
import math
inp = input()
mas = [int(s) for s in inp.strip().split(' ')]
b = mas[0]
g = mas[1]
mas = [int(s) for s in input().strip().split(' ')]
hb = {}
if mas[0] != 0:
for i in mas[1::]:
hb[i] = True
mas = [int(s) for s in input().strip().split(' ')]
hg = {}
if mas[0] != 0:
for i in mas[1::]:
hg[i] = True
for i in range(10013):
bi = i % b
gi = i % g
if bi in hb or gi in hg:
hb[bi] = True
hg[gi] = True
allHappy = True
for i in range(b):
if not(i in hb):
allHappy = False
break
if allHappy is True:
for i in range(g):
if not(i in hg):
allHappy = False
break
if allHappy is True:
print('Yes')
else:
print('No')
``` | output | 1 | 82,113 | 14 | 164,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment. | instruction | 0 | 82,114 | 14 | 164,228 |
Tags: brute force, dsu, meet-in-the-middle, number theory
Correct Solution:
```
n, m = map(int, input().split())
boy_funny = list(map(int, input().split()))
girl_funny = list(map(int, input().split()))
boy = [0]*n
girl = [0]*m
i = 1
while boy_funny[0] > 0:
boy[boy_funny[i]] = 1
i += 1
boy_funny[0] -= 1
i = 1
while girl_funny[0] > 0:
girl[girl_funny[i]] = 1
i += 1
girl_funny[0] -= 1
i = 1
i1 = 0
i2 = 0
boy[0] = boy[0] or girl[0]
girl[0] = boy[0]
while i % n != 0 or i % m != 0:
i1 = i % n
i2 = i % m
boy[i1] = boy[i1] or girl[i2]
girl[i2] = boy[i1]
i += 1
i = 1
i1 = 0
i2 = 0
boy[0] = boy[0] or girl[0]
girl[0] = boy[0]
while i % n != 0 or i % m != 0:
i1 = i % n
i2 = i % m
boy[i1] = boy[i1] or girl[i2]
girl[i2] = boy[i1]
i += 1
error = 0
for i in boy:
if i == 0:
error = 1
break
for i in girl:
if i == 0:
error = 1
break
if error == 0:
print("YES")
else:
print("NO")
``` | output | 1 | 82,114 | 14 | 164,229 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment. | instruction | 0 | 82,115 | 14 | 164,230 |
Tags: brute force, dsu, meet-in-the-middle, number theory
Correct Solution:
```
n,m=(int(i) for i in input().split())
k=max(n,m)
l=[0]*n
l1=[0]*m
l2=[int(i) for i in input().split()]
l3=[int(i) for i in input().split()]
for i in l2[1:]:
l[i]=-1
for i in l3[1:]:
l1[i]=-1
for i in range(n*m):
if(l[i%n]==-1 or l1[i%m]==-1):
l[i%n],l1[i%m]=-1,-1
if(0 in l and 0 in l1):
print("No")
else:
print("Yes")
``` | output | 1 | 82,115 | 14 | 164,231 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment. | instruction | 0 | 82,116 | 14 | 164,232 |
Tags: brute force, dsu, meet-in-the-middle, number theory
Correct Solution:
```
total_boys, total_girls = map(int, input().split())
happy_boys = list(map(int, input().split()))
happy_girls = list(map(int, input().split()))
result_boy = [False] * total_boys
result_girl = [False] * total_girls
if happy_boys[0] > 0:
for i in range(1, len(happy_boys)):
result_boy[happy_boys[i]] = True
if happy_girls[0] > 0:
for j in range(1, len(happy_girls)):
result_girl[happy_girls[j]] = True
i_max = 10000
for i in range(i_max):
invited_boy = i % total_boys
invited_girl = i % total_girls
if result_boy[invited_boy] is True:
result_girl[invited_girl] = True
if result_girl[invited_girl] is True:
result_boy[invited_boy] = True
for boy in result_boy:
if boy is False:
print("No")
exit(0)
for girl in result_girl:
if girl is False:
print("No")
exit(0)
print("Yes")
``` | output | 1 | 82,116 | 14 | 164,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment. | instruction | 0 | 82,117 | 14 | 164,234 |
Tags: brute force, dsu, meet-in-the-middle, number theory
Correct Solution:
```
def main():
n, m = map(int, input().split())
bb = [False] * n
gg = [False] * m
l = list(map(int, input().split()))
for i in l[1:]:
bb[i] = True
l = list(map(int, input().split()))
for i in l[1:]:
gg[i] = True
for i in range((n + 1) * (m + 1)):
ib = i % n
ig = i % m
if bb[ib]:
gg[ig] = True
elif gg[ig]:
bb[ib] = True
print(('No', 'Yes')[all(bb) and all(gg)])
if __name__ == '__main__':
main()
``` | output | 1 | 82,117 | 14 | 164,235 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment. | instruction | 0 | 82,118 | 14 | 164,236 |
Tags: brute force, dsu, meet-in-the-middle, number theory
Correct Solution:
```
n, m = map(int, input().split())
x = list(map(int, input().split()))[1:]
y = list(map(int, input().split()))[1:]
boys = [False for i in range(n)]
girls = [False for i in range(m)]
for el in x:
boys[el] = True
for el in y:
girls[el] = True
while True:
flag = False
for i in range(n*m):
cur = boys[i % n] or girls[i % m]
if cur and not (boys[i % n] and girls[i % m]):
flag = True
boys[i % n] = cur
girls[i % m] = cur
if not flag:
break
for boy in boys:
if not boy:
break
else:
for girl in girls:
if not girl:
break
else:
print("Yes")
exit()
print("No")
``` | output | 1 | 82,118 | 14 | 164,237 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment. | instruction | 0 | 82,119 | 14 | 164,238 |
Tags: brute force, dsu, meet-in-the-middle, number theory
Correct Solution:
```
x=input().split()
l_1=input().split()
l_2=input().split()
del l_1[0]
del l_2[0]
list_1=[]
list_2=[]
lst_1=[int(value) for value in l_1]
lst_2=[int(value) for value in l_2]
n=int(x[0])
m=int(x[1])
def judge(a,b):
if a<b:
c=b
b=a
a=c
r=a%b
while r!=0:
a=b
b=r
r=a%b
return b
d=judge(n,m)
while lst_1!=list_1 or lst_2!=list_2:
list_1=list(set(lst_1))
list_2=list(set(lst_2))
for i in lst_1:
if i<m-1:
try:
for value in range(i,m,d):
lst_2.append(value)
except:
pass
try:
for value in range(i,-1,-d):
lst_2.append(value)
except:
pass
else:
try:
for p in range(m-1,m-d-2,-1):
if abs(i-p)%d==0:
break
for value in range(p,-1,-d):
lst_2.append(value)
except:
pass
lst_2=sorted(list(set(lst_2)))
for j in lst_2:
if j<n-1:
try:
for value in range(j,n,d):
lst_1.append(value)
except:
pass
try:
for value in range(j,-1,-d):
lst_1.append(value)
except:
pass
else:
try:
for q in range(n-1,n-d-2,-1):
if abs(j-q)%d==0:
break
for value in range(q,-1,-d):
lst_1.append(value)
except:
pass
lst_1=sorted(list(set(lst_1)))
lst_3=[value for value in range(0,n)]
lst_4=[value for value in range(0,m)]
if sorted(lst_1)==lst_3 and sorted(lst_2)==lst_4:
print('Yes')
else:
print('No')
``` | output | 1 | 82,119 | 14 | 164,239 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment. | instruction | 0 | 82,120 | 14 | 164,240 |
Tags: brute force, dsu, meet-in-the-middle, number theory
Correct Solution:
```
from math import gcd
n,m = list(map(int,input().split()))
x = 10**5
boys = list(map(int,input().split()))
girls = list(map(int,input().split()))
v1 = [False for i in range(n)]
v2 = [False for i in range(m)]
for i in boys[1::]:
v1[i] = True
for i in girls[1::]:
v2[i] = True
for i in range(x):
a,b = i%n,i%m
if v1[a]==True or v2[b]==True:
v1[a] = True
v2[b] = True
# print(v1)
# print(v2)
if False in v1 or False in v2:
print("No")
else:
print("Yes")
``` | output | 1 | 82,120 | 14 | 164,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
Submitted Solution:
```
import math
string = input()
numbers = string.split()
a, b = int(numbers[0]), int(numbers[1])
happyboys = list(map(int, input().split()))
del happyboys[0]
happygirls = list(map(int, input().split()))
del happygirls[0]
boys = [0 for x in range(a)]
girls = [0 for x in range(b)]
for x in happyboys:
boys[x] = 1
for x in happygirls:
girls[x] = 1
n = a * b // math.gcd(a, b)
while True:
temp = boys + girls
for x in range(n):
p, q = x % a, x % b
if boys[p] or girls[q]:
boys[p] = girls[q] = 1
if boys + girls == temp:
break
if all(boys + girls):
print("Yes")
else:
print("No")
``` | instruction | 0 | 82,121 | 14 | 164,242 |
Yes | output | 1 | 82,121 | 14 | 164,243 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
Submitted Solution:
```
n,m=[int(x) for x in input().split()]
bys = [int(x) for x in input().split()]
grls= [int(x) for x in input().split()]
i = 0
sb=[0]*n
sg=[0]*m
for i in range(1,len(bys)):
sb[bys[i]] = 1
for i in range(1,len(grls)):
sg[grls[i]] = 1
while 1:
nxby = i%n
nxgr = i%m
if sb[nxby] == 1 or sg[nxgr] == 1:
sb[nxby] = 1
sg[nxgr] = 1
if n*m + n*m< i:
break
i+=1
if sum(sb) + sum(sg) >= m+n:
print('Yes')
else:
print('No')
``` | instruction | 0 | 82,122 | 14 | 164,244 |
Yes | output | 1 | 82,122 | 14 | 164,245 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
Submitted Solution:
```
from math import gcd
n,m=map(int,input().split())
gcdd=gcd(n,m)
l=list(map(int,input().split()));r=[0]*gcdd
for i in l[1:]:
r[i%gcdd]=1
l1=list(map(int,input().split()))
for j in l1[1:]:
r[j%gcdd]=1
for i in r:
if i==0:exit(print("No"))
print("Yes")
``` | instruction | 0 | 82,123 | 14 | 164,246 |
Yes | output | 1 | 82,123 | 14 | 164,247 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
Submitted Solution:
```
from sys import stdin, gettrace
if not gettrace():
def input():
return next(stdin)[:-1]
# def input():
# return stdin.buffer.readline()
def main():
n,m = map(int, input().split())
happyb = [False] * n
xx = [int(a) for a in input().split()]
hbc = xx[0]
for x in xx[1:]:
happyb[x] = True
happyg = [False] * m
xx = [int(a) for a in input().split()]
hgc = xx[0]
for x in xx[1:]:
happyg[x] = True
updated = True
while updated:
updated = False
for i in range(n*m):
if happyb[i%n] and not happyg[i%m]:
happyg[i%m] = True
hgc +=1
updated = True
elif happyg[i%m] and not happyb[i%n]:
happyb[i%n] = True
hbc +=1
updated = True
if hbc == n and hgc == m:
print("Yes")
return
print("No")
if __name__ == "__main__":
main()
``` | instruction | 0 | 82,124 | 14 | 164,248 |
Yes | output | 1 | 82,124 | 14 | 164,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
Submitted Solution:
```
from sys import stdin
inp = stdin.readline
n, m = [int(x) for x in inp().strip().split()]
boys = [0]*n
girls = [0]*m
for x in inp().strip().split()[1:]:
boys[int(x)] = 1
for x in inp().strip().split()[1:]:
girls[int(x)] = 1
for x in range(max(n,m)**2):
if x%n or x%m:
boys[x%n] = 1
girls[x%m] = 1
boys.sort()
girls.sort()
if not min(boys[0],girls[0]):
print("NO")
else:
print("YES")
``` | instruction | 0 | 82,125 | 14 | 164,250 |
No | output | 1 | 82,125 | 14 | 164,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
Submitted Solution:
```
from itertools import repeat
n, m = map(int, input().split())
mylist1 = []
mylist1 = mylist1 + list(repeat(0, n))
newlist1 = []
newlist1 = newlist1 + list(repeat(0, m))
mylist = list(map(int, input().split()))
num1 = mylist[0]
del(mylist[0])
newlist = list(map(int, input().split()))
num2 = newlist[0]
del(newlist[0])
for i in range(0, len(mylist)):
mylist1[mylist[i]] = 1
for i in range(0, len(newlist)):
newlist1[newlist[i]] = 1
done = True
limit = n*m
for i in range(0, limit):
if mylist1[i%n] == 1 or newlist1[i%m] == 1:
mylist1[i%n] = 1
newlist1[i%m] = 1
if done:
for i in range(0, n):
if mylist1[i] == 0:
print("No")
done = False
break
if done:
for i in range(0, m):
if newlist1[i] == 0:
done = False
print("No")
break
if done:
print("Yes")
``` | instruction | 0 | 82,126 | 14 | 164,252 |
No | output | 1 | 82,126 | 14 | 164,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
Submitted Solution:
```
n, m = map(int, input().split())
x = list(map(int, input().split()))[1:]
y = list(map(int, input().split()))[1:]
boys = [False for i in range(n)]
girls = [False for i in range(m)]
for el in x:
boys[el] = True
for el in y:
girls[el] = True
for i in range(n*m):
cur = boys[i % n] or girls[i % m]
boys[i % n] = cur
girls[i % m] = cur
for boy in boys:
if not boy:
break
else:
for girl in girls:
if not girl:
break
else:
print("Yes")
exit()
print("No")
``` | instruction | 0 | 82,127 | 14 | 164,254 |
No | output | 1 | 82,127 | 14 | 164,255 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and <image>-th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1 β€ n, m β€ 100).
The second line contains integer b (0 β€ b β€ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 β€ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 β€ g β€ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 β€ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Examples
Input
2 3
0
1 0
Output
Yes
Input
2 4
1 0
1 2
Output
No
Input
2 3
1 0
1 1
Output
Yes
Note
By <image> we define the remainder of integer division of i by k.
In first sample case:
* On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
* On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
* On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
* On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
* On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
Submitted Solution:
```
from sys import stdin,stdout
# import collections
# import itertools
# import operator
# import functools
import math
def ii():return int(stdin.readline())
def mi():return map(int,stdin.readline().split())
def li():return list(mi())
def si():return stdin.readline()
n,m = mi()
l1 = [0]*n
gc = math.gcd(n,m)
for i in li()[1:]:
l1[i%gc] = 0
for i in li()[1:]:
l1[i%gc] = 0
for i in l1:
if not l1:
print("No")
break
else:
print("Yes")
``` | instruction | 0 | 82,128 | 14 | 164,256 |
No | output | 1 | 82,128 | 14 | 164,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.
Input
The input consists of a single line containing a positive integer n (2 β€ n β€ 105) β the number of employees in Fafa's company.
Output
Print a single integer representing the answer to the problem.
Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:
* choose only 1 employee as a team leader with 9 employees under his responsibility.
* choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
* choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | instruction | 0 | 82,315 | 14 | 164,630 |
Tags: brute force, implementation
Correct Solution:
```
ans = 0
k = int(input())
for i in range(1, k):
if k % i == 0:
ans += 1
print(ans)
``` | output | 1 | 82,315 | 14 | 164,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.
Input
The input consists of a single line containing a positive integer n (2 β€ n β€ 105) β the number of employees in Fafa's company.
Output
Print a single integer representing the answer to the problem.
Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:
* choose only 1 employee as a team leader with 9 employees under his responsibility.
* choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
* choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | instruction | 0 | 82,316 | 14 | 164,632 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
yes = 0
for i in range(1, n + 1):
j=n-i
if j % i == 0 and j>0:
yes += 1
print(yes)
``` | output | 1 | 82,316 | 14 | 164,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.
Input
The input consists of a single line containing a positive integer n (2 β€ n β€ 105) β the number of employees in Fafa's company.
Output
Print a single integer representing the answer to the problem.
Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:
* choose only 1 employee as a team leader with 9 employees under his responsibility.
* choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
* choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | instruction | 0 | 82,317 | 14 | 164,634 |
Tags: brute force, implementation
Correct Solution:
```
n_employee = int(input())
counter = 0
for index in range(n_employee):
if (n_employee - index) != 0 and index != 0:
if (n_employee - index) % index == 0:
counter = counter + 1
print(int(counter))
``` | output | 1 | 82,317 | 14 | 164,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.
Input
The input consists of a single line containing a positive integer n (2 β€ n β€ 105) β the number of employees in Fafa's company.
Output
Print a single integer representing the answer to the problem.
Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:
* choose only 1 employee as a team leader with 9 employees under his responsibility.
* choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
* choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | instruction | 0 | 82,318 | 14 | 164,636 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
cnt = 0
m = 0
while m < n // 2:
m += 1
if n % m == 0:
cnt += 1
print(cnt)
``` | output | 1 | 82,318 | 14 | 164,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.
Input
The input consists of a single line containing a positive integer n (2 β€ n β€ 105) β the number of employees in Fafa's company.
Output
Print a single integer representing the answer to the problem.
Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:
* choose only 1 employee as a team leader with 9 employees under his responsibility.
* choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
* choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | instruction | 0 | 82,319 | 14 | 164,638 |
Tags: brute force, implementation
Correct Solution:
```
import sys
n = int(sys.stdin.readline().rstrip())
count = 0
for l in range(1, n):
if (n - l) % l == 0:
count += 1
print(str(count) + "\n")
``` | output | 1 | 82,319 | 14 | 164,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.
Input
The input consists of a single line containing a positive integer n (2 β€ n β€ 105) β the number of employees in Fafa's company.
Output
Print a single integer representing the answer to the problem.
Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:
* choose only 1 employee as a team leader with 9 employees under his responsibility.
* choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
* choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | instruction | 0 | 82,320 | 14 | 164,640 |
Tags: brute force, implementation
Correct Solution:
```
n=int(input())
x=0
for i in range(1,n):
if n%i==0:
x+=1
print(x)
``` | output | 1 | 82,320 | 14 | 164,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.
Input
The input consists of a single line containing a positive integer n (2 β€ n β€ 105) β the number of employees in Fafa's company.
Output
Print a single integer representing the answer to the problem.
Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:
* choose only 1 employee as a team leader with 9 employees under his responsibility.
* choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
* choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | instruction | 0 | 82,321 | 14 | 164,642 |
Tags: brute force, implementation
Correct Solution:
```
n=int(input())
count=0
i=1
while i<=int(n//2):
l=i
r=n-l
if r%l==0:
count=count+1
i=i+1
print(count)
``` | output | 1 | 82,321 | 14 | 164,643 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.