message stringlengths 2 20.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 1.95k 109k | cluster float64 17 17 | __index_level_0__ int64 3.91k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.
If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:
1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
2. Right after that he starts to type it.
3. Exactly t milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game.
Input
The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
Output
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Examples
Input
5 1 2 1 2
Output
First
Input
3 3 1 1 1
Output
Second
Input
4 5 3 1 5
Output
Friendship
Note
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
Submitted Solution:
```
s,v1,v2,t1,t2=map(int,input().split())
a,b=s*v1+2*t1,s*v2+2*t2
if(a==b):
print("Friendship")
if(a<b):
print("First")
else:
print("Second")
``` | instruction | 0 | 60,329 | 17 | 120,658 |
No | output | 1 | 60,329 | 17 | 120,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.
If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:
1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
2. Right after that he starts to type it.
3. Exactly t milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game.
Input
The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
Output
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Examples
Input
5 1 2 1 2
Output
First
Input
3 3 1 1 1
Output
Second
Input
4 5 3 1 5
Output
Friendship
Note
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
Submitted Solution:
```
s , v1 , v2 , t1 ,t2 = map(int ,input().split())
d=v1*s + 2*t1
e = v2*s + 2*t2
if d==e:
print("Friendship")
if d>e:print("First")
if d<e:
print("Second")
``` | instruction | 0 | 60,330 | 17 | 120,660 |
No | output | 1 | 60,330 | 17 | 120,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.
If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:
1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
2. Right after that he starts to type it.
3. Exactly t milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game.
Input
The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
Output
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Examples
Input
5 1 2 1 2
Output
First
Input
3 3 1 1 1
Output
Second
Input
4 5 3 1 5
Output
Friendship
Note
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
Submitted Solution:
```
s,v1,v2,t1,t2 = map(int, input().split())
p1 = s * v1 + t1
p2 = s * v2 + t2
print(p1)
print(p2)
ft1 = p1 + t1
ft2 = p2 + t2
print(ft1)
print(ft2)
if ft1 < ft2:
print("First")
elif ft1 > ft2:
print("Second")
else:
print("Friendship")
``` | instruction | 0 | 60,331 | 17 | 120,662 |
No | output | 1 | 60,331 | 17 | 120,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district i is equal to 2^i.
This year, the president decided to reduce the costs. He wants to remove k contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove?
Input
The first line of input contains two integers n and k (1 ≤ k < n ≤ 10^6) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next n-1 lines each contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b), that describe a road that connects two different districts a and b in the nation. It is guaranteed that there is exactly one path between every two districts.
Output
Print k space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.
Examples
Input
6 3
2 1
2 6
4 2
5 6
2 3
Output
1 3 4
Input
8 4
2 6
2 7
7 8
1 2
3 1
2 4
7 5
Output
1 3 4 5
Note
In the first sample, the maximum possible total number of fans is 2^2 + 2^5 + 2^6 = 100. We can achieve it by removing the contestants of the districts 1, 3, and 4.
Submitted Solution:
```
from typing import *
V = TypeVar("V")
class graph:
vertices:List[V]
graphDict:Dict[V,Set[V]]
def __init__(self,vertices,graphDict):
self.vertices = vertices
self.graphDict = graphDict
for v in vertices:
if not v in self.graphDict:
self.graphDict[v] = set()
def isEdge(self,a:V,b:V):
return b in self.graphDict[a]
def neighbours(self,a:V)->List[V]:
return self.graphDict.get(a,[])
def appendEdge(self,a:V,b:V):
assert not self.isEdge(a,b)
self.graphDict[a].add(b)
self.graphDict[b].add(a)
def deleteEdge(self,a:V,b:V):
assert self.isEdge(a,b)
self.graphDict[a].remove(b)
self.graphDict[b].remove(a)
def rootedEnumeration(self,root:V):
# Make sure graph is connected
S:Set[V] = set([root])
discovered:Set[V] = set()
decendentDict: Dict[V, List[V]] = dict()
ordering:List[V] = []
while bool(S):
v = S.pop()
if not v in discovered:
discovered.add(v)
ordering.append(v)
decendentDict[v] = self.graphDict[v] - discovered
for n in self.graphDict[v]:
S.add(n)
return decendentDict,ordering
def DFS(self,root:V):
return self.rootedEnumeration(root)[1]
def spanningTree(self,root:V):
decendents,order = self.rootedEnumeration(root)
return rootedTree(root,self.vertices,decendents,order)
@property
def connected(self)->bool:
v = self.vertices[0]
dfs = self.rootedEnumeration(v)
return (len(dfs) == len(self.vertices))
@staticmethod
def typicalTree():
G = graph([1,2,3,4,5],dict())
G.appendEdge(1,3)
G.appendEdge(1,4)
G.appendEdge(4,2)
G.appendEdge(4,5)
return G
#Custom Implementations here
class rootedTree:
vertices:List[V]
root:V
decendents:Dict[V,Set[V]]
parents:Dict[V,V]
order:List[V]
def __init__(self,root,vertices,decendents,order):
self.root = root
self.vertices = vertices
self.decendents = decendents
self.order = order
self.parents = dict()
for v in decendents:
for child in decendents[v]:
self.parents[child] = v
def decendentMax(G:graph,k:int):
T = G.spanningTree(len(G.vertices))
available:List[V] = [v for v in T.vertices if not bool(T.decendents[v])]
eliminated:Set[V] = set()
chosen:List[int] = []
while len(chosen) < k:
taking = min(available)
eliminated.add(taking)
chosen.append(taking)
available.remove(taking)
assert taking != T.root
p = T.parents[taking]
if(eliminated.issuperset(T.decendents[p])):
available.append(p)
assert len(chosen) == k
return chosen
def readInt():
return int(input())
def readLine():
return [int(s) for s in input().split(" ")]
vertices, k = readLine()
newGraph = graph(range(1,vertices+1),dict())
for _ in range(vertices-1):
a,b = readLine()
newGraph.appendEdge(a,b)
chosen = decendentMax(newGraph,k)
chosen.sort()
print(" ".join([str(c) for c in chosen]))
``` | instruction | 0 | 60,369 | 17 | 120,738 |
No | output | 1 | 60,369 | 17 | 120,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district i is equal to 2^i.
This year, the president decided to reduce the costs. He wants to remove k contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove?
Input
The first line of input contains two integers n and k (1 ≤ k < n ≤ 10^6) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next n-1 lines each contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b), that describe a road that connects two different districts a and b in the nation. It is guaranteed that there is exactly one path between every two districts.
Output
Print k space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.
Examples
Input
6 3
2 1
2 6
4 2
5 6
2 3
Output
1 3 4
Input
8 4
2 6
2 7
7 8
1 2
3 1
2 4
7 5
Output
1 3 4 5
Note
In the first sample, the maximum possible total number of fans is 2^2 + 2^5 + 2^6 = 100. We can achieve it by removing the contestants of the districts 1, 3, and 4.
Submitted Solution:
```
class Node:
def __init__(self, val):
self.key = val
self.left = None
self.right = None
class BST:
def __init__(self):
self.root = None
def _min(self, x):
if x.left is None:
return x
return self._min(x.left)
def _delete_min(self, x):
if x.left is None:
return x.right
x.left = self._delete_min(x.left)
return x
def _delete(self, x, val):
if x is None:
return None
if val < x.key:
x.left = self._delete(x.left, val)
elif val > x.key:
x.right = self._delete(x.right, val)
else:
if x.right is None:
return x.left
if x.left is None:
return x.right
t = x
x = self._min(t.right)
x.right = self._delete_min(t.right)
x.left = t.left
return x
def _put(self, x, val):
if x is None:
return Node(val)
if val < x.key:
x.left = self._put(x.left, val)
elif val > x.key:
x.right = self._put(x.right, val)
return x
def min(self):
if self.root is None:
return None
return self._min(self.root).key
def insert(self, val):
self.root = self._put(self.root, val)
def delete(self, val):
self.root = self._delete(self.root, val)
def replace(self, a, b):
self.delete(a)
self.insert(b)
def pop_min(self):
if self.root is None:
return None
val = self._min(self.root).key
self.root = self._delete_min(self.root)
return val
def _inorder(self, x, q):
if x is None:
return
self._inorder(x.left, q)
q.append(x.key)
self._inorder(x.right, q)
def keys(self):
q = []
self._inorder(self.root, q)
return q
def solve(adj, k):
bst = BST()
for i, a in enumerate(adj):
bst.insert((len(a), i))
rmv = []
for _ in range(k):
# print([(u + 1, a) for a, u in bst.keys()])
ai, i = bst.pop_min()
assert ai == 1
j = list(adj[i])[0]
aj = len(adj[j])
# print('replace ({}, {}) by ({}, {})'.format(j, aj , j, aj - 1))
bst.replace((aj, j), (aj - 1, j))
adj[j].remove(i)
rmv.append(i + 1)
# print([(u + 1, a) for a, u in bst.keys()])
rmv.sort()
return rmv
def main():
n, k = [int(_) for _ in input().split()]
adj = [set() for _ in range(n)]
for i in range(n - 1):
u, v = [int(_) for _ in input().split()]
adj[u - 1].add(v - 1)
adj[v - 1].add(u - 1)
rmv = solve(adj, k)
print(' '.join(map(str, rmv)))
if __name__ == '__main__':
main()
``` | instruction | 0 | 60,370 | 17 | 120,740 |
No | output | 1 | 60,370 | 17 | 120,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district i is equal to 2^i.
This year, the president decided to reduce the costs. He wants to remove k contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove?
Input
The first line of input contains two integers n and k (1 ≤ k < n ≤ 10^6) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next n-1 lines each contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b), that describe a road that connects two different districts a and b in the nation. It is guaranteed that there is exactly one path between every two districts.
Output
Print k space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.
Examples
Input
6 3
2 1
2 6
4 2
5 6
2 3
Output
1 3 4
Input
8 4
2 6
2 7
7 8
1 2
3 1
2 4
7 5
Output
1 3 4 5
Note
In the first sample, the maximum possible total number of fans is 2^2 + 2^5 + 2^6 = 100. We can achieve it by removing the contestants of the districts 1, 3, and 4.
Submitted Solution:
```
#!/usr/bin/env python3
import heapq
[n, k] = map(int, input().strip().split())
bis = [tuple(map(int, input().strip().split())) for _ in range(n - 1)]
tos = [[] for _ in range(n)]
for u, v in bis:
tos[u - 1].append(v - 1)
tos[v - 1].append(u - 1)
incs = [len(t) for t in tos]
visited = [False for _ in range(n)]
parent = [-1 for _ in range(n)]
def BFS(v):
visited[v] = True
while v != n - 1 and len(tos[v]) == 2:
w = sum(tos[v]) - parent[v]
parent[w] = v
v = w
visited[v] = True
for w in tos[v]:
if not visited[w]:
parent[w] = v
BFS(w)
BFS(n - 1)
heap = [i for i, l in enumerate(incs) if l==1]
heapq.heapify(heap)
res = [0 for _ in range(k)]
for K in range(k):
v = heapq.heappop(heap)
res[K] = v
p = parent[v]
incs[p] -= 1
if incs[p] == 1:
heapq.heappush(heap, p)
res.sort()
print (' '.join(map(lambda x: str(x + 1), res)))
``` | instruction | 0 | 60,371 | 17 | 120,742 |
No | output | 1 | 60,371 | 17 | 120,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district i is equal to 2^i.
This year, the president decided to reduce the costs. He wants to remove k contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove?
Input
The first line of input contains two integers n and k (1 ≤ k < n ≤ 10^6) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next n-1 lines each contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b), that describe a road that connects two different districts a and b in the nation. It is guaranteed that there is exactly one path between every two districts.
Output
Print k space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.
Examples
Input
6 3
2 1
2 6
4 2
5 6
2 3
Output
1 3 4
Input
8 4
2 6
2 7
7 8
1 2
3 1
2 4
7 5
Output
1 3 4 5
Note
In the first sample, the maximum possible total number of fans is 2^2 + 2^5 + 2^6 = 100. We can achieve it by removing the contestants of the districts 1, 3, and 4.
Submitted Solution:
```
import sys
import heapq as hp
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,k=I()
g=[[] for i in range(n)]
for i in range(n-1):
a,b=I()
g[a-1].append(b-1)
g[b-1].append(a-1)
p=[i for i in range(n)]
def dfs(i,v):
p[i]=v
for x in g[i]:
if x!=v:
dfs(x,i)
dfs(0,0)
deg=[0]*n
for i in range(n):
deg[i]=len(g[i])
he=[i for i in range(n) if deg[i]==1]
hp.heapify(he)
an=[]
while len(an)<k:
x=hp.heappop(he)
an.append(x+1)
deg[p[x]]-=1
if deg[p[x]]==1:
hp.heappush(he,p[x])
an.sort()
print(*an)
``` | instruction | 0 | 60,372 | 17 | 120,744 |
No | output | 1 | 60,372 | 17 | 120,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2 | instruction | 0 | 61,031 | 17 | 122,062 |
Tags: brute force, greedy, implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
def main():
n = int(input())
teams = [input().split() for _ in range(n)]
ans = [list((0, 0)) for _ in range(n)]
home = dict()
for i in range(n):
home[teams[i][0]] = home.get(teams[i][0], 0) + 1
for i in range(n):
ans[i][0] = n - 1 + home.get(teams[i][1], 0)
ans[i][1] = n - 1 - home.get(teams[i][1], 0)
for i in range(n):
ans[i] = '{} {}'.format(ans[i][0], ans[i][1])
print('\n'.join(ans))
if __name__ == '__main__':
main()
``` | output | 1 | 61,031 | 17 | 122,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2 | instruction | 0 | 61,032 | 17 | 122,064 |
Tags: brute force, greedy, implementation
Correct Solution:
```
from sys import stdin
n = int(stdin.readline().rstrip())
h= [0]*(10**5 + 6)
a = [0]*(n+1)
for i in range(n):
l = list(map(int, stdin.readline().rstrip().split(" ")))
h[l[0]]+=1
a[i+1]=l[1]
for i in range(1,n+1):
print(n-1 + h[a[i]] , 2*n - 2 - (n-1 + h[a[i]]))
``` | output | 1 | 61,032 | 17 | 122,065 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2 | instruction | 0 | 61,033 | 17 | 122,066 |
Tags: brute force, greedy, implementation
Correct Solution:
```
import sys
import math
n = int(sys.stdin.readline())
a = [0] * 100000
d = []
for i in range(n):
h, g = [int(x) for x in (sys.stdin.readline()).split()]
d.append(g - 1)
a[h - 1] += 1
for i in d:
print(str((n - 1) + (a[i])) + " " + str(n - a[i] - 1))
``` | output | 1 | 61,033 | 17 | 122,067 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2 | instruction | 0 | 61,034 | 17 | 122,068 |
Tags: brute force, greedy, implementation
Correct Solution:
```
n = int(input())
i = 0
l1 = list()
l2 = list()
l3 = [0] + [0] * 10**5
l4 = [0] + [0] * 10**5
i = 0
while i < n:
x, y = map(int,input().split())
l1.append(x)
l2.append(y)
l3[x] += 1
l4[y] += 1
i += 1
i = 0
for i in range(n):
print(n-1 + l3[l2[i]], n-1 - l3[l2[i]])
``` | output | 1 | 61,034 | 17 | 122,069 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2 | instruction | 0 | 61,035 | 17 | 122,070 |
Tags: brute force, greedy, implementation
Correct Solution:
```
n = int(input())
home_color_teams = [[] for _ in range(10**5 + 5)]
away_color_teams = [[] for _ in range(10**5 + 5)]
for i in range(n):
xi, yi = map(int, input().split())
home_color_teams[xi].append(i)
away_color_teams[yi].append(i)
home_color_count = [n - 1 for _ in range(n)]
away_color_count = [n - 1 for _ in range(n)]
for i in range(10**5 + 5):
c = len(home_color_teams[i])
for j in range(len(away_color_teams[i])):
home_color_count[away_color_teams[i][j]] += c
away_color_count[away_color_teams[i][j]] -= c
for i in range(n):
print(home_color_count[i], away_color_count[i])
``` | output | 1 | 61,035 | 17 | 122,071 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2 | instruction | 0 | 61,036 | 17 | 122,072 |
Tags: brute force, greedy, implementation
Correct Solution:
```
from collections import Counter
n = int(input())
x, y = [], []
for i in range(n):
a, b = map(int, input().split())
x.append(a)
y.append(b)
home = Counter(x)
away = Counter(y)
ans = 0
mHome, mAway = [n-1]*n, [n-1]*n
for i in range(n):
if y[i] in home:
mHome[i] += home[y[i]]
mAway[i] -= home[y[i]]
for i in range(n):
print(mHome[i], mAway[i])
``` | output | 1 | 61,036 | 17 | 122,073 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2 | instruction | 0 | 61,037 | 17 | 122,074 |
Tags: brute force, greedy, implementation
Correct Solution:
```
"""http://codeforces.com/problemset/problem/432/B"""
from collections import Counter
# from sys import stdin
# _data = iter(stdin.read().split('\n'))
# input = lambda: next(_data)
if __name__ == '__main__':
n = int(input())
# arr = [list(map(int, input().split())) for _ in range(n)]
arr = [None] * n
home = [0] * 100001
# home = Counter()
for i in range(n):
h, a = map(int, input().split())
arr[i] = [h, a]
home[h] += 1
num_match = n - 1
for h, a in arr:
x = home[a]
print(num_match + x, num_match - x)
``` | output | 1 | 61,037 | 17 | 122,075 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2 | instruction | 0 | 61,038 | 17 | 122,076 |
Tags: brute force, greedy, implementation
Correct Solution:
```
n=int(input())
x=[]
for i in range(n):
x.append(list(map(int,input().split())))
h={}
a={}
for i in range(n):
if(h.get(str(x[i][0]))):
h[str(x[i][0])]+=1
else:
h[str(x[i][0])]=1
for i in range(n):
home=n-1
if(h.get(str(x[i][1]))):
if(h[str(x[i][1])]>0):
away= n-1-h[str(x[i][1])]
home+=h[str(x[i][1])]
else:
away=n-1
print(home,away)
``` | output | 1 | 61,038 | 17 | 122,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2
Submitted Solution:
```
size = int(input())
match = size - 1
commands_colours = []
cnt = [0] * 100001
for i in range(0, size):
commands_colours.append([int(x) for x in input().split()])
cnt[commands_colours[i][0]] = cnt[commands_colours[i][0]] + 1
for i in range(0, size):
print(match + cnt[commands_colours[i][1]], match - cnt[commands_colours[i][1]])
``` | instruction | 0 | 61,039 | 17 | 122,078 |
Yes | output | 1 | 61,039 | 17 | 122,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2
Submitted Solution:
```
n = int(input())
local = [0]*(10**5+1)
kits = []
for i in range(n):
x, y = list(map(int, input().split(" ")))
kits.append((x, y))
local[x] += 1
res = ["%s %s" % (n-1+local[y], n-1-local[y]) for (x, y) in kits]
print("\n".join(res))
``` | instruction | 0 | 61,040 | 17 | 122,080 |
Yes | output | 1 | 61,040 | 17 | 122,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2
Submitted Solution:
```
import math
import sys
from collections import *
from bisect import bisect_left, bisect_right
def cint() : return list(map(int, sys.stdin.readline().strip().split()))
def cstr() : return list(map(str, input().split(' ')))
def solve():
n = int(input())
lst1 = []
lst2 = []
for i in range(n):
x,y = cint()
lst1.append(x)
lst2.append(y)
cnt = {}
for i in lst1:
if cnt.get(i) is None:
cnt[i] = 1
else: cnt[i]+=1
for i in range(n):
same = cnt.get(lst2[i])
if same is None: same = 0
home = n-1 + same
away = n-1 - same
print(home,away)
if __name__ == "__main__":
# t = int(input())
t = 1
while t!=0:
solve()
t-=1
``` | instruction | 0 | 61,041 | 17 | 122,082 |
Yes | output | 1 | 61,041 | 17 | 122,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2
Submitted Solution:
```
def main():
n = int(input())
l = list(tuple(map(int, input().split())) for _ in range(n))
xx, yy = [0] * 100001, [0] * 100001
for x, y in l:
xx[x] += 1
yy[y] += 1
n -= 1
for i, (_, y) in enumerate(l):
x = xx[y]
l[i] = '{:d} {:d}'.format(n + x, n - x)
print('\n'.join(l))
if __name__ == '__main__':
main()
``` | instruction | 0 | 61,042 | 17 | 122,084 |
Yes | output | 1 | 61,042 | 17 | 122,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2
Submitted Solution:
```
n = int(input())
a = []
t = []
for i in range(n):
a.append(input().split())
t.append([n-1,0])
for i in range(len(a)):
for j in a:
if a[i][1] == j[0]:
t[i][0] += 1
t[i][1] = (n-1)**2 - t[i][0]
print(t)
``` | instruction | 0 | 61,043 | 17 | 122,086 |
No | output | 1 | 61,043 | 17 | 122,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2
Submitted Solution:
```
n=int(input())
comand=[0]*n
ans=[n-1]*n
for i in range(n):
comand[i]=[0]*2
comand[i]=list(map(int, input().split()))
for i in range(n):
for j in range(i+1,n):
if comand[i][1]==comand[j][0]:
ans[i]+=1
if comand[i][0]==comand[j][1]:
ans[j]+=1
for i in ans:
print(i,(n-1)*(n-1)-i)
``` | instruction | 0 | 61,044 | 17 | 122,088 |
No | output | 1 | 61,044 | 17 | 122,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2
Submitted Solution:
```
import sys
import math
n = int(sys.stdin.readline())
a = [0] * n
b = [0] * n
d = []
for i in range(n):
h, g = [int(x) for x in (sys.stdin.readline()).split()]
d.append((h - 1, g - 1))
a[h - 1] += 1
b[g - 1] += 1
print(b)
for i in d:
print(str((n - 1) + (a[i[1]])) + " " + str(n - a[i[1]] - 1))
``` | instruction | 0 | 61,045 | 17 | 122,090 |
No | output | 1 | 61,045 | 17 | 122,091 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.
Output
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Examples
Input
2
1 2
2 1
Output
2 0
2 0
Input
3
1 2
2 1
1 3
Output
3 1
4 0
2 2
Submitted Solution:
```
n = int(input())
a = []
for i in range(n):
a.append(input().split())
a[i].append(0)
a[i].append(0)
for i in range(len(a)):
n = n - n%2
a[i][2] = n*(n-1)
for j in [x[1] for x in enumerate(a) if x[0] != i]:
if a[i][1] == j[0]:
a[i][2] += 1
else:
a[i][3] += 1
for i in a:
print(i[2], i[3])
``` | instruction | 0 | 61,046 | 17 | 122,092 |
No | output | 1 | 61,046 | 17 | 122,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0 | instruction | 0 | 61,824 | 17 | 123,648 |
Tags: greedy, implementation, sortings
Correct Solution:
```
x = int(input())
y = input().split()
team = min(y.count('1'),y.count('2'),y.count('3'))
print(team)
for i in range(team):
a = y.index('1')
b = y.index('2')
c = y.index('3')
print(a+1,b+1,c+1)
y[a] , y[b] , y[c] = 0,0,0
``` | output | 1 | 61,824 | 17 | 123,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0 | instruction | 0 | 61,825 | 17 | 123,650 |
Tags: greedy, implementation, sortings
Correct Solution:
```
import sys
n = sys.stdin.readline()
while n:
students = sys.stdin.readline().split()
s1 = []
s2 = []
s3 = []
total_1 = 0
total_2 = 0
total_3 = 0
for i, s in enumerate(students):
if s == '1':
s1.append(i+1)
total_1 += 1
elif s == '2':
s2.append(i+1)
total_2 += 1
else:
s3.append(i+1)
total_3 += 1
total_groups = min(total_1, total_2, total_3)
print(total_groups)
while s1 and s2 and s3:
print(s1.pop(0), s2.pop(0), s3.pop(0))
n = sys.stdin.readline()
``` | output | 1 | 61,825 | 17 | 123,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0 | instruction | 0 | 61,826 | 17 | 123,652 |
Tags: greedy, implementation, sortings
Correct Solution:
```
#!/usr/bin/env python
# coding=utf-8
input_s = int(input())
input_l = input().split(' ')
result_list = [[], [], []]
for (index, l) in enumerate(input_l):
num_l = int(l)
result_list[num_l - 1].append(index + 1)
j = min(len(result_list[0]), len(result_list[1]), len(result_list[2]))
print(j)
for i in range(len(result_list[0])):
if len(result_list[1]) < i + 1 or len(result_list[2]) < i + 1:
break
print('{} {} {}'.format(result_list[0][i], result_list[1][i],
result_list[2][i]))
``` | output | 1 | 61,826 | 17 | 123,653 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0 | instruction | 0 | 61,827 | 17 | 123,654 |
Tags: greedy, implementation, sortings
Correct Solution:
```
#X'OTWOD
t=int(input());a=[];b=[];c=[];o=[];
o=list(map(int,input().split()))
for j in range(1,t+1):
if o[j-1]==1:a.append(j)
elif o[j-1]==2:b.append(j)
else:c.append(j)
m=min(len(a),len(b),len(c))
print(m)
for i in range(m):
print(f'{a[i]} {b[i]} {c[i]}')
``` | output | 1 | 61,827 | 17 | 123,655 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0 | instruction | 0 | 61,828 | 17 | 123,656 |
Tags: greedy, implementation, sortings
Correct Solution:
```
import sys
from collections import Counter
number=int(sys.stdin.readline().strip())
skill=list(map(int,sys.stdin.readline().strip().split()))
if len(set(skill))==3:
team=min(Counter(skill).values())
else:
team=0
Lst=[]
for k,n in enumerate(skill):
Lst.append((n,k+1))
one=[]
two=[]
three=[]
for b in Lst:
if b[0]==1:
one.append(b[1])
if b[0]==2:
two.append(b[1])
if b[0]==3:
three.append(b[1])
print(team)
for k in zip(one,two,three):
print(' '.join(map(str,k)))
``` | output | 1 | 61,828 | 17 | 123,657 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0 | instruction | 0 | 61,829 | 17 | 123,658 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
res = [[], [], []]
for j, i in enumerate(arr):
if i:
res[i-1].append(j + 1)
x = min(map(len, res))
print(x)
for i in range(x):
print(res[0][i], res[1][i], res[2][i])
``` | output | 1 | 61,829 | 17 | 123,659 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0 | instruction | 0 | 61,830 | 17 | 123,660 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n=int(input())
t=list(map(int,input().split()))
a=min(t.count(1),t.count(2),t.count(3))
print(a)
l1=[]
l2=[]
l3=[]
for i in range(n):
if t[i]==1:
l1.append(i+1)
elif t[i]==2:
l2.append(i+1)
else:
l3.append(i+1)
if a>0:
for i in range(a):
s=[str(l1.pop(0)),str(l2.pop(0)),str(l3.pop(0))]
print(' '.join(s))
``` | output | 1 | 61,830 | 17 | 123,661 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0 | instruction | 0 | 61,831 | 17 | 123,662 |
Tags: greedy, implementation, sortings
Correct Solution:
```
import sys
import math
input = sys.stdin.readline
n = int(input())
a = map(int, input().split())
l = [[], [], []]
for i, ai in enumerate(a, 1):
l[ai-1].append(i)
print(min(len(l[0]),len(l[1]),len(l[2])))
for j in zip(*l):
print(' '.join(map(str, j)))
``` | output | 1 | 61,831 | 17 | 123,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
Submitted Solution:
```
def solve(n,s):
d = {}
for j in range(n):
if s[j] not in d:
d[s[j]] = list()
d[s[j]].append(j+1)
if len(d) < 3:
print(0)
return None
else:
m = min([len(d[j]) for j in d])
print(m)
for i in range(m):
ans = [str(d[j][i]) for j in d]
print(" ".join(ans))
n = int(input())
s = list(map(int,input().split()))
solve(n,s)
``` | instruction | 0 | 61,832 | 17 | 123,664 |
Yes | output | 1 | 61,832 | 17 | 123,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
Submitted Solution:
```
n = int(input())
s = list(map(int,input().split()))
cnt = [[], [], []]
for i in range(0, n):
cnt[s[i]-1].append(i)
mn = min(map(len,cnt))
print(mn)
for i in range(0, mn):
for L in cnt:
print(L[i]+1, end=' ')
print()
``` | instruction | 0 | 61,833 | 17 | 123,666 |
Yes | output | 1 | 61,833 | 17 | 123,667 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
z=min(l.count(1),l.count(2),l.count(3))
print(z)
while(z!=0):
print(l.index(1)+1,end=" ")
l[l.index(1)]=0
print(l.index(2)+1,end=" ")
l[l.index(2)]=0
print(l.index(3)+1)
l[l.index(3)]=0
z-=1
``` | instruction | 0 | 61,834 | 17 | 123,668 |
Yes | output | 1 | 61,834 | 17 | 123,669 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
Submitted Solution:
```
foo = input()
dx = [int(x) for x in input().split()]
ones = [x for x in enumerate(dx) if x[1] == 1]
twoes = [x for x in enumerate(dx) if x[1] == 2]
threes = [x for x in enumerate(dx) if x[1] == 3]
possible = min(len(ones), len(twoes), len(threes))
matches = []
for i in range(possible) :
matches.append((ones[i][0]+1, twoes[i][0]+1, threes[i][0]+1))
print(possible)
for x in range(possible):
print(*matches[x])
``` | instruction | 0 | 61,835 | 17 | 123,670 |
Yes | output | 1 | 61,835 | 17 | 123,671 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
Submitted Solution:
```
n=int(input())
s=[str(x) for x in input().split()]
team=min(s.count('1'),s.count('2'),s.count('3'))
a=0
b=0
c=0
if team==0:
print('0')
else:
for i in range(team):
a=s.index('1',a+1)+1
b=s.index('2',b+1)+1
c=s.index('3',c+1)+1
print(a,b,c)
``` | instruction | 0 | 61,836 | 17 | 123,672 |
No | output | 1 | 61,836 | 17 | 123,673 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
Submitted Solution:
```
a = int(input())
b = list(map(int, input().split()))
c1 = []
c2 = []
c3 = []
for i in range(a):
if(b[i] == 1):
c1.append(i+1)
elif(b[i] == 2):
c2.append(i+1)
else:
c3.append(i+1)
for i in range(min(len(c1), min(len(c2), len(c3)))):
print(c1[i], c2[i], c3[i])
``` | instruction | 0 | 61,837 | 17 | 123,674 |
No | output | 1 | 61,837 | 17 | 123,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
s=set(a)
if len(s)<3:
print(0)
else:
diff=[0]*3
for i in range(n):
diff[a[i]-1]+=1
x=min(diff)
l=[]
m=[]
p=[]
for i in range(n):
if a[i]==1:
l.append(i+1)
elif a[i]==2:
m.append(i+1)
elif a[i]==3:
p.append(i+1)
i=0
q=[]
for i in range(x):
q.append(l[i])
q.append(m[i])
q.append(p[i])
print(x)
i=0
j=3
r=0
while i<n and r<2:
print(*q[i:j])
i+=j
j+=3
r+=1
``` | instruction | 0 | 61,838 | 17 | 123,676 |
No | output | 1 | 61,838 | 17 | 123,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
* ti = 1, if the i-th child is good at programming,
* ti = 2, if the i-th child is good at maths,
* ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
z=[]
for i in a:
if 1 and 2 and 3 in a:
z.append([a.index(1)+1,a.index(2)+1,a.index(3)+1])
a.remove(1)
a.remove(2)
a.remove(3)
print(len(z))
if len(z)!=0:
for i in z:
print(" ".join(map(str,i)))
``` | instruction | 0 | 61,839 | 17 | 123,678 |
No | output | 1 | 61,839 | 17 | 123,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1". | instruction | 0 | 61,856 | 17 | 123,712 |
Tags: greedy, implementation
Correct Solution:
```
n, k, p, x, y = map(int, input().split())
s, g, l = 0, 0, []
for a in map(int, input().split()):
s += a
g += a >= y
for i in range(n - k):
c = 1 if g >= n // 2 + 1 else y
s += c
g += c == y
l.append(c)
print(' '.join(map(str, l)) if s <= x and g >= n // 2 + 1 else -1)
``` | output | 1 | 61,856 | 17 | 123,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1". | instruction | 0 | 61,857 | 17 | 123,714 |
Tags: greedy, implementation
Correct Solution:
```
def main():
n, k, p, x, y = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
median = int((n + 1) / 2)
less = 0
for i in range(len(a)):
if a[i] < y:
less += 1
#print(less, median)
if less >= median:
print(-1)
return
fillOne = min(median - less - 1, n - k)
if sum(a) + fillOne*1 + (n - k - fillOne)*y > x:
print(-1)
return
for i in range(fillOne):
print(1, end=' ')
for i in range(n - k - fillOne):
print(y, end=' ')
if __name__ == '__main__':
main()
``` | output | 1 | 61,857 | 17 | 123,715 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1". | instruction | 0 | 61,858 | 17 | 123,716 |
Tags: greedy, implementation
Correct Solution:
```
n,k,p,x,y=(int(x) for x in input().split())
a = [int(x) for x in input().split()]
if n == 1:
if y > x:
print(-1)
else:
print(y)
exit(0)
a.sort()
med_pos = n // 2
s = sum(a)
if (len(a) > med_pos) and (a[med_pos] < y):
print(-1)
exit(0)
if s + (n-k) > x:
print(-1)
exit(0)
ind = -1
for i in range(len(a)):
if a[i] >= y:
ind = i
break
if ind == -1:
ind = len(a)
left = min(n - k, med_pos - ind)
right = max(0, n - k - left)
if s + left + y * right > x:
print(-1)
exit(0)
for i in range(left):
print(1, end = ' ')
for i in range(right):
print(y, end = ' ')
``` | output | 1 | 61,858 | 17 | 123,717 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1". | instruction | 0 | 61,859 | 17 | 123,718 |
Tags: greedy, implementation
Correct Solution:
```
def main():
n, k, p, x, y = map(int, input().split())
L = list(map(int, input().split()))
[L.append(y) for _ in range(n-k)]
cnt = 0
for i in range(n):
if L[i] >= y:
cnt += 1
m = (n+1)/2
for i in range(k, n):
if cnt > m:
L[i] = 1
cnt -= 1
if sum(L) > x or cnt < m:
print(-1)
else:
print(" ".join(map(str, L[k:])))
if __name__ == '__main__':
main()
``` | output | 1 | 61,859 | 17 | 123,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1". | instruction | 0 | 61,860 | 17 | 123,720 |
Tags: greedy, implementation
Correct Solution:
```
n, k, p, x, y=map(int, input().split())
s=list(map(int, input().split()))
s=sorted(s)
if p<y:
print(-1)
else:
kol=0
summ=0
for i in s: #������� ����� � ���������� ������� ��� y
summ+=i
if i>=y:
kol+=1
if k-kol>=n//2+1 or summ > x: #���� ������� �������� ������ y
print(-1)#, '!1')
elif kol>=n//2+1: #���� ������� �������� ������ y
if summ+n-k <=x:
print('1 '*(n-k))
else:
print(-1)#, '!2')
else: #���������� � ������� �����
#print('!!!', summ, y*(n//2+1-kol), n-k-n//2-1+kol, kol)
if summ+y*(n//2+1-kol)+(n-k-n//2-1+kol)>x:
print(-1)#, '!3')
else:
for i in range(n//2+1-kol):
print(y, end=' ')
for i in range(n-k-n//2-1+kol):
print('1', end = ' ')
``` | output | 1 | 61,860 | 17 | 123,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1". | instruction | 0 | 61,861 | 17 | 123,722 |
Tags: greedy, implementation
Correct Solution:
```
n, k, p, x, y = map(int, input().split())
a = list(map(int, input().split()))
t = 0 # кол-во чисел, меньших y
for i in a:
if i < y:
t += 1
m = (n+1)//2
if t >= m:
print(-1)
else:
ans = []
ans += [y]*max(0, m-(k-t))
k += max(0, m-(k-t))
ans += [1]*max(0, n-k)
if sum(ans)+sum(a) <= x:
for i in ans[:-1]:
print(i, end = ' ')
print(ans[-1])
else:
print(-1)
``` | output | 1 | 61,861 | 17 | 123,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1". | instruction | 0 | 61,862 | 17 | 123,724 |
Tags: greedy, implementation
Correct Solution:
```
n, k, p, x, y = map(int,input().split())
s = 0
kol = 0
sp = []
st = input().split()
for i in range(k):
s += int(st[i])
if int(st[i]) < y:
kol+=1
if (kol >= (n + 1)//2):
print(-1)
else:
if (k - kol) < (n + 1)//2:
for i in range(n - k - ((n+1)//2 - k + kol)):
sp.append(1)
s += 1
for i in range((n+1)//2 - k + kol):
sp.append(y)
s += y
else:
for i in range(n - k):
sp.append(1)
s += 1
if s > x:
print(-1)
else:
for j in range(n - k):
print(sp[j], end = ' ')
``` | output | 1 | 61,862 | 17 | 123,725 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1". | instruction | 0 | 61,863 | 17 | 123,726 |
Tags: greedy, implementation
Correct Solution:
```
__author__ = 'emcenrue'
#n, k, p, x, y
#n: total tests to write
#k: total tests he has already written
#p: max score for a test
#x: max total points; if his total score is greater, then -1
#y: minimum median; if median is lower than this then -1
n, k, p, x, y = map(int, input().split())
totScore = 0
atMed = 0
belowMed = 0
scoresToPrint = list()
curScores = list(map(int, input().split()))
for score in curScores:
if score >= y:
atMed += 1
else:
belowMed += 1
while len(curScores) < n:
if belowMed >= atMed:
curScores.append(y)
scoresToPrint.append(y)
atMed += 1
else:
curScores.append(1)
scoresToPrint.append(1)
belowMed += 1
# alternate test scores between median and 1 (store these in a list)
curScores.sort()
if sum(curScores) > x or curScores[int(((n+1)/2)-1)] < y:
print("-1")
else:
print(' '.join(map(str, scoresToPrint)))
#print(sum(curScores))
#print(scoresToPrint)
# if the total is > x then -1
# sort the list, if the median < y then -1
# otherwise print out the list of your own stuff
``` | output | 1 | 61,863 | 17 | 123,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1".
Submitted Solution:
```
n, k, p, x, y = map(int, input().split())
s = list(map(int, input().split()))
m = (n + 2 - 1) // 2
count = 0
for i in range(len(s)):
if s[i] < y:
count += 1
ans = []
if n - k > m - count - 1:
ans += (m - count - 1) * [1]
if 0 < n - len(ans) - len(s):
ans += (n - len(ans) - len(s)) * [y]
else:
ans += (n - k) * [1]
if 0 < n - len(ans) - len(s):
ans += (n - len(ans) - len(s)) * [y]
p = sorted(s + ans)
if sum(s) + sum(ans) > x or p[m - 1] < y:
print(-1)
else:
print(*ans)
``` | instruction | 0 | 61,864 | 17 | 123,728 |
Yes | output | 1 | 61,864 | 17 | 123,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1".
Submitted Solution:
```
n, k, p, x , y=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
A=a.copy()
if k==0:
for i in range(n//2):
a.append(1)
for i in range(n//2+1):
a.append(y)
if sum(a)>x:
print(-1)
else:
print(*a)
elif k>=(n+1)//2:
if a[n//2]<y:
print(-1)
exit()
else:
while a[n//2]>=y and len(a)!=n+1:
a=[1]+a
a=a[1:]
for i in range(n-len(a)):
a.append(y)
if sum(a)>x:
print(-1)
else:
for i in A:
a.remove(i)
print(*a)
else:
if a[-1]<y:
a.append(y)
while len(a)<(n+1)//2:
a=[1]+a
while a[n//2]>=y and len(a)!=n+1:
a=[1]+a
a=a[1:]
for i in range(n-len(a)):
a.append(y)
if sum(a)>x:
print(-1)
else:
for i in A:
a.remove(i)
print(*a)
``` | instruction | 0 | 61,865 | 17 | 123,730 |
Yes | output | 1 | 61,865 | 17 | 123,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
Input
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
Output
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
Examples
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
Note
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1".
Submitted Solution:
```
s=input()
n,k,p,x,y=s.split()
n,k,p,x,y=int(n),int(k),int(p),int(x),int(y)
s=input()
a=[]
for i in s.split():
a.append(int(i))
sum=0
l=0
r=0
for i in a:
sum=sum+i
if i>=y: r+=1
else: l+=1
flag=1
b=[]
if sum>=x or l>n//2 or y>p:
flag=0
else:
left=x-sum
for i in range(0,n-k):
if r<n//2+1:
b.append(y)
r+=1
else: b.append(1)
left-=b[i]
if left<0 or r<n//2+1:
flag=0
if flag==1:
for i in range(0,n-k-1):
print(b[i],end=' ')
print(b[n-k-1])
else :
print(-1)
``` | instruction | 0 | 61,866 | 17 | 123,732 |
Yes | output | 1 | 61,866 | 17 | 123,733 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.