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 |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
problem
Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.
In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.
Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.
Example
Input
10
65
100
30
95
Output
68 | instruction | 0 | 29,023 | 17 | 58,046 |
"Correct Solution:
```
i = [int(input()) for i in range(5)]
for j in range(5):
if i[j] < 40:
i[j] = 40
print(sum(i) // 5)
``` | output | 1 | 29,023 | 17 | 58,047 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.
In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.
Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.
Example
Input
10
65
100
30
95
Output
68 | instruction | 0 | 29,024 | 17 | 58,048 |
"Correct Solution:
```
#Aει‘
S = 0
for i in range(5):
s = int(input())
s = max(s,40)
S+=s
print(S//5)
``` | output | 1 | 29,024 | 17 | 58,049 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.
In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.
Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.
Example
Input
10
65
100
30
95
Output
68 | instruction | 0 | 29,025 | 17 | 58,050 |
"Correct Solution:
```
x=[]
for i in range(5):
s=int(input())
if s<40:
s=40
x.append(int(s))
total=sum(x)
ave=total/5
print(int(ave))
``` | output | 1 | 29,025 | 17 | 58,051 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | instruction | 0 | 29,183 | 17 | 58,366 |
Tags: bitmasks, brute force, graphs
Correct Solution:
```
def moins(M,N):
L=[]
for i in M:
if i not in N:
L+=[i]
return L
S=str(input())
l=S.split(" ")
n,m=int(l[0]),int(l[1])
d={}
S=str(input())
L=[S]
for i in range(n-1):
S=str(input())
j,f=0,0
while f==0:
if j==len(L):
L+=[S]
f=1
elif L[j]>S:
L=L[:j]+[S]+L[j:]
f=1
else:
j+=1
T=list(L)
P=[]
for m in range(m):
S=str(input())
l=S.split(" ")
S1,S2=l[0],l[1]
if S1 in d:
d[S1][0]+=1
d[S1]+=[S2]
else:
d[S1]=[1,S2]
T.remove(S1)
P+=[S1]
if S2 in d:
d[S2][0]+=1
d[S2]+=[S1]
else:
d[S2]=[1,S1]
T.remove(S2)
P+=[S2]
m=[]
O=[]
k=0
for i in d:
m+=[[i,moins(P,d[i][1:]+[i])]]
for i in m:
if i[-1]==[]:
if len(i[:-1])>k:
O=i[:-1]
k=len(i[:-1])
for j in i[-1]:
m+=[i[:-1]+[j]+[moins(i[-1],d[j][1:]+[j])]]
for i in O:
if T==[]:
T=[i]
else:
for j in range(len(T)):
if T[j]>i:
T=T[:j]+[i]+T[j:]
break
if j==len(T)-1:
T+=[i]
print(len(T))
for i in T:
print(i)
``` | output | 1 | 29,183 | 17 | 58,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | instruction | 0 | 29,184 | 17 | 58,368 |
Tags: bitmasks, brute force, graphs
Correct Solution:
```
(n, m) = map(int, input().split())
names = []
mp = {}
for i in range(n):
name = input()
mp[name] = i
names.append(name)
mask = [0] * n
for i in range(m):
(a, b) = map(mp.get, input().split())
mask[a] |= (1<<b)
mask[b] |= (1<<a)
ans = 0
result = 0
def bcnt(x):
return 0 if x == 0 else bcnt(x>>1)+(x&1)
for val in range(1<<n):
if bcnt(val) <= ans: continue
valid = True
for i in range(n):
if ((1<<i)&val) and (val&mask[i]):
valid = False
break
if valid:
ans = bcnt(val)
result = val
print(ans)
out = []
for i in range(n):
if (1<<i)&result:
out.append(names[i])
for s in sorted(out):
print(s)
``` | output | 1 | 29,184 | 17 | 58,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | instruction | 0 | 29,185 | 17 | 58,370 |
Tags: bitmasks, brute force, graphs
Correct Solution:
```
ii=lambda:int(input())
kk=lambda:map(int, input().split())
ll=lambda:list(kk())
n,m=kk()
ppl=[input() for _ in range(n)]
others=[set() for _ in range(n)]
for _ in range(m):
a,b=input().split()
a=ppl.index(a)
b=ppl.index(b)
others[a].add(b)
others[b].add(a)
largest = set()
for i in range(2**n):
s = set()
for j in range(n):
if i&(2**j):
if others[j]&s:
break
s.add(j)
else:
if len(s)>len(largest): largest = s
print(len(largest))
print("\n".join(sorted([ppl[x] for x in largest])))
``` | output | 1 | 29,185 | 17 | 58,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | instruction | 0 | 29,186 | 17 | 58,372 |
Tags: bitmasks, brute force, graphs
Correct Solution:
```
#RΓ©cupΓ©ration des donnΓ©es
n_m = input();
n, m = [int(s) for s in n_m.split()];
names = [];
reverse = dict();
entente = [[True] * n for _ in range(n)]
for i in range(n):
name = input();
names.append(name);
reverse[name] = i;
entente[i][i] = False;
for i in range(m):
i1, i2 = [reverse[s] for s in input().split()];
entente[i2][i1] = False;
entente[i1][i2] = False;
#On lance la recherche de la meilleure combinaison
def rec(valides):
best = [[False] * n, 0];
participants_restants = sum(valides)
for i in range(n):
if valides[i] and participants_restants != sum(best[0]):
res_temp = rec([valides[j] and entente[i][j] and j>i for j in range(n)])
if best[1] <= res_temp[1]:
best = res_temp;
best[0][i] = True;
best[1] +=1;
return best;
res = [names[i] for i, b in enumerate(rec([True] * n)[0]) if b];
res.sort();
print(len(res));
for s in res :
print(s);
``` | output | 1 | 29,186 | 17 | 58,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | instruction | 0 | 29,187 | 17 | 58,374 |
Tags: bitmasks, brute force, graphs
Correct Solution:
```
from collections import defaultdict
graph = defaultdict(list)
n,m = list(map(int,input().split()))
d = {}
cnt = 0
for i in range(n):
x = input()
d[x] = cnt
cnt+=1
arr = []
for i in range(m):
u,v = list(map(str,input().split()))
arr.append([u,v])
possibilities = []
for i in range(2**n):
x = bin(i).split('b')[1]
x = '0'*(n-len(x))+x
possibilities.append(x)
ans = []
for i in possibilities:
f = 0
for j in arr:
if i[d[j[0]]]=='1' and i[d[j[1]]]=='1':
f = 1
break
if f==0:
ans.append(i)
k = -1
u = -1
mat = []
for i in ans:
y = i.count('1')
if k<y:
k = y
u = i
# for i in ans:
# if i.count('1')==k:
# mat.append(i)
# print(mat)
# print(k)
for i in range(len(u)):
if u[i]=='1':
for j in d:
if d[j]==i:
mat.append(j)
break
mat.sort()
print(len(mat))
for i in mat:
print(i)
``` | output | 1 | 29,187 | 17 | 58,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | instruction | 0 | 29,188 | 17 | 58,376 |
Tags: bitmasks, brute force, graphs
Correct Solution:
```
from itertools import combinations
def solve():
n, m = map(int, input().split())
name = sorted([input().strip() for i in range(n)])
bad = sorted([sorted(input().strip().split()) for i in range(m)])
# print(name)
# print(bad)
for i in range(n, -1, -1):
temp = sorted(map(sorted, combinations(name, i)))
# print(temp)
for k in temp:
flag = 1
for j in map(sorted, combinations(k, 2)):
# print(j)
if j in bad:
flag = 0
break
if flag:
return k
x = solve()
print(len(x))
print(*x, sep='\n')
``` | output | 1 | 29,188 | 17 | 58,377 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | instruction | 0 | 29,189 | 17 | 58,378 |
Tags: bitmasks, brute force, graphs
Correct Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, sqrt, trunc, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
def on(a):
i = n
cnt = []
while i >= 0:
if a & (1 << i):
cnt.append(i)
i -= 1
return cnt
def check(arr, index):
for i in arr:
if names[i] in graph[names[index]] or names[index] in graph[names[i]]:
return False
return True
def recur(i=0, mask=0):
global answer
if i == n:
temp = on(mask)
if len(temp) > len(answer):
answer = temp
return
if mask & (1 << i):
return
temp = on(mask)
if check(temp, i):
recur(i+1, mask | (1 << i))
recur(i+1, mask)
n, m = sp()
graph = dd(set)
names = []
for i in range(n):
names.append(data())
for i in range(m):
u, v = ssp()
graph[u].add(v)
graph[v].add(u)
answer = []
recur()
out(len(answer))
for i in range(len(answer)):
answer[i] = names[answer[i]]
for i in sorted(answer):
out(i)
``` | output | 1 | 29,189 | 17 | 58,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | instruction | 0 | 29,190 | 17 | 58,380 |
Tags: bitmasks, brute force, graphs
Correct Solution:
```
# maa chudaaye duniya
from collections import defaultdict
graph = defaultdict(list)
n,m = list(map(int,input().split()))
d = {}
cnt = 0
for i in range(n):
x = input()
d[x] = cnt
cnt+=1
arr = []
for i in range(m):
u,v = list(map(str,input().split()))
arr.append([u,v])
possibilities = []
for i in range(2**n):
x = bin(i).split('b')[1]
x = '0'*(n-len(x))+x
possibilities.append(x)
ans = []
for i in possibilities:
f = 0
for j in arr:
if i[d[j[0]]]=='1' and i[d[j[1]]]=='1':
f = 1
break
if f==0:
ans.append(i)
k = -1
u = -1
mat = []
for i in ans:
y = i.count('1')
if k<y:
k = y
u = i
for i in range(len(u)):
if u[i]=='1':
for j in d:
if d[j]==i:
mat.append(j)
break
mat.sort()
print(len(mat))
for i in mat:
print(i)
``` | output | 1 | 29,190 | 17 | 58,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Submitted Solution:
```
def good(a,bad):
for i in bad:
if (i[0]in a) and (i[1] in a):
return False
return True
def f(arr,bad,d):
n=len(arr)
mask=0
ans=[]
while mask<1<<n:
temp=[]
for i in range(len(arr)):
if mask &(1<<i):
temp.append(i)
if good(temp,bad):
ans.append(temp)
mask+=1
mx=max(ans,key=lambda s:len(s))
print(len(mx))
for i in mx:
print(arr[i])
return ""
a,b=map(int,input().strip().split())
blanck=[]
for i in range(a):
blanck.append(input())
d={}
blanck=sorted(blanck)
for i in range(len(blanck)):
d[blanck[i]]=i
bad=[]
for i in range(b):
x,y=map(str,input().strip().split())
k=sorted((d[x],d[y]))
bad.append(k)
print(f(blanck,bad,d))
``` | instruction | 0 | 29,191 | 17 | 58,382 |
Yes | output | 1 | 29,191 | 17 | 58,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Submitted Solution:
```
import itertools as it
n, m = map(int, input().split())
edges = set()
friends_M = {}
for i in range(n):
friends_M[input()] = i
for _ in range(m):
a, b = input().split()
a, b = friends_M[a], friends_M[b]
edges.add((a, b))
edges.add((b, a))
best = 0
best_vals = []
for subset in it.product([0, 1], repeat=n):
ss = list(it.compress(range(n), subset))
good = True
for i in range(len(ss)):
for j in range(i + 1, len(ss)):
if (ss[i], ss[j]) in edges:
good = False
if good:
if len(ss) > best:
best = len(ss)
best_vals = ss
print(best)
res = []
for i in range(len(best_vals)):
for j, k in friends_M.items():
if k == best_vals[i]:
res += [j]
break
for name in sorted(res):
print(name)
``` | instruction | 0 | 29,192 | 17 | 58,384 |
Yes | output | 1 | 29,192 | 17 | 58,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Submitted Solution:
```
n,m=map(int,input().split())
names=[]
for i in range(n):
names.append(input())
hate=[]
for i in range(m):
hate.append(list(input().split()))
ans=set()
for x in range(1,(1<<n)+1):
a=set()
for i in range(n):
if x & (1<<i):
a.add(names[i])
flag=True
for b in hate:
if b[0] in a and b[1] in a:
flag=False
break
if flag:
if len(a)>len(ans):
ans=a
print(len(ans))
print(*sorted(list(ans)),sep="\n")
``` | instruction | 0 | 29,193 | 17 | 58,386 |
Yes | output | 1 | 29,193 | 17 | 58,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Submitted Solution:
```
n,m=map(int,input().split())
d1={}
d2={}
arr=[]
for i in range(n):
s=input()
d1[s]=i
arr.append([])
d2[i]=str(s)
for i in range(m):
a,b=input().split()
arr[d1[a]].append(d1[b])
arr[d1[b]].append(d1[a])
from copy import deepcopy
ans=[]
def dp(n,i,f,e):
global ans
if(i==n):
if(len(f)>len(ans)):
ans=list(f)
return
dp(n,i+1,f,e)
if(i not in e):
dp(n,i+1,f+[i],e+arr[i])
dp(n,0,[],[])
print(len(ans))
for i in range(len(ans)):
ans[i]=d2[ans[i]]
ans.sort()
for i in ans:
print(i)
``` | instruction | 0 | 29,194 | 17 | 58,388 |
Yes | output | 1 | 29,194 | 17 | 58,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Submitted Solution:
```
(n, m) = map(int, input().split())
names = []
mp = {}
for i in range(n):
name = input()
mp[name] = i
names.append(name)
mask = [0] * n
for i in range(m):
(a, b) = map(mp.get, input().split())
mask[a] |= (1<<b)
mask[b] |= (1<<a)
ans = 0
result = 0
def bcnt(x):
return 0 if x == 0 else bcnt(x>>1)+(x&1)
for val in range(1<<n):
if bcnt(val) <= ans: continue
valid = True
for i in range(n):
if ((1<<i)&val) and (val&mask[i]):
valid = False
break
if valid:
ans = bcnt(val)
result = val
print(ans)
for i in range(n):
if (1<<i)&result:
print(names[i])
``` | instruction | 0 | 29,195 | 17 | 58,390 |
No | output | 1 | 29,195 | 17 | 58,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Submitted Solution:
```
def printable(volunteers):
volunteers.sort()
print(len(volunteers))
for i in volunteers:
print(i)
def main():
n,m = input().strip().split(' ')
volunteers = []
conflicts = []
tmp = 0
while tmp < int(n):
volunteers.append(input().strip())
tmp += 1
tmp = 0
while tmp < int(m):
conflicts.append(input())
tmp += 1
final = []
if int(m) == 0:
printable(volunteers)
else:
for i in volunteers:
l_tmp = [x for x in conflicts if i in x]
# print(l_tmp)
if len(l_tmp) == 0:
final.append(i)
printable(final)
if __name__ == "__main__":
main()
``` | instruction | 0 | 29,196 | 17 | 58,392 |
No | output | 1 | 29,196 | 17 | 58,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Submitted Solution:
```
from itertools import combinations
from copy import deepcopy
def check(l):
for i,j in enemy.items():
if i in l and j in l:
return False
return True
n , m = map(int , input().split())
names = []
for i in range(n):
names.append(input())
enemy = {}
for i in range(m):
s1,s2 = input().split()
enemy[s1] = s2
enemy[s2] = s1
ans = []
for i in range(2,n+1):
for j in combinations(names,i):
if check(j):
if len(ans) < len(j):
ans = deepcopy(j)
print(len(ans))
aaa = sorted(ans)
for i in aaa:
print(i)
``` | instruction | 0 | 29,197 | 17 | 58,394 |
No | output | 1 | 29,197 | 17 | 58,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Submitted Solution:
```
import math
from operator import itemgetter
var=input("")
var=var.split(" ")
n=int(var[0])
m=int(var[1])
L=[]
for i in range(n):
name=input("")
L.append(name)
if m==0:
L.sort()
print(len(L))
for i in range(len(L)):
print(L[i])
else:
d={}
K=[]
L1=[]
for i in range(m):
pair=input("")
pair=pair.split(" ")
K.append(pair)
A=pair[0]
B=pair[1]
if A in d.keys():
d[A]+=1
else:
d[A]=1
if B in d.keys():
d[B]+=1
else:
d[B]=1
for x in L:
if x not in d.keys():
L1.append(x)
while K!=[] and max(list(d.values()))>0:
l=list(d.items())
l.sort(key=itemgetter(1),reverse=True)
x=l[0][0]
del d[x]
i=0
while i<len(K):
if K[i][0]==x:
if K[i][1] in d.keys():
d[K[i][1]]=d[K[i][1]]-1
K.remove(K[i])
i=i-1
elif K[i][1]==x:
if K[i][0] in d.keys():
d[K[i][0]]=d[K[i][0]]-1
K.remove(K[i])
i=i-1
i=i+1
Z=list(d.keys())
L1=L1+Z
L1.sort()
print(len(L1))
for i in L1:
print(i)
``` | instruction | 0 | 29,198 | 17 | 58,396 |
No | output | 1 | 29,198 | 17 | 58,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
There used to be a game called Joseph's potatoes. Let's say n people are participating. Participants form a circle facing the center and are numbered starting from 1. One hot potato is given to participant n (the large number 30 inside the figure on the left). Participants who are given the potatoes will give the potatoes to the participant on the right. The person passed the mth time is passed to the person on the right and exits the circle (the figure on the left shows the case of m = 9). Each time you hand it over, you will pass one by one, and the last remaining person will be the winner and you will receive potatoes.
After n and m are decided, it would be nice to know where you can win before you actually start handing the potatoes. The figure above shows the case of playing this game with the rule that 30 participants exit every 9 people. The large numbers on the inside are the numbers assigned to the participants, and the small numbers on the outside are the numbers that are removed. According to it, it will break out of the circle in the order of 9,18,27,6,16,26, and 21 will remain at the end. That is, 21 is the winner (the smaller number is 30).
Enter the number of game participants n and the interval m between the participants who break out of the circle, and create a program that outputs the winner's number. However, m, n <1000.
input
Given multiple datasets. Each dataset is given in the following format:
n m
The number of game participants n (integer) and the interval m (integer) between the participants who break out of the circle are given on one line separated by blanks.
The input ends with two 0s. The number of datasets does not exceed 50.
output
For each dataset, output the number (integer) of the winner and the person who will receive the potatoes on one line.
Example
Input
41 3
30 9
0 0
Output
31
21
Submitted Solution:
```
while True:
n, m = map(int, input().split())
if n == 0:
break
lst = [1]*n
a = 0
b = 0
c = 0
while b < n-1:
a += lst[c%n]
if a == m:
a = 0
lst[c%n] = 0
b +=1
c += 1
print(lst.index(1)+1)
``` | instruction | 0 | 30,855 | 17 | 61,710 |
Yes | output | 1 | 30,855 | 17 | 61,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
There used to be a game called Joseph's potatoes. Let's say n people are participating. Participants form a circle facing the center and are numbered starting from 1. One hot potato is given to participant n (the large number 30 inside the figure on the left). Participants who are given the potatoes will give the potatoes to the participant on the right. The person passed the mth time is passed to the person on the right and exits the circle (the figure on the left shows the case of m = 9). Each time you hand it over, you will pass one by one, and the last remaining person will be the winner and you will receive potatoes.
After n and m are decided, it would be nice to know where you can win before you actually start handing the potatoes. The figure above shows the case of playing this game with the rule that 30 participants exit every 9 people. The large numbers on the inside are the numbers assigned to the participants, and the small numbers on the outside are the numbers that are removed. According to it, it will break out of the circle in the order of 9,18,27,6,16,26, and 21 will remain at the end. That is, 21 is the winner (the smaller number is 30).
Enter the number of game participants n and the interval m between the participants who break out of the circle, and create a program that outputs the winner's number. However, m, n <1000.
input
Given multiple datasets. Each dataset is given in the following format:
n m
The number of game participants n (integer) and the interval m (integer) between the participants who break out of the circle are given on one line separated by blanks.
The input ends with two 0s. The number of datasets does not exceed 50.
output
For each dataset, output the number (integer) of the winner and the person who will receive the potatoes on one line.
Example
Input
41 3
30 9
0 0
Output
31
21
Submitted Solution:
```
while 1:
n,m=map(int,input().split())
if n==0:break
a=m-1
while a<m*n-n:a=m*a//(m-1)+1
print(n*m-a)
``` | instruction | 0 | 30,856 | 17 | 61,712 |
Yes | output | 1 | 30,856 | 17 | 61,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
There used to be a game called Joseph's potatoes. Let's say n people are participating. Participants form a circle facing the center and are numbered starting from 1. One hot potato is given to participant n (the large number 30 inside the figure on the left). Participants who are given the potatoes will give the potatoes to the participant on the right. The person passed the mth time is passed to the person on the right and exits the circle (the figure on the left shows the case of m = 9). Each time you hand it over, you will pass one by one, and the last remaining person will be the winner and you will receive potatoes.
After n and m are decided, it would be nice to know where you can win before you actually start handing the potatoes. The figure above shows the case of playing this game with the rule that 30 participants exit every 9 people. The large numbers on the inside are the numbers assigned to the participants, and the small numbers on the outside are the numbers that are removed. According to it, it will break out of the circle in the order of 9,18,27,6,16,26, and 21 will remain at the end. That is, 21 is the winner (the smaller number is 30).
Enter the number of game participants n and the interval m between the participants who break out of the circle, and create a program that outputs the winner's number. However, m, n <1000.
input
Given multiple datasets. Each dataset is given in the following format:
n m
The number of game participants n (integer) and the interval m (integer) between the participants who break out of the circle are given on one line separated by blanks.
The input ends with two 0s. The number of datasets does not exceed 50.
output
For each dataset, output the number (integer) of the winner and the person who will receive the potatoes on one line.
Example
Input
41 3
30 9
0 0
Output
31
21
Submitted Solution:
```
while True:
n,m = input().split()
n = int(n)
m = int(m)
if n==m==0:
break
l = [i for i in range(n)]
c = -1
while len(l) >= 2:
c = (c+m)%len(l)
l.pop(c)
c -= 1
print(l[0]+1)
``` | instruction | 0 | 30,857 | 17 | 61,714 |
Yes | output | 1 | 30,857 | 17 | 61,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
There used to be a game called Joseph's potatoes. Let's say n people are participating. Participants form a circle facing the center and are numbered starting from 1. One hot potato is given to participant n (the large number 30 inside the figure on the left). Participants who are given the potatoes will give the potatoes to the participant on the right. The person passed the mth time is passed to the person on the right and exits the circle (the figure on the left shows the case of m = 9). Each time you hand it over, you will pass one by one, and the last remaining person will be the winner and you will receive potatoes.
After n and m are decided, it would be nice to know where you can win before you actually start handing the potatoes. The figure above shows the case of playing this game with the rule that 30 participants exit every 9 people. The large numbers on the inside are the numbers assigned to the participants, and the small numbers on the outside are the numbers that are removed. According to it, it will break out of the circle in the order of 9,18,27,6,16,26, and 21 will remain at the end. That is, 21 is the winner (the smaller number is 30).
Enter the number of game participants n and the interval m between the participants who break out of the circle, and create a program that outputs the winner's number. However, m, n <1000.
input
Given multiple datasets. Each dataset is given in the following format:
n m
The number of game participants n (integer) and the interval m (integer) between the participants who break out of the circle are given on one line separated by blanks.
The input ends with two 0s. The number of datasets does not exceed 50.
output
For each dataset, output the number (integer) of the winner and the person who will receive the potatoes on one line.
Example
Input
41 3
30 9
0 0
Output
31
21
Submitted Solution:
```
# AOJ 0085 Joseph's Potato
# Python3 2018.6.15 bal4u
while True:
n, m = map(int, input().split())
if n == 0:
break
k = 1;
for j in range(2, n+1):
k = (k + m) % j
if k == 0: k = j
print(k)
``` | instruction | 0 | 30,858 | 17 | 61,716 |
Yes | output | 1 | 30,858 | 17 | 61,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
There used to be a game called Joseph's potatoes. Let's say n people are participating. Participants form a circle facing the center and are numbered starting from 1. One hot potato is given to participant n (the large number 30 inside the figure on the left). Participants who are given the potatoes will give the potatoes to the participant on the right. The person passed the mth time is passed to the person on the right and exits the circle (the figure on the left shows the case of m = 9). Each time you hand it over, you will pass one by one, and the last remaining person will be the winner and you will receive potatoes.
After n and m are decided, it would be nice to know where you can win before you actually start handing the potatoes. The figure above shows the case of playing this game with the rule that 30 participants exit every 9 people. The large numbers on the inside are the numbers assigned to the participants, and the small numbers on the outside are the numbers that are removed. According to it, it will break out of the circle in the order of 9,18,27,6,16,26, and 21 will remain at the end. That is, 21 is the winner (the smaller number is 30).
Enter the number of game participants n and the interval m between the participants who break out of the circle, and create a program that outputs the winner's number. However, m, n <1000.
input
Given multiple datasets. Each dataset is given in the following format:
n m
The number of game participants n (integer) and the interval m (integer) between the participants who break out of the circle are given on one line separated by blanks.
The input ends with two 0s. The number of datasets does not exceed 50.
output
For each dataset, output the number (integer) of the winner and the person who will receive the potatoes on one line.
Example
Input
41 3
30 9
0 0
Output
31
21
Submitted Solution:
```
while True:
n, m = map(int, input().split())
if n==0: break
p, i = [i+1 for i in range(n)], m
while True:
p.pop(m-1)
if len(p)==1:
print(p[0])
break
tmp = m+i-1
m = tmp%len(p) if tmp>len(p) else tmp
``` | instruction | 0 | 30,859 | 17 | 61,718 |
No | output | 1 | 30,859 | 17 | 61,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
There used to be a game called Joseph's potatoes. Let's say n people are participating. Participants form a circle facing the center and are numbered starting from 1. One hot potato is given to participant n (the large number 30 inside the figure on the left). Participants who are given the potatoes will give the potatoes to the participant on the right. The person passed the mth time is passed to the person on the right and exits the circle (the figure on the left shows the case of m = 9). Each time you hand it over, you will pass one by one, and the last remaining person will be the winner and you will receive potatoes.
After n and m are decided, it would be nice to know where you can win before you actually start handing the potatoes. The figure above shows the case of playing this game with the rule that 30 participants exit every 9 people. The large numbers on the inside are the numbers assigned to the participants, and the small numbers on the outside are the numbers that are removed. According to it, it will break out of the circle in the order of 9,18,27,6,16,26, and 21 will remain at the end. That is, 21 is the winner (the smaller number is 30).
Enter the number of game participants n and the interval m between the participants who break out of the circle, and create a program that outputs the winner's number. However, m, n <1000.
input
Given multiple datasets. Each dataset is given in the following format:
n m
The number of game participants n (integer) and the interval m (integer) between the participants who break out of the circle are given on one line separated by blanks.
The input ends with two 0s. The number of datasets does not exceed 50.
output
For each dataset, output the number (integer) of the winner and the person who will receive the potatoes on one line.
Example
Input
41 3
30 9
0 0
Output
31
21
Submitted Solution:
```
while 1:
n,m=list(map(int,input().split()))
if n==0 and m==0:break
l=range(1,1+n)
st=m-1
while len(l)!=1:
del l[st]
st+=(m-1)
while 1:
if st>=len(l):
st=st-len(l)
if st<len(l):break
print(l[0])
``` | instruction | 0 | 30,860 | 17 | 61,720 |
No | output | 1 | 30,860 | 17 | 61,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
There used to be a game called Joseph's potatoes. Let's say n people are participating. Participants form a circle facing the center and are numbered starting from 1. One hot potato is given to participant n (the large number 30 inside the figure on the left). Participants who are given the potatoes will give the potatoes to the participant on the right. The person passed the mth time is passed to the person on the right and exits the circle (the figure on the left shows the case of m = 9). Each time you hand it over, you will pass one by one, and the last remaining person will be the winner and you will receive potatoes.
After n and m are decided, it would be nice to know where you can win before you actually start handing the potatoes. The figure above shows the case of playing this game with the rule that 30 participants exit every 9 people. The large numbers on the inside are the numbers assigned to the participants, and the small numbers on the outside are the numbers that are removed. According to it, it will break out of the circle in the order of 9,18,27,6,16,26, and 21 will remain at the end. That is, 21 is the winner (the smaller number is 30).
Enter the number of game participants n and the interval m between the participants who break out of the circle, and create a program that outputs the winner's number. However, m, n <1000.
input
Given multiple datasets. Each dataset is given in the following format:
n m
The number of game participants n (integer) and the interval m (integer) between the participants who break out of the circle are given on one line separated by blanks.
The input ends with two 0s. The number of datasets does not exceed 50.
output
For each dataset, output the number (integer) of the winner and the person who will receive the potatoes on one line.
Example
Input
41 3
30 9
0 0
Output
31
21
Submitted Solution:
```
n, m = map(int, input().split())
p, i = [i+1 for i in range(n)], m
while True:
p.pop(m-1)
if len(p)==1:
print(p[0])
break
tmp = m+i-1
m = tmp%len(p) if tmp>len(p) else tmp
``` | instruction | 0 | 30,861 | 17 | 61,722 |
No | output | 1 | 30,861 | 17 | 61,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
There used to be a game called Joseph's potatoes. Let's say n people are participating. Participants form a circle facing the center and are numbered starting from 1. One hot potato is given to participant n (the large number 30 inside the figure on the left). Participants who are given the potatoes will give the potatoes to the participant on the right. The person passed the mth time is passed to the person on the right and exits the circle (the figure on the left shows the case of m = 9). Each time you hand it over, you will pass one by one, and the last remaining person will be the winner and you will receive potatoes.
After n and m are decided, it would be nice to know where you can win before you actually start handing the potatoes. The figure above shows the case of playing this game with the rule that 30 participants exit every 9 people. The large numbers on the inside are the numbers assigned to the participants, and the small numbers on the outside are the numbers that are removed. According to it, it will break out of the circle in the order of 9,18,27,6,16,26, and 21 will remain at the end. That is, 21 is the winner (the smaller number is 30).
Enter the number of game participants n and the interval m between the participants who break out of the circle, and create a program that outputs the winner's number. However, m, n <1000.
input
Given multiple datasets. Each dataset is given in the following format:
n m
The number of game participants n (integer) and the interval m (integer) between the participants who break out of the circle are given on one line separated by blanks.
The input ends with two 0s. The number of datasets does not exceed 50.
output
For each dataset, output the number (integer) of the winner and the person who will receive the potatoes on one line.
Example
Input
41 3
30 9
0 0
Output
31
21
Submitted Solution:
```
while True:
n,m = input().split()
n = int(n)
m = int(m)
if n==m==0:
break
l = [i for i in range(n)]
c = 0
while len(l) >= 2:
c = (c+m)%len(l)
l.pop(c)
c -= 1
print(l[0])
``` | instruction | 0 | 30,862 | 17 | 61,724 |
No | output | 1 | 30,862 | 17 | 61,725 |
Provide a correct Python 3 solution for this coding contest problem.
This year too, the time has come for the National Programming Championships. In the district tournament where the right to participate in the national tournament is bet, 2n teams will face each other in a one-on-one winning tournament system.
Team numbers 0, .. .2n β 1 are assigned to the tournament table, and the confrontation procedure from the first round to the nth round is as follows.
1. In the first round, (team with team number l) and (team with team number l + 1) will face each other. (l β‘ 0 (mod 2))
2. In the i + 1st round (1 β€ i <n), "the team whose team number is l or more and less than l + 2i who has not lost even once in the confrontation up to the i round" and "the team number is l" Of the teams with + 2i or more and less than l + 2i + 1, the team that has never lost in the confrontation up to the i round will confront. (l β‘ 0 (mod 2i + 1))
After the nth round, the ranking of each team is fixed at 2n β (the number of times that team has won). Since there is no draw in this confrontation, one of the confronting teams wins and the other loses.
As we were selected to represent the district conference on a sunny day, we decided to have the manager examine the results of other district conferences. The result of the examination here was the "ranking table received from the manager". To explain the "ranking table received from the manager" in more detail, the ranking of the team with team number i is written in the i (0 β€ i β€ 2n β 1) th element in a sequence of length 2n. ..
However, the "stands received from the manager" had a large number of the same rankings! Due to the rules of the tournament, it is unlikely that the same ranking will be lined up in large numbers. Therefore, let's calculate the minimum number of teams to change the ranking in order to make the "standings received from the manager" a "consistent standings" and tell the manager how wrong the standings are. A "consistent standings" is a standings that can occur as a result of a tournament with a fixed ranking.
Input
The "ranking table received from the manager" is given to the input in the following format.
n m
a0 a1 .. .am
b0 b1 ... bmβ1
* The first line consists of two integers, n and m, where 2n is the "number of participating teams in the district tournament" and m is the "number of sections in which consecutive rankings are lined up in the" standings received from the manager "". Represents.
* The second line consists of m + 1 integers of ai (0 β€ i β€ m), and each ai represents "the division position of the section where consecutive rankings are lined up in the'ranking table received from the manager'". ..
* The third line consists of m integers of bi (0 β€ i <m), and each 2bi represents "the ranking of teams whose team numbers are greater than or equal to ai and less than ai + 1 in the standings received from the manager". ..
Constraints
* 1 β€ n β€ 30
* 1 β€ m β€ 10,000
* 0 = a0 <a1 β€ ... β€ amβ1 <am = 2n
* 0 β€ bi β€ n
Output
Output the minimum number of teams to change the ranking in one line so that the "standings received from the manager" becomes a "consistent standings".
Sample Input 1
1 1
0 2
1
Output for the Sample Input 1
1
There are two "consistent standings" with 2 participating teams: {"ranking of teams with team number 0" and "ranking of teams with team number 1"}, {1, 2} and {2, 1}. There is. In order to modify the standings {2, 2} to a "consistent standings", the ranking of one of the teams must be changed to 1.
Sample Input 2
twenty three
0 1 2 4
0 1 2
Output for the Sample Input 2
2
Sample Input 3
twenty three
0 1 3 4
0 2 1
Output for the Sample Input 3
0
Sample Input 4
4 5
0 1 2 4 8 16
0 1 2 3 4
Output for the Sample Input 4
Ten
Example
Input
1 1
0 2
1
Output
1 | instruction | 0 | 31,752 | 17 | 63,504 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, M = map(int, readline().split())
*A, = map(int, readline().split())
*B, = map(int, readline().split())
C = []
prv = 0
for i in range(M):
C.append((A[i+1] - prv, 1 << B[i]))
prv = A[i+1]
ans = 0
for i in range(N-1, -1, -1):
v = 1 << (i+1)
C1 = []
r = 0; p = 0
for c, b in C:
if r:
if (b & v) == (p & v) > 0:
b0 = b | p
elif b & v:
b0 = p
elif p & v:
b0 = b
else:
b0 = b | p
ans += 1
if C1 and C1[-1][1] == b0:
c1, b1 = C1.pop()
C1.append((1+c1, b0))
else:
C1.append((1, b0))
c -= 1
if c > 1:
if b & v == 0:
ans += c // 2
if C1 and C1[-1][1] == b:
c1, b1 = C1.pop()
C1.append((c//2+c1, b))
else:
C1.append((c//2, b))
if c % 2:
r = 1; p = b
else:
r = 0
C = C1
c, p = C[0]
if p & 1 == 0:
ans += 1
write("%d\n" % ans)
solve()
``` | output | 1 | 31,752 | 17 | 63,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image> | instruction | 0 | 32,601 | 17 | 65,202 |
Tags: dp
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = list(zip(a,b))
dp = [[None,None] for i in range(n)]
dp[n-1][0] = a[n-1][0]
dp[n-1][1] = a[n-1][1]
for i in range(n-2,-1,-1):
if a[i][0] + dp[i+1][1]>dp[i+1][0]:
dp[i][0] = a[i][0] + dp[i+1][1]
else:
dp[i][0] = dp[i+1][0]
if a[i][1] + dp[i+1][0]>dp[i+1][1]:
dp[i][1] = a[i][1] + dp[i+1][0]
else:
dp[i][1] = dp[i+1][1]
print(max(dp[0][0],dp[0][1]))
``` | output | 1 | 32,601 | 17 | 65,203 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image> | instruction | 0 | 32,602 | 17 | 65,204 |
Tags: dp
Correct Solution:
```
def solve():
n = int(input())
h = [[0 for i in range(n)], [0 for i in range(n)]]
h[0] = list(map(int, input().split()))
h[1] = list(map(int, input().split()))
dp = [[0, 0] for i in range(n)]
for i in range(n):
if i == 0:
dp[i][0] = h[0][0]
dp[i][1] = h[1][0]
continue
for j in range(2):
# don't peak i
dp[i][j] = dp[i - 1][j]
# peak i
dp[i][j] = max(dp[i][j], h[j][i] + dp[i - 1][1 - j]);
print(max(dp[n - 1][0], dp[n - 1][1]))
if __name__ == '__main__':
solve()
``` | output | 1 | 32,602 | 17 | 65,205 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image> | instruction | 0 | 32,603 | 17 | 65,206 |
Tags: dp
Correct Solution:
```
n=int(input())
a1=[int(x) for x in input().split()]
a2=[int(x) for x in input().split()]
dp=[[0 for i in range(n)] for j in range(2)]
dp[0][n-1]=a1[n-1]
dp[1][n-1]=a2[n-1]
if(n>1):
dp[0][n-2]=a1[n-2]+a2[n-1]
dp[1][n-2]=a2[n-2]+a1[n-1]
for i in range(n-3,-1,-1):
dp[0][i]=a1[i]+max(dp[1][i+1],dp[1][i+2])
dp[1][i]=a2[i]+max(dp[0][i+1],dp[0][i+2])
print(max(dp[0][0],dp[1][0]))
``` | output | 1 | 32,603 | 17 | 65,207 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image> | instruction | 0 | 32,604 | 17 | 65,208 |
Tags: dp
Correct Solution:
```
import sys
from collections import deque
IS_LOCAL = False
def read_one(dtype=int):
return dtype(input())
def read_multiple(f, dtype=int):
return f(map(dtype, input().split()))
def swap(x, y):
return y, x
def main():
n = 5
a = [
[9, 3, 5, 7, 3],
[5, 8, 1, 4, 5]
]
if not IS_LOCAL:
n = read_one()
a = [
read_multiple(list),
read_multiple(list)
]
m = [0, 0]
for i in range(n):
t0 = max(m[1] + a[0][i], m[0])
t1 = max(m[0] + a[1][i], m[1])
m = [t0, t1]
print(max(m))
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == 'True':
IS_LOCAL = True
main()
``` | output | 1 | 32,604 | 17 | 65,209 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image> | instruction | 0 | 32,605 | 17 | 65,210 |
Tags: dp
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
max0, max1 = 0, 0
for i in range(n): max0, max1 = max(max0, a[i]+max1), max(max1, b[i]+max0)
print(max(max0, max1))
``` | output | 1 | 32,605 | 17 | 65,211 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image> | instruction | 0 | 32,606 | 17 | 65,212 |
Tags: dp
Correct Solution:
```
n = int(input())
h1 = list(map(int, input().split()))
h2 = list(map(int, input().split()))
t=h1[-1]
b=h2[-1]
for i in range(n-2,-1,-1):
ct=h1[i]+b
cb=h2[i]+t
t=max(ct,t)
b=max(cb,b)
print(max(t,b))
``` | output | 1 | 32,606 | 17 | 65,213 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image> | instruction | 0 | 32,607 | 17 | 65,214 |
Tags: dp
Correct Solution:
```
from math import*
n=int(input())
m1=list(map(int,input().split()))
m2=list(map(int,input().split()))
dp=[[0]*2 for i in range(n)]
if n==1:
print(max(m1[0],m2[0]))
exit()
if n==2:
print(max(m1[0]+m2[1],m2[0]+m1[1]))
exit()
dp[0][0]=m1[0]
dp[0][1]=m2[0]
dp[1][0]=m2[0]+m1[1]
dp[1][1]=m2[1]+m1[0]
for i in range(2,n):
dp[i][0]=max(dp[i-1][1]+m1[i],dp[i-2][1]+m1[i])
dp[i][1]=max(dp[i-1][0]+m2[i],dp[i-2][0]+m2[i])
print(max(dp[n-1]))
``` | output | 1 | 32,607 | 17 | 65,215 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image> | instruction | 0 | 32,608 | 17 | 65,216 |
Tags: dp
Correct Solution:
```
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
for i in range (1,n):
a[i]=max(b[i-1]+a[i],a[i-1])
b[i]=max(a[i-1]+b[i],b[i-1])
print (max(a[n-1],b[n-1]))
``` | output | 1 | 32,608 | 17 | 65,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image>
Submitted Solution:
```
''' CODED WITH LOVE BY SATYAM KUMAR '''
from sys import stdin, stdout
import cProfile, math
from collections import Counter,defaultdict,deque
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**27) # new thread will get stack of such size
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10**9+7
import sys
class merge_find:
def __init__(self,n):
self.parent = list(range(n))
self.size = [1]*n
self.num_sets = n
self.lista = [[_] for _ in range(n)]
def find(self,a):
to_update = []
while a != self.parent[a]:
to_update.append(a)
a = self.parent[a]
for b in to_update:
self.parent[b] = a
return self.parent[a]
def merge(self,a,b):
a = self.find(a)
b = self.find(b)
if a==b:
return
if self.size[a]<self.size[b]:
a,b = b,a
self.num_sets -= 1
self.parent[b] = a
self.size[a] += self.size[b]
self.lista[a] += self.lista[b]
def set_size(self, a):
return self.size[self.find(a)]
def __len__(self):
return self.num_sets
def display(string_to_print):
stdout.write(str(string_to_print) + "\n")
def primeFactors(n): #n**0.5 complex
factors = dict()
for i in range(2,math.ceil(math.sqrt(n))+1):
while n % i== 0:
if i in factors:
factors[i]+=1
else: factors[i]=1
n = n // i
if n>2:
factors[n]=1
return (factors)
def all_factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def fibonacci_modP(n,MOD):
if n<2: return 1
#print (n,MOD)
return (cached_fn(fibonacci_modP, (n+1)//2, MOD)*cached_fn(fibonacci_modP, n//2, MOD) + cached_fn(fibonacci_modP, (n-1) // 2, MOD)*cached_fn(fibonacci_modP, (n-2) // 2, MOD)) % MOD
def factorial_modP_Wilson(n , p):
if (p <= n):
return 0
res = (p - 1)
for i in range (n + 1, p):
res = (res * cached_fn(InverseEuler,i, p)) % p
return res
def binary(n,digits = 20):
b = bin(n)[2:]
b = '0'*(digits-len(b))+b
return b
def isprime(n):
"""Returns True if n is prime."""
if n < 4:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
def generate_primes(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n+1, p):
prime[i] = False
p += 1
return prime
factorial_modP = []
def warm_up_fac(MOD):
global factorial_modP,fac_warmup
if fac_warmup: return
factorial_modP= [1 for _ in range(fac_warmup_size+1)]
for i in range(2,fac_warmup_size):
factorial_modP[i]= (factorial_modP[i-1]*i) % MOD
fac_warmup = True
def InverseEuler(n,MOD):
return pow(n,MOD-2,MOD)
def nCr(n, r, MOD):
global fac_warmup,factorial_modP
if not fac_warmup:
warm_up_fac(MOD)
fac_warmup = True
return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD
def test_print(*args):
if testingMode:
print(args)
def display_list(list1, sep=" "):
stdout.write(sep.join(map(str, list1)) + "\n")
def display_2D_list(li):
for i in li:
print(i)
def prefix_sum(li):
sm = 0
res = []
for i in li:
sm+=i
res.append(sm)
return res
def get_int():
return int(stdin.readline().strip())
def get_tuple():
return map(int, stdin.readline().split())
def get_list():
return list(map(int, stdin.readline().split()))
import heapq,itertools
pq = [] # list of entries arranged in a heap
entry_finder = {} # mapping of tasks to entries
REMOVED = '<removed-task>'
def add_task(task, priority=0):
'Add a new task or update the priority of an existing task'
if task in entry_finder:
remove_task(task)
count = next(counter)
entry = [priority, count, task]
entry_finder[task] = entry
heapq.heappush(pq, entry)
def remove_task(task):
'Mark an existing task as REMOVED. Raise KeyError if not found.'
entry = entry_finder.pop(task)
entry[-1] = REMOVED
def pop_task():
'Remove and return the lowest priority task. Raise KeyError if empty.'
while pq:
priority, count, task = heapq.heappop(pq)
if task is not REMOVED:
del entry_finder[task]
return task
raise KeyError('pop from an empty priority queue')
memory = dict()
def clear_cache():
global memory
memory = dict()
def cached_fn(fn, *args):
global memory
if args in memory:
return memory[args]
else:
result = fn(*args)
memory[args] = result
return result
def ncr (n,r):
return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
def binary_serach(i,li):
#print("Search for ",i)
fn = lambda x: li[x]-x//i
x = -1
b = len(li)
while b>=1:
#print(b,x)
while b+x<len(li) and fn(b+x)>0: #Change this condition 2 to whatever you like
x+=b
b=b//2
return x
# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
testingMode = False
fac_warmup_size = 10**5+100
optimiseForReccursion = False #Can not be used clubbed with TestCases # WHen using recursive functions, use Python 3
from math import factorial
def main():
n = get_int()
a = get_list()
b = get_list()
u = [0,0]
l = [0,0]
for i in range(n):
u.append(max(l[-1],l[-2],u[-2])+b[i])
l.append(max(u[-2],u[-3],l[-2])+a[i])
print(max(u[-1],l[-1]))
# --------------------------------------------------------------------- END=
if TestCases:
for i in range(get_int()):
cProfile.run('main()') if testingMode else main()
else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()
``` | instruction | 0 | 32,609 | 17 | 65,218 |
Yes | output | 1 | 32,609 | 17 | 65,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image>
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [[0, 0, 0] for i in range(n)]
dp[0][0] = 0
dp[0][1] = a[0]
dp[0][2] = b[0]
for i in range(1, n):
dp[i][0] = max([dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]])
dp[i][1] = max([dp[i - 1][0], dp[i - 1][2]]) + a[i]
dp[i][2] = max([dp[i - 1][0], dp[i - 1][1]]) + b[i]
print(max([dp[-1][0], dp[-1][1], dp[-1][2]]))
``` | instruction | 0 | 32,610 | 17 | 65,220 |
Yes | output | 1 | 32,610 | 17 | 65,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image>
Submitted Solution:
```
n = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
dp = [a[0], b[0], 0]
for i in range(1, n):
dp = max(dp[1], dp[2]) + a[i], max(dp[0], dp[2]) + b[i], max(dp[0], dp[1])
print(max(dp))
``` | instruction | 0 | 32,611 | 17 | 65,222 |
Yes | output | 1 | 32,611 | 17 | 65,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image>
Submitted Solution:
```
n = int(input())
h1 = list(map(int, input().split()))
h2 = list(map(int, input().split()))
ans1 = ans2 = 0
for i in range(n):
a1, a2 = ans1, ans2
ans1 = max(a1, a2+h1[i])
ans2 = max(a2, a1+h2[i])
print(max(ans1, ans2))
``` | instruction | 0 | 32,612 | 17 | 65,224 |
Yes | output | 1 | 32,612 | 17 | 65,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image>
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 14 12:40:58 2019
@author: Hamadeh
"""
import sys
class cinn:
def __init__(self):
self.x=[]
def cin(self,t=int):
if(len(self.x)==0):
a=input()
self.x=a.split()
self.x.reverse()
return self.get(t)
def get(self,t):
return t(self.x.pop())
def clist(self,n,t=int): #n is number of inputs, t is type to be casted
l=[0]*n
for i in range(n):
l[i]=self.cin(t)
return l
def clist2(self,n,t1=int,t2=int,t3=int,tn=2):
l=[0]*n
for i in range(n):
if(tn==2):
a1=self.cin(t1)
a2=self.cin(t2)
l[i]=(a1,a2)
elif (tn==3):
a1=self.cin(t1)
a2=self.cin(t2)
a3=self.cin(t3)
l[i]=(a1,a2,a3)
return l
def clist3(self,n,t1=int,t2=int,t3=int):
return self.clist2(self,n,t1,t2,t3,3)
def cout(self,i,ans=''):
if(ans==''):
print("Case #"+str(i+1)+":", end=' ')
else:
print("Case #"+str(i+1)+":",ans)
def printf(self,thing):
print(thing,end='')
def countlist(self,l,s=0,e=None):
if(e==None):
e=len(l)
dic={}
for el in range(s,e):
if l[el] not in dic:
dic[l[el]]=1
else:
dic[l[el]]+=1
return dic
def talk (self,x):
print(x,flush=True)
def dp1(self,k):
L=[-1]*(k)
return L
def dp2(self,k,kk):
L=[-1]*(k)
for i in range(k):
L[i]=[-1]*kk
return L
def isprime(self,n):
if(n==1 or n==0):
return False
for i in range(2,int(n**0.5+1)):
if(n%i==0):
return False
return True
def factors(self,n):
from functools import reduce
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def nthprime(self,n):
#usable up to 10 thousand
i=0
s=2
L=[]
while(i<n):
while(not self.isprime(s)):
s+=1
L.append(s)
s+=1
i+=1
return L
def matrixin(self,m,n,t=int):
L=[]
for i in range(m):
p=self.clist(n,t)
L.append(p)
return L
def seive(self,k):
#1000000 tops
n=k+1
L=[True]*n
L[1]=False
L[0]=False
for i in range(2,n):
if(L[i]==True):
for j in range(2*i,n,i):
L[j]=False
return L
def seiven(self,n,L):
i=0
for j in range(len(L)):
if(L[j]==True):
i+=1
if(i==n):
return j
def matrixin2(self,m,t=int):
L=[]
for i in range(m):
iny=self.cin(str)
lsmall=[]
for el in iny:
lsmall.append(t(el))
L.append(lsmall)
return L
c=cinn()
n=c.cin()
L1=c.clist(n)
L2=c.clist(n)
su1=0
su2=0
for i in range(n):
if(i%2):
su1+=L1[i]
su2+=L2[i]
else:
su1+=L2[i]
su2+=L1[i]
print(max(su1,su2))
``` | instruction | 0 | 32,613 | 17 | 65,226 |
No | output | 1 | 32,613 | 17 | 65,227 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image>
Submitted Solution:
```
n = int(input().strip())
num1 = [int(i) for i in input().strip().split()]
num2 = [int(i) for i in input().strip().split()]
dp = [[0,0] for i in range(n)]
index = 0
if n == 1:
print(max(num1[0],num2[0]))
else:
dp[0][0] = max(num1[0],num2[0])
dp[0][1] = 1 if dp[0][0] == num1[0] else 2
dp[1][0] = max(num1[0] + num2[1],num2[0] + num1[1])
dp[1][1] = 1 if num2[0] + num1[1] == dp[1][0] else 2
for i in range(2,n):
if dp[i-1][1] == 1:
if dp[i-1][0] + num2[i] > dp[i-2][0] + num1[i]:
dp[i][0] = dp[i-1][0] + num2[i]
dp[i][1] = 2
else:
dp[i][0] = dp[i-2][0] + num1[i]
dp[i][1] =1
else:
if dp[i-1][0] + num1[i] > dp[i-2][0] + num2[i]:
dp[i][0] = dp[i-1][0] + num1[i]
dp[i][1] = 1
else:
dp[i][0] = dp[i-2][0] + num2[i]
dp[i][1] =2
print(dp[-1][0])
``` | instruction | 0 | 32,614 | 17 | 65,228 |
No | output | 1 | 32,614 | 17 | 65,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image>
Submitted Solution:
```
n = int(input())
arr_1 = list(map(int, input().split()))
arr_2 = list(map(int, input().split()))
if n == 1:
print(max(arr_1[0], arr_2[0]))
else:
dp_1 = []
dp_2 = []
dp_1.append(max(arr_1[0] + arr_2[1], arr_2[0]))
dp_2.append(max(arr_2[0] + arr_1[1], arr_1[0]))
for i in range(2, n):
if i % 2 == 0:
dp_1.append(dp_1[i - 2] + arr_1[i])
dp_2.append(dp_2[i - 2] + arr_2[i])
else:
dp_1.append(dp_1[i - 2] + arr_2[i])
dp_2.append(dp_2[i - 2] + arr_1[i])
print(max(dp_1[n - 2], dp_2[n - 2]))
``` | instruction | 0 | 32,615 | 17 | 65,230 |
No | output | 1 | 32,615 | 17 | 65,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β
n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.
<image>
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.
Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of students in each row.
The second line of the input contains n integers h_{1, 1}, h_{1, 2}, β¦, h_{1, n} (1 β€ h_{1, i} β€ 10^9), where h_{1, i} is the height of the i-th student in the first row.
The third line of the input contains n integers h_{2, 1}, h_{2, 2}, β¦, h_{2, n} (1 β€ h_{2, i} β€ 10^9), where h_{2, i} is the height of the i-th student in the second row.
Output
Print a single integer β the maximum possible total height of players in a team Demid can choose.
Examples
Input
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
7
Note
In the first example Demid can choose the following team as follows:
<image>
In the second example Demid can choose the following team as follows:
<image>
Submitted Solution:
```
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l = []
zt = 0
for i in range(n):
l.append((l1[i], l2[i]))
su0 = l[0][0]
su1 = l[0][1]
i = 1
if (n==1):
print(max(l[0]))
elif (n==2):
print(max([l[0][1]+l[1][0], l[0][0]+l[1][1]]))
else:
while (i < n-1):
if (l[i+1][0] >= l[i][0]+l[i+1][1]):
su0, su1 = max(su1+l[i+1][0], su0+l[i][1]+l[i+1][0]), max(su1+l[i][0]+l[i+1][1], su0+l[i+1][1])
i += 2
elif (l[i+1][1] >= l[i][1]+l[i+1][0]):
su0, su1 = max(su1+l[i+1][0], su0+l[i][1]+l[i+1][0]), max(su1+l[i][0]+l[i+1][1], su0+l[i+1][1])
i += 2
else:
su0, su1 = su1+l[i+1][0], su0+l[i+1][1]
i += 1
if (i==n):
print(max(su0, su1))
else:
print(max(su0+l[i][1], su1+l[i][0]))
``` | instruction | 0 | 32,616 | 17 | 65,232 |
No | output | 1 | 32,616 | 17 | 65,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself.
You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one.
Input
The first line contains an integer n (1 β€ n β€ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once.
Then follow n lines each containing three integers from 1 to 3n β each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above.
The last line contains number k (1 β€ k β€ 3n) which is the number of a student for who the list of priorities should be found.
Output
Print 3n - 1 numbers β the lexicographically smallest list of priorities for the student number k.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 β€ i β€ 3n), that ai < bi, and for any j (1 β€ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines.
Examples
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
4
Output
2 3 5 6 9 1 7 8
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
8
Output
1 2 3 4 5 6 7 9
Input
2
4 1 3 2 5 6
4 6 5
1 2 3
4
Output
5 6 1 2 3 | instruction | 0 | 32,972 | 17 | 65,944 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n = int(input())
a = list(map(int, input().split()))
order = [0] * (3 * n + 1)
for i, x in enumerate(a):
order[x] = i
used = [0] * (3 * n + 1)
items = [tuple(map(int, input().split())) for _ in range(n)]
k = int(input())
def end1(x, y, z):
free = []
pre, suf = [], []
for i in range(1, 3 * n + 1):
if i == k:
continue
if i == x or i == y or i == z:
pre.append(i)
elif not used[i]:
suf.append(i)
else:
free.append(i)
ans = []
fi, fn = 0, len(free)
for x in (pre + suf):
while fi < fn and free[fi] < x:
ans.append(free[fi])
fi += 1
ans.append(x)
ans += free[fi:]
print(*ans)
exit()
def end2():
print(*(list(range(1, k)) + list(range(k + 1, 3 * n + 1))))
exit()
for x, y, z in items:
used[x] = used[y] = used[z] = 1
if k in (x, y, z):
if order[k] == min(map(lambda x: order[x], (x, y, z))):
end1(x, y, z)
else:
end2()
``` | output | 1 | 32,972 | 17 | 65,945 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself.
You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one.
Input
The first line contains an integer n (1 β€ n β€ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once.
Then follow n lines each containing three integers from 1 to 3n β each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above.
The last line contains number k (1 β€ k β€ 3n) which is the number of a student for who the list of priorities should be found.
Output
Print 3n - 1 numbers β the lexicographically smallest list of priorities for the student number k.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 β€ i β€ 3n), that ai < bi, and for any j (1 β€ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines.
Examples
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
4
Output
2 3 5 6 9 1 7 8
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
8
Output
1 2 3 4 5 6 7 9
Input
2
4 1 3 2 5 6
4 6 5
1 2 3
4
Output
5 6 1 2 3 | instruction | 0 | 32,973 | 17 | 65,946 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
import sys
I = lambda: int(input())
RL = readline = lambda: sys.stdin.readline().strip('\n')
RM = readmap = lambda x = int: map(x,readline().split(' '))
def f(l,x):
if x==l[0]: return l[1],l[2]
if x==l[1]: return l[0],l[2]
if x==l[2]: return l[0],l[1]
return -1
def delrank(x):
global pre,nxt
prex,nxtx = pre[x],nxt[x]
nxt[prex] = nxtx
pre[nxtx] = prex
n = I()
N = 3*n
rank = [*RM()]+[N+1]
tris = [tuple(RM()) for i in range(n)]
k = I()
pre,nxt = list(range(N+2)), list(range(N+2))
temp0 = 0
for i in range(N+1):
temp1 = rank[i]
pre[temp1],nxt[temp0] = temp0,temp1
temp0 = temp1
for ind,tri in enumerate(tris):
leader = nxt[0]
x,y = f(tri,leader)
if k in tri:
if leader != k:
l = [i for i in range(1,N+1) if i!=k]
else:
#condition here is element in l3 should be after max(x,y)
#so sort l1+l2 first cut the portion after max(x,y) and add
#it to l3 and sort the new l3
l1 = [i for tri in tris[:ind] for i in tri]
l2 = [x,y]
l3 = [i for tri in tris[ind+1:] for i in tri]
l0 = sorted(l1 + l2)
ind = l0.index(max(x,y))
l = l0[:ind+1] + sorted(l0[ind+1:]+l3)
#print(leader,l1,l2,l3)
print(' '.join([str(i) for i in l]))
sys.exit(0)
for i in tri: delrank(i)
'''
7
4 19 14 8 21 16 2 18 1 15 3 17 13 5 6 10 9 7 12 11 20
4 19 10
14 8 3
21 17 9
16 6 12
2 13 20
18 1 7
15 5 11
21
'''
quit()
#E Shortest Path
def rec(u,v):
'''to recursivley visit the edge previous to this edge'''
if v: rec(pre[u][v],u);print(v,end=' ')
from collections import deque
n,m,k = RM()
adj = [[] for i in range(n+1)]
dist = [[int(1e9)]*(n+1) for i in range(n+1)]
pre = [[0]*(n+1) for i in range(n+1)]
bad = set()
for _ in range(m):
x,y = RM()
adj[x].append(y)
adj[y].append(x)
for _ in range(k): bad.add(tuple(RM()))
dist[0][1] = 0
q = deque([(0,1)])
while q:
u,v = q.popleft()
d = dist[u][v] + 1
for w in adj[v]:
if d<dist[v][w] and not (u,v,w) in bad:
dist[v][w] = d
pre[v][w] = u
q.append((v,w))
if w == n:
print(d)
rec(v,w)
print()
sys.exit(0)
print(-1)
``` | output | 1 | 32,973 | 17 | 65,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself.
You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one.
Input
The first line contains an integer n (1 β€ n β€ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once.
Then follow n lines each containing three integers from 1 to 3n β each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above.
The last line contains number k (1 β€ k β€ 3n) which is the number of a student for who the list of priorities should be found.
Output
Print 3n - 1 numbers β the lexicographically smallest list of priorities for the student number k.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 β€ i β€ 3n), that ai < bi, and for any j (1 β€ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines.
Examples
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
4
Output
2 3 5 6 9 1 7 8
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
8
Output
1 2 3 4 5 6 7 9
Input
2
4 1 3 2 5 6
4 6 5
1 2 3
4
Output
5 6 1 2 3 | instruction | 0 | 32,974 | 17 | 65,948 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
from sys import stdin, stdout
n = int(stdin.readline())
points = list(map(int, stdin.readline().split()))
teams = []
chance = []
for i in range(n):
teams.append(tuple(map(int, stdin.readline().split())))
k = int(stdin.readline())
for i in range(n):
f, s, t = teams[i]
if not k in teams[i]:
chance += [f, s, t]
else:
a, b = [f, s, t][:[f, s, t].index(k)] + [f, s, t][[f, s, t].index(k) + 1:]
if points.index(a) < points.index(k) or points.index(b) < points.index(k):
chance = []
for i in range(1, 3 * n + 1):
if i != k:
chance.append(i)
else:
chance += [a, b]
break
chance.sort()
s = set(chance)
for i in range(1, 3 * n + 1):
if not i in s and i != k:
chance.append(i)
chance = chance[:chance.index(max(a, b)) + 1] + sorted(chance[chance.index(max(a, b)) + 1:])
stdout.write(' '.join(list(map(str, chance))))
``` | output | 1 | 32,974 | 17 | 65,949 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself.
You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one.
Input
The first line contains an integer n (1 β€ n β€ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once.
Then follow n lines each containing three integers from 1 to 3n β each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above.
The last line contains number k (1 β€ k β€ 3n) which is the number of a student for who the list of priorities should be found.
Output
Print 3n - 1 numbers β the lexicographically smallest list of priorities for the student number k.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 β€ i β€ 3n), that ai < bi, and for any j (1 β€ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines.
Examples
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
4
Output
2 3 5 6 9 1 7 8
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
8
Output
1 2 3 4 5 6 7 9
Input
2
4 1 3 2 5 6
4 6 5
1 2 3
4
Output
5 6 1 2 3 | instruction | 0 | 32,975 | 17 | 65,950 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
n = int(input())
pos = list(map(int, input().split()))
gr = []
for _ in range(n):
gr.append(list(map(int, input().split())))
k = int(input())
cidx = -1
for idx, cg in enumerate(gr):
for elm in cg:
if elm == k:
cidx = idx
break
per = [0] * len(pos)
for idx, elm in enumerate(pos):
per[elm - 1] = idx
max_per = min([per[gr[cidx][i] - 1] for i in range(3)])
if max_per == per[k - 1]:
fi = []
for idx in range(cidx):
for elm in gr[idx]:
fi.append(elm)
tm = []
for elm in gr[cidx]:
if elm != k:
fi.append(elm)
tm.append(elm)
max_tm = max(tm)
fi.sort()
cut_point = fi.index(max_tm)
se = fi[cut_point + 1:]
fi = fi[:cut_point + 1]
for idx in range(cidx + 1, n):
for elm in gr[idx]:
se.append(elm)
se.sort()
ans = fi + se
else:
ans = []
for elm in pos:
if elm != k:
ans.append(elm)
ans.sort()
print(*ans)
``` | output | 1 | 32,975 | 17 | 65,951 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself.
You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one.
Input
The first line contains an integer n (1 β€ n β€ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once.
Then follow n lines each containing three integers from 1 to 3n β each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above.
The last line contains number k (1 β€ k β€ 3n) which is the number of a student for who the list of priorities should be found.
Output
Print 3n - 1 numbers β the lexicographically smallest list of priorities for the student number k.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 β€ i β€ 3n), that ai < bi, and for any j (1 β€ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines.
Examples
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
4
Output
2 3 5 6 9 1 7 8
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
8
Output
1 2 3 4 5 6 7 9
Input
2
4 1 3 2 5 6
4 6 5
1 2 3
4
Output
5 6 1 2 3 | instruction | 0 | 32,976 | 17 | 65,952 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
import sys
I = lambda: int(input())
RL = readline = lambda: sys.stdin.readline().strip('\n')
RM = readmap = lambda x = int: map(x,readline().split(' '))
def f(l,x):
if x==l[0]: return l[1],l[2]
if x==l[1]: return l[0],l[2]
if x==l[2]: return l[0],l[1]
return -1
def delrank(x):
global pre,nxt
prex,nxtx = pre[x],nxt[x]
nxt[prex] = nxtx
pre[nxtx] = prex
n = I()
N = 3*n
rank = [*RM()]+[N+1]
tris = [tuple(RM()) for i in range(n)]
k = I()
pre,nxt = list(range(N+2)), list(range(N+2))
temp0 = 0
for i in range(N+1):
temp1 = rank[i]
pre[temp1],nxt[temp0] = temp0,temp1
temp0 = temp1
for ind,tri in enumerate(tris):
leader = nxt[0]
x,y = f(tri,leader)
if k in tri:
if leader != k:
l = [i for i in range(1,N+1) if i!=k]
else:
l1 = [i for tri in tris[:ind] for i in tri]
l2 = [x,y]
l3 = [i for tri in tris[ind+1:] for i in tri]
l1 = sorted(l1 + l2)
ind = l1.index(max(x,y))
l = l1[:ind+1] + sorted(l1[ind+1:]+l3)
#print(leader,l1,l2,l3)
print(' '.join([str(i) for i in l]))
sys.exit(0)
for i in tri: delrank(i)
'''
7
4 19 14 8 21 16 2 18 1 15 3 17 13 5 6 10 9 7 12 11 20
4 19 10
14 8 3
21 17 9
16 6 12
2 13 20
18 1 7
15 5 11
21
'''
quit()
#E Shortest Path
def rec(u,v):
'''to recursivley visit the edge previous to this edge'''
if v: rec(pre[u][v],u);print(v,end=' ')
from collections import deque
n,m,k = RM()
adj = [[] for i in range(n+1)]
dist = [[int(1e9)]*(n+1) for i in range(n+1)]
pre = [[0]*(n+1) for i in range(n+1)]
bad = set()
for _ in range(m):
x,y = RM()
adj[x].append(y)
adj[y].append(x)
for _ in range(k): bad.add(tuple(RM()))
dist[0][1] = 0
q = deque([(0,1)])
while q:
u,v = q.popleft()
d = dist[u][v] + 1
for w in adj[v]:
if d<dist[v][w] and not (u,v,w) in bad:
dist[v][w] = d
pre[v][w] = u
q.append((v,w))
if w == n:
print(d)
rec(v,w)
print()
sys.exit(0)
print(-1)
``` | output | 1 | 32,976 | 17 | 65,953 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself.
You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one.
Input
The first line contains an integer n (1 β€ n β€ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once.
Then follow n lines each containing three integers from 1 to 3n β each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above.
The last line contains number k (1 β€ k β€ 3n) which is the number of a student for who the list of priorities should be found.
Output
Print 3n - 1 numbers β the lexicographically smallest list of priorities for the student number k.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 β€ i β€ 3n), that ai < bi, and for any j (1 β€ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines.
Examples
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
4
Output
2 3 5 6 9 1 7 8
Input
3
5 4 1 2 6 3 7 8 9
5 6 2
9 3 4
1 7 8
8
Output
1 2 3 4 5 6 7 9
Input
2
4 1 3 2 5 6
4 6 5
1 2 3
4
Output
5 6 1 2 3
Submitted Solution:
```
n = int(input())
pos = list(map(int, input().split()))
gr = []
for _ in range(n):
gr.append(list(map(int, input().split())))
k = int(input())
cidx = -1
for idx, cg in enumerate(gr):
for elm in cg:
if elm == k:
cidx = idx
break
per = [0] * len(pos)
for idx, elm in enumerate(pos):
per[elm - 1] = idx
max_per = min([per[gr[cidx][i] - 1] for i in range(3)])
if max_per == per[k - 1]:
fi = []
for idx in range(cidx):
for elm in gr[idx]:
fi.append(elm)
tm = []
for elm in gr[cidx]:
if elm != k:
fi.append(elm)
tm.append(elm)
max_tm = max(tm)
fi.sort()
cut_point = fi.index(max_tm)
se = fi[max_tm + 1:]
fi = fi[:max_tm + 1]
for idx in range(cidx + 1, n):
for elm in gr[idx]:
se.append(elm)
se.sort()
ans = fi + se
else:
ans = []
for elm in pos:
if elm != k:
ans.append(elm)
ans.sort()
print(*ans)
``` | instruction | 0 | 32,977 | 17 | 65,954 |
No | output | 1 | 32,977 | 17 | 65,955 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.