output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s967178652 | Wrong Answer | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | n = input().split()
print(min(n))
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s121456830 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | a = map(int, input().split())
k = 0
for l in a:
k += 1
if int(l) == 0:
print(k)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s112877680 | Runtime Error | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | n = int(input())
s = [int(i) for i in input().split()]
s = set(s)
for i in s:
for j in s:
if i == j or i % j == 0:
s.remove(i)
s.add(-i)
break
l = [i for i in s if i >= 0]
print(len(l))
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s845650010 | Wrong Answer | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | a = []
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s207332440 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | A = list(map(int, input().rstrip().split(" ")))
# print(A)
B = A.index(0)
print(B + 1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s390527368 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | [print(j + 1) for j, k in enumerate([i for i in input().split()]) if k == "0"]
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s274894153 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | lists = list(map(int, input().split()))
print(lists.index(0) + 1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s516553820 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | A, B, C, D, E = (int(x) for x in input().split())
renketsu = str(A) + str(B) + str(C) + str(D) + str(E)
print(renketsu.find("0") + 1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s579012376 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | print([int(i) for i in input().split()].index(0) + 1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s092041831 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | q = [int(i) for i in input().split()]
print(q.index(0) + 1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s653908645 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | mylist = list(map(int, input().split()))
print(mylist.index(0) + 1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s826618864 | Wrong Answer | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | print(list(map(int, input().split())).index(0))
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s553628145 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | [print(i + 1) for i, x in enumerate(map(int, input().split())) if x == 0]
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s726448198 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | i_list = i = list(map(int, input().split()))
print(i_list.index(0) + 1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s026351985 | Runtime Error | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | a = input()
b = input()
c = input()
d = input()
e = input()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
sum = a + b + c + d + e
print(15 - sum)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s971436665 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | ls1 = list(map(int, input().split()))
print(ls1.index(0) + 1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s737298525 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | aa = list(map(int, input().split()))
print((set([1, 2, 3, 4, 5]) - set(aa)).pop())
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s076375545 | Accepted | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | line = list(map(int, input().split(" ")))
print(15 - sum(line))
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s221398415 | Runtime Error | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | a, b, c = input().split()
print("{} {} {}".format(c, a, b))
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s005958182 | Wrong Answer | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | print(1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
If the variable Snuke assigned 0 was x_i, print the integer i.
* * * | s097792889 | Runtime Error | p02639 | Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5 | h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
m = [[-1] * w for _ in range(h)]
for hh in range(h):
c = input()
for ww, cc in enumerate(c):
if cc == ".":
m[hh][ww] = h * w
from collections import deque
q = deque()
q.append((0, x1, y1))
while q:
s, x, y = q.popleft()
for i in range(1, k + 1):
xx, yy = x + i, y
if xx >= h or m[xx][yy] == -1:
break
if m[xx][yy] <= s + 1:
continue
if xx == x2 and yy == y2:
print(s + 1)
exit(0)
m[xx][yy] = s + 1
q.append((s + 1, xx, yy))
for i in range(1, k + 1):
xx, yy = x - i, y
if xx < 0 or m[xx][yy] == -1:
break
if m[xx][yy] <= s + 1:
continue
if xx == x2 and yy == y2:
print(s + 1)
exit(0)
m[xx][yy] = s + 1
q.append((s + 1, xx, yy))
for i in range(1, k + 1):
xx, yy = x, y + i
if yy >= w or m[xx][yy] == -1:
break
if m[xx][yy] <= s + 1:
continue
if xx == x2 and yy == y2:
print(s + 1)
exit(0)
m[xx][yy] = s + 1
q.append((s + 1, xx, yy))
for i in range(1, k + 1):
xx, yy = x, y - i
if yy < 0 or m[xx][yy] == -1:
break
if m[xx][yy] <= s + 1:
continue
if xx == x2 and yy == y2:
print(s + 1)
exit(0)
m[xx][yy] = s + 1
q.append((s + 1, xx, yy))
print(-1)
| Statement
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0. | [{"input": "0 2 3 4 5", "output": "1\n \n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\n* * *"}, {"input": "1 2 0 4 5", "output": "3"}] |
Print the numbers of Sugim's manju and Sigma's manju at the end of the game,
in this order, with a space in between.
* * * | s821529255 | Wrong Answer | p03301 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | n = input()
slimes = map(int, input().split())
res = 0
last = -1
cnt = 0
for slime in slimes:
if slime != last:
res += cnt // 2
last = slime
cnt = 1
else:
cnt += 1
res += cnt // 2
print(res)
| Statement
There are N boxes arranged in a row from left to right. The i-th box from the
left contains a_i manju (buns stuffed with bean paste). Sugim and Sigma play a
game using these boxes. They alternately perform the following operation.
Sugim goes first, and the game ends when a total of N operations are
performed.
* Choose a box that still does not contain a piece and is adjacent to the box chosen in the other player's **last** operation, then put a piece in that box. If there are multiple such boxes, any of them can be chosen.
* If there is no box that satisfies the condition above, or this is Sugim's first operation, choose any one box that still does not contain a piece, then put a piece in that box.
At the end of the game, each player can have the manju in the boxes in which
he put his pieces. They love manju, and each of them is wise enough to perform
the optimal moves in order to have the maximum number of manju at the end of
the game.
Find the number of manju that each player will have at the end of the game. | [{"input": "5\n 20 100 10 1 10", "output": "120 21\n \n\nIf the two performs the optimal moves, the game proceeds as follows:\n\n * First, Sugim has to put his piece in the second box from the left.\n * Then, Sigma has to put his piece in the leftmost box.\n * Then, Sugim puts his piece in the third or fifth box.\n * Then, Sigma puts his piece in the fourth box.\n * Finally, Sugim puts his piece in the remaining box.\n\n* * *"}, {"input": "6\n 4 5 1 1 4 5", "output": "11 9\n \n\n* * *"}, {"input": "5\n 1 10 100 10 1", "output": "102 20"}] |
* Calculate the possible index and print in sorted order. The output should be separated with a space. Don't print a space after last number.
* Put a line break in the end. | s171363804 | Accepted | p03751 | The input is given from standard input in the following format.
N
S_1
S_2
:
S_N
T | n = int(input())
l = [input() for _ in range(n)]
t = input()
l.append(t)
li = list(map(lambda x: x.replace("?", "A"), l))
ho = list(map(lambda x: x.replace("?", "z"), l))
li.sort(reverse=True)
ho.sort()
x = n - li.index(t)
y = ho.index(t)
print(" ".join(map(str, list(range(y + 1, x + 2)))))
| Statement
Mr.X, who the handle name is T, looked at the list which written N handle
names, S_1, S_2, ..., S_N.
But he couldn't see some parts of the list. Invisible part is denoted `?`.
Please calculate all possible index of the handle name of Mr.X when you sort
N+1 handle names (S_1, S_2, ..., S_N and T) in lexicographical order.
Note: If there are pair of people with same handle name, either one may come
first. | [{"input": "2\n tourist\n petr\n e", "output": "1\n \n\nThere are no invisible part, so there are only one possibility. The sorted\nhandle names are `e`, `petr`, `tourist`, so `e` comes first."}] |
* Calculate the possible index and print in sorted order. The output should be separated with a space. Don't print a space after last number.
* Put a line break in the end. | s658515322 | Runtime Error | p03751 | The input is given from standard input in the following format.
N
S_1
S_2
:
S_N
T | # recursion-version
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_A&lang=jp
# http://penguinshunya.hatenablog.com/entry/2019/07/09/003006
import sys
sys.setrecursionlimit(10000)
inpPh = 0
debug = True
# debug = False
if not debug:
inpPh = 0
input1 = """
4
1 2
2 3
2 4
"""[
1:
]
input2 = """
4
1 2
2 4
4 3
"""[
1:
]
input1bk = """
4
0 1 2
1 2 1
1 3 3
"""[
1:
]
# input1 = input2
output1_2 = """
5 7
"""
inputXs = [input1, input2, None]
if debug:
try:
inputXs.append(inputA0)
except:
pass
else:
pass
inploc = inpPh - 1 # 0,1,2
if inpPh > 0:
# print('selected_input:\n'+inputXs[inploc])
# print('')
pass
inpX_lst = []
if debug and inpPh > 0:
inpX_lst = inputXs[inploc].splitlines()
if inpPh == 0:
n = int(input())
else:
n = int(inpX_lst.pop(0))
st_list = []
noe_vwise = [0 for _ in range(n)]
for i in range(n - 1):
if inpPh == 0:
si, ti = tuple(map(lambda x: int(x), input().split()))
else:
si, ti = tuple(map(lambda x: int(x), inpX_lst.pop(0).split()))
noe_vwise[si - 1] += 1
# noe_vwise[ti-1] += 1
st_list.append((si - 1, ti - 1))
# print(st_list)
from collections import namedtuple
INF = float("inf")
Edge = namedtuple("Edge", ["to", "value"])
def Edge(x, y):
return (x, y)
def reroot(n, es_vwise, dp_es_vwise, e_init, noe_vwise, pe_vwise):
def dfs1(v, v_par):
nonlocal es_vwise, dp_es_vwise, e_init, vpar_v, noe_vwise
stack = [(v, v_par)]
while stack:
(v, v_par) = stack.pop()
# print('es_vwise[v]',v,es_vwise[v])
ret = e
# ret = Edge(-INF,-INF)
ret = (0, 0)
for i in range(len(es_vwise[v])):
e_local = es_vwise[v][i]
if e_local[0] == v_par:
print("this-part should not be printed")
vpar_v[v] = i
continue
dp_es_vwise[v][i] = lift(dfs1(e_local[0], v), e_local[1])
# dp_es_vwise[v][i] = lift(dfs1(e_local[0], v), e_local[1] )
ret = merge(ret, dp_es_vwise[v][i])
return ret
def dfs2(v, t):
# bundlable_parental_edge = t
nonlocal ans, es_vwise, dp_es_vwise, vpar_v, e_init, noe_vwise
nonlocal pe_vwise
if vpar_v[v] is not None:
pass
# lift(parental_edge, gparental_edge)
# dp_es_vwise[v][vpar_v[v]] = lift(t,es_vwise[v][vpar_v[v]][1] )
l = len(es_vwise[v])
dpl = [e_init for i in range(l + 1)]
dpr = [e_init for i in range(l + 1)]
if pe_vwise[v] is not None:
v0, v1, w = pe_vwise[v]
dpr[l] = lift(t, w)
for i in range(l):
dpl[i + 1] = merge(dpl[i], dp_es_vwise[v][i])
for i in range(l - 1, -1, -1):
dpr[i] = merge(dpr[i + 1], dp_es_vwise[v][i])
# l: 0->1, l-1->l
# r: l->l-1, 1->0
ans[v] = dpr[0]
for i in range(l):
if i == vpar_v[v]:
print("continue, l", 0)
continue
u = es_vwise[v][i][0]
dfs2(u, merge(dpl[i], dpr[i + 1]))
def lift(a, w):
if a[1] == 0:
return (w, 1)
return ((a[0] / a[1]) + w, 1)
# w is 1, though...
# return Edge(max(0,a[0]) +w, -INF)
def merge(a, b):
# print("merge:",a,b)
return (a[0] + b[0], a[1] + b[1])
nov = n
vpar_v = [None for i in range(nov)]
vpar_v0 = [None for i in range(nov)]
for i in range(len(es_vwise)):
for e in es_vwise[i]:
vpar_v0[e[0]] = i
ans = [Edge(0, -INF) for i in range(nov)]
dfs1(0, None)
# 0 must be root?
dfs2(0, None)
ret = 0
for i in range(len(ans)):
# print(f'i:{i} ans:{ans[i]}')
print(float(ans[i][0] / ans[i][1]))
return ans
class reroot_init:
def __init__(self, n, noe_vwise):
self.n = n
self.es_vwise = [[] for i in range(n)]
self.dp_es_vwise = [[] for i in range(n)]
self.pe_vwise = [None for i in range(n)]
parental_edge_vwise = self.pe_vwise
def movemain(self):
reroot(n, self.es_vwise, self.dp_es_vwise, (-INF, -INF), noe_vwise, {})
def main():
rri = reroot_init(n, noe_vwise)
es_vwise = [[] for i in range(n)]
dp_es_vwise = [[] for i in range(n)]
pe_vwise = [None for i in range(n)]
edges_vwise = es_vwise
parental_edge_vwise = pe_vwise
def v_add_edge(v, u, w):
es_vwise[v].append((u, w))
dp_es_vwise[v].append((0, -INF))
for st in st_list:
s, t = st
# print(stw)
v_add_edge(s, t, 1)
pe_vwise[t] = (s, t, 1)
e_init = (0, 0)
reroot(n, es_vwise, dp_es_vwise, e_init, noe_vwise, pe_vwise)
main()
| Statement
Mr.X, who the handle name is T, looked at the list which written N handle
names, S_1, S_2, ..., S_N.
But he couldn't see some parts of the list. Invisible part is denoted `?`.
Please calculate all possible index of the handle name of Mr.X when you sort
N+1 handle names (S_1, S_2, ..., S_N and T) in lexicographical order.
Note: If there are pair of people with same handle name, either one may come
first. | [{"input": "2\n tourist\n petr\n e", "output": "1\n \n\nThere are no invisible part, so there are only one possibility. The sorted\nhandle names are `e`, `petr`, `tourist`, so `e` comes first."}] |
* Calculate the possible index and print in sorted order. The output should be separated with a space. Don't print a space after last number.
* Put a line break in the end. | s689387982 | Wrong Answer | p03751 | The input is given from standard input in the following format.
N
S_1
S_2
:
S_N
T | n = int(input())
a, z = [], []
for _ in range(n):
s = input()
a.append(s.replace("?", "a"))
z.append(s.replace("?", "z"))
t = input()
a.append(t)
z.append(t)
a, z = sorted(a)[::-1], sorted(z)
r, l = n + 1 - a.index(t), z.index(t) + 1
for i in range(l, r + 1):
print(i, end=" ")
| Statement
Mr.X, who the handle name is T, looked at the list which written N handle
names, S_1, S_2, ..., S_N.
But he couldn't see some parts of the list. Invisible part is denoted `?`.
Please calculate all possible index of the handle name of Mr.X when you sort
N+1 handle names (S_1, S_2, ..., S_N and T) in lexicographical order.
Note: If there are pair of people with same handle name, either one may come
first. | [{"input": "2\n tourist\n petr\n e", "output": "1\n \n\nThere are no invisible part, so there are only one possibility. The sorted\nhandle names are `e`, `petr`, `tourist`, so `e` comes first."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s267224660 | Accepted | p02843 | Input is given from Standard Input in the following format:
X | n = int(input().strip())
valid = {0: True}
for i in range(1, n + 1):
valid[i] = any(valid.get(i - j, False) for j in range(100, 106))
print(1 if valid[i] else 0)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s426498501 | Accepted | p02843 | Input is given from Standard Input in the following format:
X | dp = [False] * 100200
dp[0] = True
for x in range(100000):
if dp[x]:
for i in range(100, 106):
dp[x + i] = True
print(int(dp[int(input())]))
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s412260789 | Wrong Answer | p02843 | Input is given from Standard Input in the following format:
X | X = int(input())
item_list = [100, 101, 102, 103, 104, 105]
pre_list = []
sum_value = 0
for i in range(1, 1001):
tmp_list = []
for value in item_list:
tmp_list.append(i * value)
pre_list.append(tmp_list)
sum_list = [[0] * 6 for i in range(1000)]
for i in range(1000):
for j in range(6):
if i == 0:
sum_list[i][j] = sum_list[i][j - 1] + pre_list[i][j]
elif j == 0:
sum_list[i][j] = sum_list[i - 1][j] + pre_list[i][j]
else:
sum_list[i][j] = (
sum_list[i - 1][j]
+ sum_list[i][j - 1]
- sum_list[i - 1][j - 1]
+ pre_list[i][j]
)
flag = 0
for i1 in range(0, 999):
for i2 in range(i1 + 1, 1000):
for j1 in range(0, 5):
for j2 in range(j1 + 1, 6):
value = (
sum_list[i2][j2]
- sum_list[i1][j2]
- sum_list[i2][j1]
+ sum_list[i1][j1]
)
if X == value:
flag = 1
print(flag)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s092985559 | Wrong Answer | p02843 | Input is given from Standard Input in the following format:
X | import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL():
return list(map(int, input().split()))
def SL():
return input().split()
def I():
return int(sys.stdin.readline())
def S():
return input()
N = I()
a = [100, 101, 102, 103, 104, 105]
dp = [[False] * (N + 1) for i in range(6 + 1)]
dp[0][0] = True
for i in range(1, 6 + 1):
for j in range(N + 1):
if 0 <= (j - a[i - 1]) < N + 1:
if dp[i - 1][j - a[i - 1]] == True:
dp[i][j] = True
if dp[i - 1][j] == True:
dp[i][j] = True
print(int(dp[-1][-1]))
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s067127826 | Accepted | p02843 | Input is given from Standard Input in the following format:
X | m = int(input())
f = [0] * (m + 1)
f[0] = 1
for x in range(100, 106):
for i in range(x, m + 1):
f[i] = max(f[i - x], f[i])
print(f[m])
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s629460232 | Accepted | p02843 | Input is given from Standard Input in the following format:
X | x = input()
if int(x) < 100:
print(0)
exit(0)
if 0 <= int(x[-2] + x[-1]) <= 5:
print(1)
exit(0)
elif 6 <= int(x[-2] + x[-1]) <= 10 and 2 <= int(x) // 100:
print(1)
elif 11 <= int(x[-2] + x[-1]) <= 15 and 3 <= int(x) // 100:
print(1)
elif 16 <= int(x[-2] + x[-1]) <= 20 and 4 <= int(x) // 100:
print(1)
elif 21 <= int(x[-2] + x[-1]) <= 25 and 5 <= int(x) // 100:
print(1)
elif 26 <= int(x[-2] + x[-1]) <= 30 and 6 <= int(x) // 100:
print(1)
elif 31 <= int(x[-2] + x[-1]) <= 35 and 7 <= int(x) // 100:
print(1)
elif 36 <= int(x[-2] + x[-1]) <= 40 and 8 <= int(x) // 100:
print(1)
elif 41 <= int(x[-2] + x[-1]) <= 45 and 9 <= int(x) // 100:
print(1)
elif 46 <= int(x[-2] + x[-1]) <= 50 and 10 <= int(x) // 100:
print(1)
elif 51 <= int(x[-2] + x[-1]) <= 55 and 11 <= int(x) // 100:
print(1)
elif 56 <= int(x[-2] + x[-1]) <= 60 and 12 <= int(x) // 100:
print(1)
elif 61 <= int(x[-2] + x[-1]) <= 65 and 13 <= int(x) // 100:
print(1)
elif 66 <= int(x[-2] + x[-1]) <= 70 and 14 <= int(x) // 100:
print(1)
elif 71 <= int(x[-2] + x[-1]) <= 75 and 15 <= int(x) // 100:
print(1)
elif 76 <= int(x[-2] + x[-1]) <= 80 and 16 <= int(x) // 100:
print(1)
elif 81 <= int(x[-2] + x[-1]) <= 85 and 17 <= int(x) // 100:
print(1)
elif 86 <= int(x[-2] + x[-1]) <= 90 and 18 <= int(x) // 100:
print(1)
elif 91 <= int(x[-2] + x[-1]) <= 95 and 19 <= int(x) // 100:
print(1)
elif 96 <= int(x[-2] + x[-1]) <= 99 and 20 <= int(x) // 100:
print(1)
else:
print(0)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s640914864 | Wrong Answer | p02843 | Input is given from Standard Input in the following format:
X | X = int(input())
if (
X % 100 == 0
or X % 101 == 0
or X % 102 == 0
or X % 103 == 0
or X % 104 == 0
or X % 105 == 0
):
print(1)
elif (
X % 200 == 0
or X % 201 == 0
or X % 202 == 0
or X % 203 == 0
or X % 204 == 0
or X % 205 == 0
or X % 206 == 0
or X % 207 == 0
or X % 208 == 0
or X % 209 == 0
or X % 210 == 0
):
print(1)
elif (
X % 300 == 0
or X % 301 == 0
or X % 302 == 0
or X % 303 == 0
or X % 304 == 0
or X % 305 == 0
or X % 306 == 0
or X % 307 == 0
or X % 308 == 0
or X % 309 == 0
or X % 310 == 0
or X % 311 == 0
or X % 312 == 0
or X % 313 == 0
or X % 314 == 0
or X % 315 == 0
):
print(1)
elif (
X % 400 == 0
or X % 401 == 0
or X % 402 == 0
or X % 403 == 0
or X % 404 == 0
or X % 405 == 0
or X % 406 == 0
or X % 407 == 0
or X % 408 == 0
or X % 409 == 0
or X % 410 == 0
or X % 411 == 0
or X % 412 == 0
or X % 413 == 0
or X % 414 == 0
or X % 415 == 0
or X % 416 == 0
or X % 417 == 0
or X % 418 == 0
or X % 419 == 0
or X % 420 == 0
):
print(1)
elif (
X % 500 == 0
or X % 501 == 0
or X % 502 == 0
or X % 503 == 0
or X % 504 == 0
or X % 505 == 0
or X % 506 == 0
or X % 507 == 0
or X % 508 == 0
or X % 509 == 0
or X % 510 == 0
or X % 511 == 0
or X % 512 == 0
or X % 513 == 0
or X % 514 == 0
or X % 515 == 0
or X % 516 == 0
or X % 517 == 0
or X % 518 == 0
or X % 519 == 0
or X % 520 == 0
or X % 521 == 0
or X % 522 == 0
or X % 523 == 0
or X % 524 == 0
or X % 525 == 0
):
print(1)
elif (
X % 600 == 0
or X % 601 == 0
or X % 602 == 0
or X % 603 == 0
or X % 604 == 0
or X % 605 == 0
or X % 606 == 0
or X % 607 == 0
or X % 608 == 0
or X % 609 == 0
or X % 610 == 0
or X % 611 == 0
or X % 612 == 0
or X % 613 == 0
or X % 614 == 0
or X % 615 == 0
or X % 616 == 0
or X % 617 == 0
or X % 618 == 0
or X % 619 == 0
or X % 620 == 0
or X % 621 == 0
or X % 622 == 0
or X % 623 == 0
or X % 624 == 0
or X % 625 == 0
or X % 626 == 0
or X % 627 == 0
or X % 628 == 0
or X % 629 == 0
or X % 630 == 0
):
print(1)
else:
print(0)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s208942206 | Runtime Error | p02843 | Input is given from Standard Input in the following format:
X | X = int(input())
N = X // 100
M = X % 100
A = [0, 1, 2, 3, 4, 5]
dp = [[0] * (M + 1) for i in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for k in range(M + 1):
dp[i + 1][k] |= dp[i][k]
if k >= A[i]:
dp[i + 1][k] |= dp[i][k - A[i]]
print(dp[N][M])
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s864924002 | Accepted | p02843 | Input is given from Standard Input in the following format:
X | x = int(input())
if 1 <= x and x <= 99:
print(0)
exit()
elif 106 <= x and x <= 199:
print(0)
exit()
elif 211 <= x and x <= 299:
print(0)
exit()
elif 316 <= x and x <= 399:
print(0)
exit()
elif 421 <= x and x <= 499:
print(0)
exit()
elif 526 <= x and x <= 599:
print(0)
exit()
elif 631 <= x and x <= 699:
print(0)
exit()
elif 736 <= x and x <= 799:
print(0)
exit()
elif 841 <= x and x <= 899:
print(0)
exit()
elif 946 <= x and x <= 999:
print(0)
exit()
elif 1051 <= x and x <= 1099:
print(0)
exit()
elif 1156 <= x and x <= 1199:
print(0)
exit()
elif 1261 <= x and x <= 1299:
print(0)
exit()
elif 1366 <= x and x <= 1399:
print(0)
exit()
elif 1471 <= x and x <= 1499:
print(0)
exit()
elif 1576 <= x and x <= 1599:
print(0)
exit()
elif 1681 <= x and x <= 1699:
print(0)
exit()
elif 1786 <= x and x <= 1799:
print(0)
exit()
elif 1891 <= x and x <= 1899:
print(0)
exit()
elif 1996 <= x and x <= 1999:
print(0)
exit()
else:
print(1)
exit()
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s783690454 | Accepted | p02843 | Input is given from Standard Input in the following format:
X | x = int(input())
total = 0
if x % 10 == 9:
total += 104 + 105
elif x % 10 == 8:
total += 104 + 104
elif x % 10 == 7:
total += 103 + 104
elif x % 10 == 6:
total += 105 + 101
elif x % 10 == 5:
total += 105
elif x % 10 == 4:
total += 104
elif x % 10 == 3:
total += 103
elif x % 10 == 2:
total += 102
elif x % 10 == 1:
total += 101
if x % 100 // 10 == 1:
total += 105 + 105
elif x % 100 // 10 == 2:
total += 105 * 4
elif x % 100 // 10 == 3:
total += 105 * 6
elif x % 100 // 10 == 4:
total += 105 * 8
elif x % 100 // 10 == 5:
total += 105 * 10
elif x % 100 // 10 == 6:
total += 105 * 12
elif x % 100 // 10 == 7:
total += 105 * 14
elif x % 100 // 10 == 8:
total += 105 * 16
elif x % 100 // 10 == 9:
total += 105 * 18
if total <= x:
print(1)
else:
print(0)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s256718655 | Wrong Answer | p02843 | Input is given from Standard Input in the following format:
X | X = int(input())
if (
X % 100 == 0
or X % 101 == 0
or X % 102 == 0
or X % 103 == 0
or X % 104 == 0
or X % 105 == 0
):
print(1)
elif (
X % 201 == 0
or X % 202 == 0
or X % 203 == 0
or X % 204 == 0
or X % 205 == 0
or X % 206 == 0
or X % 207 == 0
or X % 208 == 0
or X % 209 == 0
):
print(1)
elif (
X % 303 == 0
or X % 304 == 0
or X % 305 == 0
or X % 306 == 0
or X % 307 == 0
or X % 308 == 0
or X % 309 == 0
or X % 310 == 0
or X % 311 == 0
or X % 312 == 0
):
print(1)
elif (
X % 406 == 0
or X % 407 == 0
or X % 408 == 0
or X % 409 == 0
or X % 410 == 0
or X % 411 == 0
or X % 412 == 0
or X % 413 == 0
or X % 414 == 0
):
print(1)
elif (
X % 510 == 0
or X % 511 == 0
or X % 512 == 0
or X % 513 == 0
or X % 514 == 0
or X % 515 == 0
):
print(1)
elif X % 615 == 0:
print(1)
else:
print(0)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s571153295 | Wrong Answer | p02843 | Input is given from Standard Input in the following format:
X | n = int(input())
if n % 615 == 0:
print(1)
else:
if (
n % 100 == 0
or n % 101 == 0
or n % 102 == 0
or n % 103 == 0
or n % 104 == 0
or n % 105 == 0
):
print(1)
elif (
n % 206 == 0
or n % 207 == 0
or n % 208 == 0
or n % 201 == 0
or n % 202 == 0
or n % 203 == 0
or n % 204 == 0
or n % 205 == 0
):
print(1)
elif (
n % 303 == 0
or n % n % 304 == 0
or n % 305 == 0
or n % 306 == 0
or n % 307 == 0
or n % 308 == 0
or n % 309 == 0
or n % 310 == 0
or n % 311 == 0
or n % 312 == 0
):
print(1)
elif (
n % 406 == 0
or n % 407 == 0
or n % 408 == 0
or n % 409 == 0
or n % 410 == 0
or n % 411 == 0
or n % 412 == 0
or n % 413 == 0
or n % 414 == 0
):
print(1)
elif (
n % 510 == 0
or n % 511 == 0
or n % 512 == 0
or n % 513 == 0
or n % 514 == 0
or n % 515 == 0
):
print(1)
else:
print(0)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s918493670 | Accepted | p02843 | Input is given from Standard Input in the following format:
X | x = int(input())
k = int(x / 100)
h = x % 100
h2 = 0
for i in range(k):
if h - h2 >= 5:
h2 += 5
elif h - h2 >= 4:
h2 += 4
elif h - h2 >= 3:
h2 += 3
elif h - h2 >= 2:
h2 += 2
elif h - h2 >= 1:
h2 += 1
else:
pass
print(1) if h2 == h else print(0)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s838940521 | Runtime Error | p02843 | Input is given from Standard Input in the following format:
X | x = int(input())
a = int(str(x)[-2:])
b = int(str(x)[:-2])
counter = 0
while a >= 5:
a -= 5
counter += 1
while a >= 4:
a -= 4
counter += 1
while a >= 3:
a -= 3
counter += 1
while a >= 2:
a -= 2
counter += 1
while a >= 1:
a -= 1
counter += 1
print(1 if counter <= b else 0)
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
If it is possible to buy some set of items that cost exactly X yen in total,
print `1`; otherwise, print `0`.
* * * | s373191433 | Wrong Answer | p02843 | Input is given from Standard Input in the following format:
X | X = int(input())
arr = [
100,
101,
102,
103,
104,
105,
201,
202,
203,
204,
205,
206,
207,
208,
209,
303,
304,
305,
306,
307,
308,
406,
407,
408,
409,
500,
510,
511,
512,
513,
514,
615,
]
if X in arr:
print("1")
else:
print("0")
| Statement
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen each
* Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.
(Ignore consumption tax.) | [{"input": "615", "output": "1\n \n\nFor example, we can buy one of each kind of item, which will cost\n100+101+102+103+104+105=615 yen in total.\n\n* * *"}, {"input": "217", "output": "0\n \n\nNo set of items costs 217 yen in total."}] |
For each insert operation, print the number of elements in $S$.
For each find operation, print the number of specified elements in $S$. | s164980768 | Accepted | p02455 | The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $x$
where the first digits 0 and 1 represent insert and find operations
respectively. | n = int(input())
s = set()
for i in range(n):
a, b = map(int, input().split())
if a == 0:
s.add(b)
print(len(s))
else:
if b in s:
print(1)
else:
print(0)
| Set: Search
For a set $S$ of integers, perform a sequence of the following operations.
Note that _each value in $S$ must be unique_.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ in $S$ (0 or 1). | [{"input": "7\n 0 1\n 0 2\n 0 3\n 0 2\n 0 4\n 1 3\n 1 10", "output": "1\n 2\n 3\n 3\n 4\n 1\n 0"}] |
For each insert operation, print the number of elements in $S$.
For each find operation, print the number of specified elements in $S$. | s719878383 | Accepted | p02455 | The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $x$
where the first digits 0 and 1 represent insert and find operations
respectively. | tbl = set()
q = int(input())
for i in range(q):
a = input().split()
x = int(a[1])
if a[0] == "0":
tbl.add(x)
print(len(tbl))
else:
print(1 if x in tbl else 0)
| Set: Search
For a set $S$ of integers, perform a sequence of the following operations.
Note that _each value in $S$ must be unique_.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ in $S$ (0 or 1). | [{"input": "7\n 0 1\n 0 2\n 0 3\n 0 2\n 0 4\n 1 3\n 1 10", "output": "1\n 2\n 3\n 3\n 4\n 1\n 0"}] |
For each insert operation, print the number of elements in $S$.
For each find operation, print the number of specified elements in $S$. | s200404008 | Accepted | p02455 | The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $x$
where the first digits 0 and 1 represent insert and find operations
respectively. | def solve():
from sys import stdin
f_i = stdin
q = int(f_i.readline())
d = {}
ans = []
cnt = 0
for i in range(q):
op, x = map(int, f_i.readline().split())
if op == 0:
if d.setdefault(x, "0") == "0":
d[x] = "1"
cnt += 1
ans.append(str(cnt))
else:
ans.append(d.setdefault(x, "0"))
print("\n".join(ans))
solve()
| Set: Search
For a set $S$ of integers, perform a sequence of the following operations.
Note that _each value in $S$ must be unique_.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ in $S$ (0 or 1). | [{"input": "7\n 0 1\n 0 2\n 0 3\n 0 2\n 0 4\n 1 3\n 1 10", "output": "1\n 2\n 3\n 3\n 4\n 1\n 0"}] |
For each insert operation, print the number of elements in $S$.
For each find operation, print the number of specified elements in $S$. | s888948085 | Accepted | p02455 | The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $x$
where the first digits 0 and 1 represent insert and find operations
respectively. | import sys
s = set()
input()
for q in sys.stdin:
q = q.split()
if q[0] == "0":
s.add(q[1])
print(len(s))
else:
print(int(q[1] in s))
| Set: Search
For a set $S$ of integers, perform a sequence of the following operations.
Note that _each value in $S$ must be unique_.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ in $S$ (0 or 1). | [{"input": "7\n 0 1\n 0 2\n 0 3\n 0 2\n 0 4\n 1 3\n 1 10", "output": "1\n 2\n 3\n 3\n 4\n 1\n 0"}] |
Print the minimum number of elements that needs to be replaced.
* * * | s307539123 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | # abc111_c.py
# https://atcoder.jp/contests/abc111/tasks/arc103_a
# C - /\/\/\/ /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点
# 問題文
# 数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。
# 各 i=1,2,...,n−2について、ai=ai+2
# 数列に現れる数はちょうど 2種類
# 偶数長の数列 v1,v2,...,vnが与えられます。
# 要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。
# 制約
# 2≤n≤105
# nは偶数
# 1≤vi≤105
# viは整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# n
# v1 v2 ... vn
# 出力
# 書き換える要素数の最小値を出力してください。
# 入力例 1
# 4
# 3 1 3 2
# 出力例 1
# 1
# 数列 3,1,3,2は /\/\/\/ ではありませんが、1 要素書き換えることで /\/\/\/ にすることができます。
# 例えば、4 要素目を書き換えて 3,1,3,1とすればよいです。
# 入力例 2
# 6
# 105 119 105 119 105 119
# 出力例 2
# 0
# 数列 105,119,105,119,105,119は /\/\/\/ です。
# 入力例 3
# 4
# 1 1 1 1
# 出力例 3
# 2
# 数列 1,1,1,1は 1 種類の数からなる数列であるため、 /\/\/\/ ではありません。
def calculation(lines):
n = int(lines[0])
values = list(map(int, lines[1].split()))
# n = lines[0]
d_odd = dict()
d_even = dict()
for i in range(n):
value = values[i]
if i % 2 == 0:
if value in d_even.keys():
d_even[value] += 1
else:
d_even[value] = 1
else:
if value in d_odd.keys():
d_odd[value] += 1
else:
d_odd[value] = 1
n_even_max1st = 0
n_even_max2nd = 0
for key in d_even:
ma = d_even[key]
if n_even_max1st < ma:
key_even = key
n_even_max2nd = n_even_max1st
n_even_max1st = ma
n_odd_max1st = 0
n_odd_max2nd = 0
for key in d_odd:
ma = d_odd[key]
if n_odd_max1st < ma:
key_odd = key
n_odd_max2nd = n_odd_max1st
n_odd_max1st = ma
# 変数初期化
result = 0
# 奇数/偶数の最大値が異なる場合
if key_even != key_odd:
print("if d_even[key_even] != d_odd[key_odd]:")
result += int(n / 2) - n_even_max1st
result += int(n / 2) - n_odd_max1st
else:
m = max(n_even_max2nd, n_odd_max2nd)
result += int(n / 2) - n_even_max1st
result += int(n / 2) - m
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ["4", "3 1 3 2"]
lines_export = [1]
if pattern == 2:
lines_input = ["6", "105 119 105 119 105 119"]
lines_export = [0]
if pattern == 3:
lines_input = ["4", "1 1 1 1"]
lines_export = [2]
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
if len(args) == 1:
mode = 0
else:
mode = int(args[1])
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(2)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == "__main__":
main()
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s891024420 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | from collections import Counter as ct
n = int(input())
s = input().split()
a = ct(s[::2])
b = ct(s[1::2])
sa = sorted(a.items(), key=lambda x: -x[1])
sb = sorted(b.items(), key=lambda x: -x[1])
if sa[0][0] == sb[0][0]:
if len(sa) * len(sb) == 1:
dt = n // 2
elif sa[0][1] - sa[1][1] < sb[0][1] - sb[1][1] or len(sb) == 1:
dt = sa[1][1] + sb[0][1]
else:
dt = sa[0][1] + sb[1][1]
else:
dt = sa[0][1] + sb[0][1]
print(sum([x for x in a.values()] + [y for y in b.values()]) - dt)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s597874307 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | def cal(n, v):
k = n // 2
even = range(0, 2 * k, 2)
odd = range(1, 2 * k + 1, 2)
el = []
for i in even:
el.append(v[i])
ol = []
for i in odd:
ol.append(v[i])
d = {}
for i in el:
if (i in d) is False:
d[i] = 0
else:
d[i] += 1
f = {}
for i in ol:
if (i in f) is False:
f[i] = 0
else:
f[i] += 1
while True:
e = max(d, key=d.get)
o = max(f, key=f.get)
if e == o:
if d[e] > f[o]:
del f[o]
elif d[e] < f[o]:
del d[e]
else:
return print(k)
else:
break
sum = 0
for i in el:
if i != e:
sum += 1
for i in ol:
if i != o:
sum += 1
return print(sum)
n = int(input())
v = list(map(int, input().split()))
cal(n, v)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s948105518 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
l = [[0 for _ in range(10**5)] for _ in range(2)]
for i, j in enumerate(input().split()):
l[i % 2][int(j) - 1] += 1
A = max(l[0])
B = max(l[1])
a = l[0].index(A)
b = l[1].index(B)
if l[0].count(A) > 1 or l[1].count(B) > 1 or a != b:
print(n - A - B)
else:
l[0][a] = 0
l[1][b] = 0
C = max(l[0])
D = max(l[1])
print(min(n - A - D, n - B - C))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s741784793 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | # n <= 10**5
n = int(input())
# vi <= 10**5
v = list(map(int, input().split()))
a = [[0, 0] for _ in range(100010)]
for i in range(n):
a[i % 2][v[i]] += 1
od, ev = [], []
for i in range(100010):
od.append([a[1][i], i])
ev.append([a[0][i], i])
od.sort()
od.reverse()
ev.sort()
ev.reverse()
if od[0][1] != ev[0][1]: print(n - od[0][0] - ev[0][0])
else: print(n - max(od[0][0] + ev[[0][1], od[1][0] + ev[0][0])) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s723258160 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input().rstrip())
v_list = input().rstrip().split(" ")
result = 0
finish_num = n // 2
for i in range(finish_num):
if v_list[i] != v_list[i + 2]:
result += 1
print(result)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s325640367 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | from collections import Counter
n=int(input())
origin_list=list(map(int,input().split()))
list_1=[]
list_2=[]
for i in range(1,n/2):
list_1.append(origin_list[i])
for i in range((n/2)-1):
list_2.append(origin_list[i]
mode1=list_1.most_common(1)[0][1]
mode2=list_2.most_common(1)[0][1]
print(n-(mode1+mode2)) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s265748019 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0] != b[0][0]:
print(n-(a[0][1]+b[0][1]))
else:
print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1]))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s043630189 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]
n = int(input())
a = ai()
if all(i == a[0] for i in a):
print(n//2)
exit()
a1 = a[::2]
a2 = a[1::2]
from collections import Counter
c1 = Counter(a1)
c2 = Counter(a2)
m1 = c1.most_common(2)
m2 = c2.most_common(2)
if m1[0][0] == m2[0][0]:
if len(c1) == 1:
print(n-m1[0][1]-m2[1][1])
elif len(c2) == 1:
print(n - m1[0][1] - m2[1][1])
else:
print(min(n-m1[0][1]-m2[1][1], n-m1[1][1]-m2[0][1]))
else:
print(n-m1[0 | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s174141173 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
v = list(map(int, input().split()))
a = sorted(([i,v[::2].count(i)] for i in set(v[::2])), key=lambda x:x[1])
b = sorted(([j,v[1::2].count(j)] for j in set(v[1::2])),key=lambda x:x[1])
if a[-1]!=b[-1]:
print(n-a[-1][1]-b[-1][1])
elif len(a) == 1 and len(b) == 1:
print(min(a[-1][1],b[-1][1]))
elif len(a) ==1:
print(n-a[-1][1]-b[-2][1])
elif len(b) ==1:
print(n-a[-2][1]-b[-1][1])
else:
print(min(n-a[-2][1]-b[-1][1],n-a[-1][1]-b[-2][1]) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s397222316 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | odds = [n * ((i + 1) % 2) for i, n in enumerate(vs)]
evens = [n * (i % 2) for i, n in enumerate(vs)]
half = int(N / 2)
odds_half = sorted(odds)[half:]
evens_half = sorted(evens)[half:]
om_n = 0
om_c = 0
for n in set(odds_half):
if odds_half.count(n) > om_c:
om_n = n
em_n = 0
em_c = 0
for n in set(evens_half):
if evens_half.count(n) > em_c:
em_n = n
sum_odds = sum(map(lambda x: abs(x - om_n), odds_half))
sum_evens = sum(map(lambda x: abs(x - em_n), evens_half))
print(sum_odds + sum_evens)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s642324885 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
v = list(map(int,input().split()))
s = []
t = []
import collections
for i in range(0,n,2):
s.append(v[i])
for i in range(1,n,2):
t.append(v[i])
S = Counter(s)
T = Counter(t)
x = S.most_common()[0][0] #sの最頻値
y = S.most_common()[1][0] #sの2番目に多いやつ
z = T.most_common()[0][0]
w = T.most_common()[1][0]
if x!=z:
print(n-S.most_common()[0][1]-T.most_common()[0][1])
elif y>w:
print(n-S.most_common()[0][1]-S.most_common()[1][1])
else:
print(n-S.most_common()[0][1]-T.most_common()[1][1])
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s521605115 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | if __name__ == '__main__': n = int(input())
vs = list(map(int, input().split()))
even = vs[::2]
odd = vs[1::2]
from collections import Counter
result = 0
#evenの処理
ce = Counter(even)
emode = ce.most_common(1)[0]
oe = Counter(odd)
omode = oe.most_common(1)[0]
if emode[0] == omode[0]:
if emode[1] > omode[1]:
for i in range(len(even)):
if even[i] != emode[0]:
result += 1
if len(oe.most_common()) == 1:
omode = -1
result += len(odd)
else:
omode = oe.most_common(2)[0][0]
for i in range(len(odd)):
if odd[i] != omode:
result += 1
else:
for i in range(len(odd)):
if odd[i] != omode[0]:
result += 1
if len(ce.most_common()) == 1:
emode = -1
result += len(even)
else:
emode = ce.most_common(2)[0][0]
for i in range(len(even)):
if even[i] != emode:
result += 1
else:
for i in range(len(even)):
if even[i] != emode[0]:
result += 1
for i in range(len(odd)):
if odd[i] != omode[0]:
result += 1
print(result) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s511974816 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | #111c
import collections
import copy
n = int(input()) #2≤n≤10**5 偶数
v_list = [int(e) for e in input().split()]
#数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。
#・各 i=1,2,...,n−2について、ai=ai+2
#・数列に現れる数はちょうど 2種類
#偶数長の数列 v1,v2,...,vnが与えられます。
#要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。
#一番多く出てくる文字を求め、書き換えない数字を決める
v_list_odd = [v_list[i] for i in range(n) if i%2==1]
v_list_even = [v_list[i] for i in range(n) if i%2==0]
#print(v_list_odd)
#print(v_list_even)
c = collections.Counter(v_list_odd)
v_list_odd_counter = copy.copy(c)
if len(c)>1:
fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
c = collections.Counter(v_list_even)
v_list_even_counter = copy.copy(c)
if len(c)>1:
fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
#固定文字の決定
#1文字目が重複していなければ、両方とも出現回数最多を固定する
if fix_picklist_for_v_list_even[0] != fix_picklist_for_v_list_odd[0]:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
#1文字目が重複している場合
#両方1文字しかなければ片方のみ
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) == 2:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
fix_char_for_v_list_odd = "!"
#片方が1文字ならば、そうでない方は2文字目を使う。
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) != 2:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif len(fix_picklist_for_v_list_even) != 2 and len(fix_picklist_for_v_list_odd) == 2:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
#両方2文字あるなら、固定パターンの合計が多い方を採用
elif fix_picklist_for_v_list_even[1] + fix_picklist_for_v_list_odd[3] > fix_picklist_for_v_list_even[3]+fix_picklist_for_v_list_odd[1]:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif fix_picklist_for_v_list_even[1] + fix_picklist_for_v_list_odd[3] =< fix_picklist_for_v_list_even[3]+fix_picklist_for_v_list_odd[1]:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
#print(fix_char_for_v_list_odd)
#print(fix_char_for_v_list_even)
#書き換え要素数をカウント
ans_odd = n/2 - v_list_odd_counter[fix_char_for_v_list_odd]
ans_even = n/2 - v_list_even_counter[fix_char_for_v_list_even]
print(int(ans_odd + ans_even)) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s955957832 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = v[::2]
ki = v[1::2]
ans = 0
k,g = False,False
###全部同じなら全長の半分,
# 最頻値が同じなら2番目を比べる
if v.count(v[0]) == n
ans += n // 2
else:
kic = Counter(ki)
guc = Counter(gu)
k1 = kic.most_common(2)
g1 = guc.most_common(2)
if k1[0][0] == g1[0][0]:
if k1[1][1] < g1[1][1]:
g = True
else:
k = True
kic = list(kic.values())
guc = list(guc.values())
kic.sort(reverse = True)
guc.sort(reverse = True)
if len(kic) != 1:
if k:
ans += kic[0]
ans += sum(kic[2::])
else:
ans += sum(kic[1::])
if len(guc) != 1:
if g:
ans += guc[0]
ans += sum(guc[2::])
else:
ans += sum(guc[1::])
print(ans) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s684678718 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | # coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
n = int(input())
v = list(map(int, input().split()))
a = defaultdict(int)
b = defaultdict(int)
nn = n // 2
for i in range(nn):
a[v[i * 2]] += 1
b[v[i * 2 + 1]] += 1
ma1 = max(a, key=a.get)
mb1 = max(b, key=b.get)
mva1 = a[ma1]
mvb1 = b[mb1]
a[ma1] = 0
b[mb1] = 0
ma2 = max(a, key=a.get)
mb2 = max(b, key=b.get)
mva2 = a[ma2]
mvb2 = b[mb2]
a[ma2] = 0
b[mb2] = 0
ma = [(ma1, mva1), (ma2, mva2)]
mb = [(mb1, mvb1), (mb2, mvb2)]
mx = 0xFFFFFFFF
for i in ma:
for j in mb:
if i[0] == j[0]:
pass
else:
mx = min(sum(a.values()) + i[1] + sum(b.values()) + j[1], mx)
if mx == 0xFFFFFFFF:
print(0)
else:
print(mx | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s145564406 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | if __name__ == '__main__': n = int(input())
vs = list(map(int, input().split()))
even = vs[::2]
odd = vs[1::2]
from collections import Counter
result = 0
#evenの処理
c = Counter(even)
emode = c.most_common(1)[0][0]
for i in range(len(even)):
if even[i] != emode:
result += 1
c = Counter(odd)
if c.most_common(1)[0][0] != emode:
omode = c.most_common(1)[0][0]
else:
if len(c.most_common()) == 1:
omode = -1
else:
omode = c.most_common(2)[0][0]
for i in range(len(odd)):
if odd[i] != omode:
result += 1
if __name__ == '__main__': n = int(input())
vs = list(map(int, input().split()))
even = vs[::2]
odd = vs[1::2]
from collections import Counter
result = 0
#evenの処理
c = Counter(even)
emode = c.most_common(1)[0][0]
for i in range(len(even)):
if even[i] != emode:
result += 1
c = Counter(odd)
if c.most_common(1)[0][0] != emode:
omode = c.most_common(1)[0][0]
else:
if len(c.most_common()) == 1:
omode = -1
else:
omode = c.most_common(2)[0][0]
for i in range(len(odd)):
if odd[i] != omode:
result += 1
print(result) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s039584186 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
v = list(map(int, input().split()))
array1 = v[::2]
array2 = v[1::2]
dict1 = {}
dict2 = {}
for i in array1:
if i not in dict1:
dict1[i] = 1
else:
dict1[i] = dict1[i] + 1
for i in array2:
if i not in dict2:
dict2[i] = 1
else:
dict2[i] = dict2[i] + 1
sort_array1 = []
sort_array2 = []
for k, v in sorted(dict1.items(), key=lambda x: -x[1]):
sort_array1.append({k:v})
for k, v in sorted(dict2.items(), key=lambda x: -x[1]):
sort_array2.append({k:v})
one_num1 = 0
one_num2 = 0
for k1,v1 in sort_array1[0].items():
if len(sort_array1) != 1:
one_num1 = len(array1) - v1
for k2,v2 in sort_array2[0].items():
if len(sort_array2) != 1:
one_num2 = len(array2) - v2
if k1 != k2:
print(one_num1 + one_num2)
break
if len(sort_array1) == 1 and len(sort_array2) == 1:
print(len(array1))
break
if len(sort_array1) == 1:
for k,v in sort_array2[1].items():
two_num2 = v
print(1+two_num2)
break
if len(sort_array2) == 1:
for k,v in sort_array1[1].items():
two_num1 = v
print(1+two_num1)
break
for k,v in sort_array1[1].items():
two_num1 = len(array1) - v
for k,v in sort_array2[1].items():
two_num2 = len(array2) - v
if two_num1 <= two_num2:
print (one_num2 + two_num1)
else:
print (one_num1 + two_num2)
~ | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s925431085 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = input()
x = list(map(int, input().split(" ")))
ki = []
gu = []
ki = x[0::2]
gu = x[1::2]
a = set(ki)
dd = 0
z = ki.count(a[0])
b = [0, z]
for i in range(1, len(a)):
c = ki.count(a[i])
b.append(c)
if z < c:
dd = i
a2 = set(gu)
bb = 0
y = gu.count(gu[0])
d = [0, y]
for i in range(1, len(a2)):
c = gu.count(a2[i])
d.append(c)
if y < c:
bb = i
if a[dd] != a2[bb]:
print(len(ki) - max(b) + len(gu) - max(d))
else:
if max(a) > max(a2):
d = sorted(d, reverse=True)
print(len(ki) - max(b) + len(gu) - d[1])
else:
b = sorted(b, reverse=True)
print(len(ki) - b[1] + len(gu) - max(d))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s488628222 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n=int(input())
v = list(map(int,input().split()))
dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
if i%2==0:
dic0[v[i]] += 1
if i%2==1:
dic1[v[i]] += 1
MX0_1 = max(dic0)
MX1_1 = max(dic1)
li0 = []
li1 = []
for i in range(10**5+1):
if dic0[i]>10:
#print(i,dic0[i])
if dic1[i]>10:
#print(i,dic1[i],"\n")
if dic0[i] == MX0_1:
li0.append(i)
dic0[i] = 0
if dic1[i] == MX1_1:
li1.append(i)
dic1[i] = 0
# print(li0,li1)
# print(MX0_1,MX0_1)
if len(li0)>=2 or len(li1)>=2:
print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
if MX0_1+max(dic1) >= MX1_1+max(dic0):
print(n-MX0_1-max(dic1))
else:
print(n-MX1_1-max(dic0))
print(1/0)
elif li0[0] != li1[0]:
print(n-MX0_1-MX1_1) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s663539115 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n//2):
a.append(v[i*2])
b.append(v[i*2+1])
A = collections.Counter(a)
B = collections.Counter(b)
if A.most_common()[0][0] != B.most_common()[0][0]:
ans = n - A.most_common()[0][1] - B.most_common()[0][1]
elif len(A) > 1 and len(B) > 1:
if A.most_common()[0][0] + B.most_common()[1][0] < A.most_common()[1][0] + B.most_common()[0][0]:
ans = n - (A.most_common()[1][0] + B.most_common()[0][0])
else:
ans = n - (A.most_common()[0][0] + B.most_common()[1][0])
elif len(A)=1 and len(B)>1:
ans = n - B.most_common()[1][0]
elif len(A)>1 and len(B)=1:
ans = n - A.most_common()[1][0]
else:
ans = n//2
print(ans) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s562933580 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | from collections import Counter
N = int(input())
arr = [input() for i in range(0,N)]
odd = arr[0::2]
even = arr[1::2]
odd_counter = Counter(odd)
even_counter = Counter(even)
odd_mode = odd_counter.most_common()[0][0]
even_mode = even_counter.most_common()[0][0]
odd_diff = (N / 2) - odd_counter.most_common()[0][1]
even_diff = (N / 2) - even_counter.most_common()[0][1]
if odd_mode != even_mode:
print(odd_diff + even_diff)
else:
odd_diff2 = (N / 2) - odd_counter.most_common()[1][1]
even_diff2 = (N / 2) - even_counter.most_common()[1][1]
if odd_diff2 > even_diff2:
print(odd_diff + even_diff2)
else:
print(odd_diff2 + even_diff)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s468456785 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | _ = input()
seq = list(map(int,input().split()))
seq1 = seq[::2]
seq2 = seq[1::2]
if len(set(seq)) == 1:
print(min(len(seq1),len(seq2)))
exit()
def count_dictonary(seq):
ret_dict={}
for item in seq:
if item not in ret_dict:
ret_dict[item] = 1
else:
ret_dict[item]+=1
return ret_dict
'''
seq_dict1 = count_dictonary(seq1)
seq_dict2 = count_dictonary(seq2)
min_change=len(seq)
for i1 in seq_dict1:
for i2 in seq_dict2:
ch1 = len(seq1) - seq_dict1[i1]
ch2 = len(seq2) - seq_dict2[i2]
#print(i1,i2,ch1,ch2,ch1+ch2)
change_ = ch1+ch2
if(min_change > ch1+ch2):
min_change = ch1+ch2
print(min_change)
''' | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s435029845 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = [::2]
ki = [1::2]
ans = 0
k,g = False,False
if v.count(v[0]) == n:#全部同じ
ans += n // 2
else:
kic = Counter(ki)
guc = Counter(gu)
k1 = kic.most_common(2)
g1 = guc.most_common(2)
if k1[0][0] == g1[0][0]:
if k1[1][1] < g1[1][1]:
k = True
elif k1[1][1] > g1[1][1]:
g = True
kic = list(kic.values())
guc = list(guc.values())
kic.sort(reverse = True)
guc.sort(reverse = True)
if len(kic) != 1:
if k:
ans += kic[0]
ans += sum(kic[2::])
else:
ans += sum(kic[1::])
if len(guc) != 1:
if g:
ans += guc[0]
ans += sum(guc[2::])
else:
ans += sum(guc[1::])
print(ans) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s414581363 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | from collections import Counter
n = int(input())
V = [int(n) for n in input().split()]
if len(set(V)) == 1:
ans = len(V) // 2
else:
vp_ = [v for i, v in enumerate(V) if i%2 == 0]
vn_ = [v for i, v in enumerate(V) if i%2 != 0]
vp = Counter(vp_).most_common()
vn = Counter(vn_).most_common()
if vp[0][0] != vn[0][0]:
gp = vp[0][1]
gn = vn[0][1]
else:
if vp[0][1] > vn[0][1]:
gp = vp[0][1]
gn = vn[1][1]
elif vp[0][1] < vn[0][1]:
gp = vp[1][1]
gn = vn[0][1]
else vp[0][1] == vn[0][1]:
if vp[1][1] >= vn[1][1]:
gp = vp[1][1]
gn = vn[0][1]
else:
gp = vp[0][1]
gn = vn[1][1]
ans = n - gp - gn
print(ans) | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s717181989 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
int main()
{
int n;
cin >> n;
int v[n];
rep(i, n) cin >> v[i];
int seq0[100001] = {}, seq1[100001] = {};
for (int i = 0; i < n; i += 2)
++seq0[v[i]];
for (int i = 1; i < n; i += 2)
++seq1[v[i]];
sort(seq0 + 1, seq0 + 100001, greater<int>());
sort(seq1 + 1, seq1 + 100001, greater<int>());
if (seq0[0] == seq1[0])
cout << min(n - seq0[0][0] - seq1[0][1], n - seq[0][1] - seq1[0][0]);
else
cout << n - seq0[0][0] - seq1[0][0];
} | Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s661483886 | Runtime Error | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n=int(input())
N=list(map(int,input().split()))
even=[]
odd=[]
for i in range(len(N)):
if i%2==0:
even.append(N[i])
if i%2==1:
odd.append(N[i])
import collections
c = collections.Counter(even)
x=c.most_common()[0][0]
o=even.count(x)
d= collections.Counter(odd)
y=d.most_common()[0][0]
p=odd.count(y)
s=len(even)-even.count(x)
t=len(odd)-odd.count(y)
if x!=y and o==len(even) and p==len(odd):
print(0)
elif x==y and o==len(even) and p==len(odd):
print(n/2)
elif x==y and (o!=len(even) or p!=len(odd)):
if o>p:
y=d.most_common()[1][0]
s=len(even)-even.count(x)
t=len(odd)-odd.count(y)
print(s+t)
else:
x=c.most_common()[1][0]
s=len(even)-even.count(x)
t=len(odd)-odd.count(y)
print(s+t)
elif:
print(s+t)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s660751666 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
list_v = list((map(int, input().split())))
list_e = list_v[::2]
list_o = list_v[1::2]
dict_e = {}
dict_o = {}
for number in set(list_e):
dict_e[number] = 0
for i in range(0, int(n / 2)):
dict_e[list_e[i]] += 1
for number in set(list_o):
dict_o[number] = 0
for i in range(0, int(n / 2)):
dict_o[list_o[i]] += 1
e_max = 0
o_max = 0
for key in dict_e.keys():
if dict_e[key] > e_max:
e_max = dict_e[key]
e_key = key
for key in dict_o.keys():
if dict_o[key] > o_max:
o_max = dict_o[key]
o_key = key
ans = o_max + e_max
if e_key == o_key:
e_max2 = 0
for key in dict_e.keys():
if dict_e[key] > e_max2 and key != o_key:
e_max2 = dict_e[key]
e_key2 = key
o_max2 = 0
for key in dict_o.keys():
if dict_o[key] > o_max2 and key != e_key:
o_max2 = dict_o[key]
o_key2 = key
ans = max(e_max + o_max2, e_max2 + o_max)
print(n - ans)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s742960243 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | N = int(input())
V = list(map(int, input().split()))
def m():
first = V[0::2]
second = V[1::2]
fdic = {}
sdic = {}
for i in range(N // 2):
if fdic.get(first[i], 0) == 0:
fdic[first[i]] = 1
else:
fdic[first[i]] += 1
if sdic.get(second[i], 0) == 0:
sdic[second[i]] = 1
else:
sdic[second[i]] += 1
flist = list(fdic.items())
slist = list(sdic.items())
flist.sort(reverse=True, key=lambda x: x[1])
slist.sort(reverse=True, key=lambda x: x[1])
if flist[0][0] != slist[0][0] and len(flist) == 1 and len(slist) == 1:
return 0
if flist[0][0] != slist[0][0]:
ans = 0
for k, v in flist[1:]:
ans += v
for k, v in slist[1:]:
ans += v
return ans
if flist[0][1] == slist[0][1]:
return N // 2
if flist[0][1] > slist[0][1]:
ans = 0
for k, v in flist[1:]:
ans += v
for k, v in slist[2:]:
ans += v
ans += slist[0][0]
return ans
else:
ans = 0
for k, v in slist[1:]:
ans += v
for k, v in flist[2:]:
ans += v
ans += flist[0][0]
return ans
print(m())
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s660770877 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | import collections
n, *v = map(int, open(0).read().split())
v1 = [0] * (n // 2)
v2 = [0] * (n // 2)
for i in range(n // 2):
v1[i] = v[2 * i]
v2[i] = v[2 * i + 1]
v1_cnt = collections.Counter(v1)
v2_cnt = collections.Counter(v2)
v1_cnt_l = sorted(list(v1_cnt.values()))
v2_cnt_l = sorted(list(v2_cnt.values()))
# print(v1_cnt_l, v2_cnt_l)
if max(v1_cnt, key=v1_cnt.get) == max(v2_cnt, key=v2_cnt.get):
if 1 < len(v1_cnt_l) and 1 < len(v2_cnt_l):
# print('1 1')
num1 = sum(v1_cnt_l) - v1_cnt_l[-1]
num1 += sum(v2_cnt_l) - v2_cnt_l[-2]
num2 = sum(v1_cnt_l) - v1_cnt_l[-2]
num2 += sum(v2_cnt_l) - v2_cnt_l[-1]
num = min(num1, num2)
elif 1 < len(v1_cnt_l):
# print('2 2')
num = sum(v1_cnt_l) - v1_cnt_l[-2]
num += sum(v2_cnt_l) - v2_cnt_l[-1]
elif 1 < len(v2_cnt_l):
# print('3 3')
num = sum(v1_cnt_l) - v1_cnt_l[-1]
num += sum(v2_cnt_l) - v2_cnt_l[-2]
else:
# print('4 4')
num = n // 2
else:
num = sum(v1_cnt_l) - v1_cnt_l[-1]
num += sum(v2_cnt_l) - v2_cnt_l[-1]
print(num)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s363770543 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | import math
class xx:
val = 0
num = 0
def __init__(self, v, n):
self.val, self.num = v, n
while True:
try:
n = eval(input().strip())
arr = list(map(int, input().strip().split()))
one = {}
two = {}
for i in range(0, n, 2):
if arr[i] in one.keys():
one[arr[i]] = one[arr[i]] + 1
else:
one[arr[i]] = 1
for i in range(1, n, 2):
if arr[i] in two.keys():
two[arr[i]] = two[arr[i]] + 1
else:
two[arr[i]] = 1
# print(one)
# print(two)
one = sorted(one.items(), key=lambda x: x[1], reverse=True)
two = sorted(two.items(), key=lambda x: x[1], reverse=True)
# print(one)
# print(two)
if one[0][0] != two[0][0]:
sum = n // 2 - one[0][1]
sum += n // 2 - two[0][1]
print(sum)
elif one[0][0] == two[0][0] and one[0][1] == two[0][1] and one[0][1] == n // 2:
print(n // 2)
elif one[0][0] == two[0][0]:
len1 = len(one)
len2 = len(two)
if len1 >= 2 and len2 >= 2:
sum = n // 2 - one[0][1]
sum += n // 2 - two[1][1]
sum2 = n // 2 - one[1][1]
sum2 += n // 2 - two[0][1]
print(min(sum, sum2))
elif len1 == 1 and len2 >= 2:
sum = n // 2 - one[0][1]
sum += n // 2 - two[1][1]
print(sum)
elif len1 >= 2 and len2 == 1:
sum = n // 2 - one[1][1]
sum += n // 2 - two[0][1]
print(sum)
except:
break
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s952087602 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | ###############################################################################
from bisect import bisect_left as binl
from copy import copy, deepcopy
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * y) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def get_divisors(x):
retlist = []
for i in range(1, int(x**0.5) + 3):
if x % i == 0:
retlist.append(i)
retlist.append(x // i)
return retlist
def make_linklist(xylist):
linklist = {}
for a, b in xylist:
linklist.setdefault(a, [])
linklist.setdefault(b, [])
linklist[a].append(b)
linklist[b].append(a)
return linklist
def calc_longest_distance(linklist, v=1):
distance_list = {}
distance_count = 0
distance = 0
vlist_previous = []
vlist = [v]
nodecount = len(linklist)
while distance_count < nodecount:
vlist_next = []
for v in vlist:
distance_list[v] = distance
distance_count += 1
vlist_next.extend(linklist[v])
distance += 1
vlist_to_del = vlist_previous
vlist_previous = vlist
vlist = list(set(vlist_next) - set(vlist_to_del))
max_distance = -1
max_v = None
for v, distance in distance_list.items():
if distance > max_distance:
max_distance = distance
max_v = v
return (max_distance, max_v)
def calc_tree_diameter(linklist, v=1):
_, u = calc_longest_distance(linklist, v)
distance, _ = calc_longest_distance(linklist, u)
return distance
###############################################################################
def make_1st_2nd_list(countlist):
max_v_list = []
max_v_list_2nd = []
max_count = -1
max_count_2nd = -1
for i, count in enumerate(countlist):
if count > max_count:
max_count_2nd = max_count
max_v_list_2nd = max_v_list
max_count = count
max_v_list = [i]
elif count == max_count:
max_v_list.append(i)
elif count > max_count_2nd:
max_count_2nd = count
max_v_list_2nd = [i]
elif count == max_count_2nd:
max_v_list_2nd.append(i)
return (max_v_list, max_v_list_2nd)
def main():
n = intin()
vlist = intina()
countlist0 = [0] * (10**5 + 1)
countlist1 = [0] * (10**5 + 1)
for i, v in enumerate(vlist):
if i % 2 == 0:
countlist0[v] += 1
else:
countlist1[v] += 1
max_v_list0, max_v_list_2nd0 = make_1st_2nd_list(countlist0)
max_v_list1, max_v_list_2nd1 = make_1st_2nd_list(countlist1)
if (
len(max_v_list0) == 1
and len(max_v_list1) == 1
and max_v_list0[0] == max_v_list1[0]
):
if not max_v_list_2nd0 and not max_v_list_2nd1:
print(n // 2)
elif not max_v_list_2nd0:
print(n - countlist0[max_v_list0[0]] - countlist1[max_v_list_2nd1[0]])
elif not max_v_list_2nd1:
print(n - countlist0[max_v_list_2nd0[0]] - countlist1[max_v_list1[0]])
else:
c0 = countlist0[max_v_list0[0]]
c1 = countlist1[max_v_list1[0]]
ans1 = n - countlist0[max_v_list0[0]] - countlist1[max_v_list_2nd1[0]]
ans2 = n - countlist0[max_v_list_2nd0[0]] - countlist1[max_v_list1[0]]
print(min(ans1, ans2))
return
print(n - countlist0[max_v_list0[0]] - countlist1[max_v_list1[0]])
if __name__ == "__main__":
main()
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s638030831 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
v = [{}, {}]
for i, vi in enumerate(map(int, input().split())):
j = i % 2
v[j].update([(vi, v[j][vi] + 1)]) if vi in v[j] else v[j].update([(vi, 1)])
f1 = lambda v, i: max(v[i], key=v[i].get) if len(v[i]) > 0 else 0
f2 = lambda v, i, k: v[i].pop(k) if len(v[i]) > 0 else 0
kMax, vMax = [], []
for i in [0, 1]:
kMax.append([f1(v, 0), f1(v, 1)])
vMax.append([f2(v, 0, kMax[i][0]), f2(v, 1, kMax[i][1])])
if kMax[0][0] != kMax[0][1]:
print(n - sum(vMax[0]))
else:
print(n - max([vMax[0][0] + vMax[1][1], vMax[0][1] + vMax[1][0]]))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s412301845 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n1 = int(input())
n2 = [int(i) for i in input().split()]
n3 = []
n4 = []
for i1 in range(n1):
if i1 % 2 == 0:
n3.append(n2[i1])
else:
n4.append(n2[i1])
n3.sort()
n4.sort()
t1 = 0
c1 = 0
n5 = []
for i2 in range(len(n3)):
if n3[i2] == t1:
c1 += 1
if i2 == len(n3) - 1:
n5.append([t1, c1])
else:
if i2 != 0:
n5.append([t1, c1])
t1 = n3[i2]
c1 = 1
if i2 == len(n3) - 1:
n5.append([t1, c1])
t1 = 0
c1 = 0
n6 = []
for i3 in range(len(n4)):
if n4[i3] == t1:
c1 += 1
if i3 == len(n4) - 1:
n6.append([t1, c1])
else:
if i3 != 0:
n6.append([t1, c1])
t1 = n4[i3]
c1 = 1
if i3 == len(n4) - 1:
n6.append([t1, c1])
n5.sort(key=lambda x: (x[1], x[0]), reverse=True)
n6.sort(key=lambda x: (x[1], x[0]), reverse=True)
r1 = 0
if len(n5) == 1 and len(n6) == 1 and n5[0][0] == n6[0][0]:
r1 = n1 // 2
else:
if n5[0][0] != n6[0][0]:
r1 = n1 - n5[0][1] - n6[0][1]
else:
if len(n5) == 1:
r1 = n1 - n5[0][1] - n6[1][1]
elif len(n6) == 1:
r1 = n1 - n5[1][1] - n6[0][1]
else:
if (n1 - n5[0][1] - n6[1][1]) >= (n1 - n5[1][1] - n6[0][1]):
r1 = r1 = n1 - n5[1][1] - n6[0][1]
else:
r1 = n1 - n5[0][1] - n6[1][1]
print(r1)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s212903948 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | a = int(input())
b = list(map(int, input().split()))
c = {}
for i in range(a):
if str(b[i]) in c:
c[str(b[i])] += 1
else:
c[str(b[i])] = 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
if len(c) <= 1:
print(a // 2)
elif len(c) == 2:
e = [int(c[0][0]), int(c[1][0])] + b
f = [int(c[1][0]), int(c[0][0])] + b
ec = 0
fc = 0
for i in range(2, len(e)):
if e[i] != e[i - 2]:
e[i] = e[i - 2]
ec += 1
if f[i] != f[i - 2]:
f[i] = f[i - 2]
fc += 1
print(min(ec, fc))
elif len(c) >= 3:
e = [int(c[0][0]), int(c[1][0])] + b
f = [int(c[1][0]), int(c[0][0])] + b
g = [int(c[0][0]), int(c[2][0])] + b
h = [int(c[1][0]), int(c[2][0])] + b
j = [int(c[2][0]), int(c[0][0])] + b
k = [int(c[2][0]), int(c[1][0])] + b
ec = 0
fc = 0
gc = 0
hc = 0
jc = 0
kc = 0
for i in range(2, len(e)):
if e[i] != e[i - 2]:
e[i] = e[i - 2]
ec += 1
if f[i] != f[i - 2]:
f[i] = f[i - 2]
fc += 1
if g[i] != g[i - 2]:
g[i] = g[i - 2]
gc += 1
if h[i] != h[i - 2]:
h[i] = h[i - 2]
hc += 1
if j[i] != j[i - 2]:
j[i] = j[i - 2]
jc += 1
if k[i] != k[i - 2]:
k[i] = k[i - 2]
kc += 1
print(min(ec, fc, gc, hc, jc, kc))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s694187344 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | # 111c
import collections
import copy
n = int(input()) # 2≤n≤10**5 偶数
v_list = [int(e) for e in input().split()]
# 数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。
# ・各 i=1,2,...,n−2について、ai=ai+2
# ・数列に現れる数はちょうど 2種類
# 偶数長の数列 v1,v2,...,vnが与えられます。
# 要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。
# 一番多く出てくる文字を求め、書き換えない数字を決める
v_list_odd = [v_list[i] for i in range(n) if i % 2 == 1]
v_list_even = [v_list[i] for i in range(n) if i % 2 == 0]
# print(v_list_odd)
# print(v_list_even)
c = collections.Counter(v_list_odd)
v_list_odd_counter = copy.copy(c)
if len(c) > 1:
fix_picklist_for_v_list_odd = [
((c.most_common(2))[0])[0],
((c.most_common(2))[0])[1],
((c.most_common(2))[1])[0],
((c.most_common(2))[1])[1],
]
else:
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd = [
((c.most_common(2))[0])[0],
((c.most_common(2))[0])[1],
]
c = collections.Counter(v_list_even)
v_list_even_counter = copy.copy(c)
if len(c) > 1:
fix_picklist_for_v_list_even = [
((c.most_common(2))[0])[0],
((c.most_common(2))[0])[1],
((c.most_common(2))[1])[0],
((c.most_common(2))[1])[1],
]
else:
fix_picklist_for_v_list_even = [
((c.most_common(2))[0])[0],
((c.most_common(2))[0])[1],
]
# 固定文字の決定
# 1文字目が重複していなければ、両方とも出現回数最多を固定する
if fix_picklist_for_v_list_even[0] != fix_picklist_for_v_list_odd[0]:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
# 1文字目が重複している場合
# 両方1文字しかなければ片方のみ
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) == 2:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
fix_char_for_v_list_odd = "!"
# 片方が1文字ならば、そうでない方は2文字目を使う。
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) != 2:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif len(fix_picklist_for_v_list_even) != 2 and len(fix_picklist_for_v_list_odd) == 2:
fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
# 両方2文字あるなら、固定パターンの合計が多い方を採用
elif (
fix_picklist_for_v_list_even[0] + fix_picklist_for_v_list_odd[2]
> fix_picklist_for_v_list_even[2] + fix_picklist_for_v_list_odd[0]
):
fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif (
fix_picklist_for_v_list_even[0] + fix_picklist_for_v_list_odd[2]
<= fix_picklist_for_v_list_even[2] + fix_picklist_for_v_list_odd[0]
):
fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
# print(fix_char_for_v_list_odd)
# print(fix_char_for_v_list_even)
# 書き換え要素数をカウント
ans_odd = n / 2 - v_list_odd_counter[fix_char_for_v_list_odd]
ans_even = n / 2 - v_list_even_counter[fix_char_for_v_list_even]
print(int(ans_odd + ans_even))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s468154151 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | import copy
n = int(input())
li = input().split(" ")
el = []
ol = []
for i in range(n):
if i % 2 == 0:
el.append(int(li[i]))
else:
ol.append(int(li[i]))
n_el = len(list(set(el)))
n_ol = len(list(set(ol)))
if n_el == 1 and n_ol == 1 and el[0] != ol[0]:
print(0)
elif n_el == 1 and n_ol == 1 and el[0] == ol[0]:
print(len(ol))
else:
els = {}
ols = {}
for e in el:
if str(e) in els:
els[str(e)] += 1
else:
els[str(e)] = 1
for o in ol:
if str(o) in ols:
ols[str(o)] += 1
else:
ols[str(o)] = 1
# print(els)
# print(ols)
elv = list(els.values())
olv = list(ols.values())
elk = sorted(list(els.keys()))
olk = sorted(list(ols.keys()))
# print(elv)
# print(olv)
is_same_key = 1
for i in range(len(elk)):
if elk[i] != olk[i]:
is_same_key = 0
break
ans = 0
if not (is_same_key):
ans += sum(elv) - max(elv)
ans += sum(olv) - max(olv)
print(ans)
else:
tempe = []
tempo = []
for i in elk:
tempe.append(n // 2 - els[i])
tempo.append(n // 2 - ols[i])
# print(tempe)
# print(tempo)
min_e = min(tempe)
min_o = min(tempo)
ind_min_e = tempe.index(min_e)
ind_min_o = tempo.index(min_o)
if ind_min_o != ind_min_e:
print(min_e + min_o)
else:
ans_temp = 0
tempo_temp = copy.deepcopy(tempo)
tempe_temp = copy.deepcopy(tempe)
tempo_temp[ind_min_o] = 999999999
ans_temp = min_e + min(tempo_temp)
tempe_temp[ind_min_e] = 999999999
if min_o + min(tempe_temp) < ans_temp:
ans_temp = min_o + min(tempe_temp)
print(ans_temp)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s642988773 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
v = list(map(int, input().split()))
def calc(l):
new_l = []
adic = {}
count = 0
for c in l:
if c in adic.keys():
new_l.append(adic[c])
else:
new_l.append(count)
adic[c] = count
count += 1
return new_l
def mink(lis):
# print(lis)
l = lis[0::2]
m = lis[1::2]
ls = [[i, 0] for i in (set(l))]
for d in l:
for f in ls:
if d == f[0]:
f[1] += 1
nls = sorted(ls, key=lambda x: x[1])
ms = [[i, 0] for i in (set(m))]
for e in m:
for g in ms:
if e == g[0]:
g[1] += 1
nms = sorted(ms, key=lambda x: x[1])
if len(nls) > 1:
sfls = nls[1][1]
else:
sfls = -1
if len(nms) > 1:
sfms = nms[1][1]
else:
sfms = -1
ll = len(l) - nls[0][1]
mm = len(m) - nms[0][1]
if nls[0][0] == nms[0][0]:
if nls[0][1] > nms[0][1]:
if len(nms) > 1:
mm = len(m) - nms[1][1]
else:
mm = len(m)
elif nls[0][1] < nms[0][1]:
if len(nls) > 1:
ll = len(l) - nls[1][1]
else:
ll = len(l)
else: # ==
mm = len(m) - max(sfls, sfms)
if mm > len(m):
mm = len(m)
print(ll + mm)
mink(calc(v))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s427315698 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
v = input().split()
vv = list(set(v))
min = 10**6
for i in vv:
vvv = vv.copy()
vvv.remove(i)
for j in vvv:
ct = 0
a = [i if k % 2 == 0 else j for k in range(n)]
for k in range(n):
if a[k] != v[k]:
ct += 1
if ct < min:
min = ct
print(min)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s662779791 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
a = list(map(int, input().split()))
b = [a[2 * i] for i in range(int(n / 2))]
c = [a[2 * i - 1] for i in range(1, int(n / 2) + 1)]
print(b)
print(c)
d = [b.count(i) for i in list(set(b))]
e = [c.count(i) for i in list(set(c))]
if list(set(b))[d.index(max(d))] != list(set(c))[e.index(max(e))]:
print(n - max(d) - max(e))
else:
f = max(d)
g = max(e)
del list(set(b))[d.index(max(d))]
del list(set(c))[e.index(max(e))]
d.remove(f)
e.remove(g)
if len(d) == 0:
h = 0
else:
h = max(d)
if len(e) == 0:
i = 0
else:
i = max(e)
print(n - max(f + i, g + h))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s785608609 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
li_input = list(map(int, input().split()))
li_ki = li_input[0::2]
li_gu = li_input[1::2]
li_ki_counter = sorted([(i, li_ki.count(i)) for i in set(li_ki)], key=lambda x: x[1])
li_gu_counter = sorted([(i, li_gu.count(i)) for i in set(li_gu)], key=lambda x: x[1])
ki_1st = li_ki_counter[0][0]
gu_1st = li_gu_counter[0][0]
if ki_1st == gu_1st:
# 最頻値が同じ値の場合、2番目に多い要素を使う
if len(li_ki_counter) == 1:
ki_2nd = -1
else:
ki_2nd = li_ki_counter[1][0]
if len(li_gu_counter) == 1:
gu_2nd = -1
else:
gu_2nd = li_gu_counter[1][0]
ptn1 = len(list(filter(lambda x: x != ki_1st, li_ki))) + len(
list(filter(lambda x: x != gu_2nd, li_gu))
)
ptn2 = len(list(filter(lambda x: x != ki_2nd, li_ki))) + len(
list(filter(lambda x: x != gu_1st, li_gu))
)
if ptn1 >= ptn2:
print(ptn2)
else:
print(ptn1)
else:
# 最頻値が異なる場合
print(
len(list(filter(lambda x: x != ki_1st, li_ki)))
+ len(list(filter(lambda x: x != gu_1st, li_gu)))
)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s844837900 | Accepted | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | # -*- coding: utf-8 -*-
"""
Created on Fri May 10 23:15:55 2019
@author: Yamazaki Kenichi
"""
n = int(input())
A = list(map(int, input().split()))
T = [[0 for i in range(10**5 + 1)], [0 for i in range(10**5 + 1)]]
counta = 0
for c in A:
T[counta % 2][c] += 1
counta += 1
tmp = [[0] * 4, [0] * 4]
for i in range(10**5 + 1):
# for i in range(6):
for k in range(2):
if T[k][i] > tmp[k][0]:
tmp[k][2], tmp[k][3] = tmp[k][0], tmp[k][1]
tmp[k][0], tmp[k][1] = T[k][i], i
elif T[k][i] > tmp[k][2]:
tmp[k][2], tmp[k][3] = T[k][i], i
# print(tmp)
if tmp[0][1] != tmp[1][1]:
print(n - tmp[0][0] - tmp[1][0])
else:
print(min(n - tmp[0][0] - tmp[1][2], n - tmp[0][2] - tmp[1][0]))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s717431095 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
seq = list(map(int, input().split()))
oddlist = []
evenlist = []
for i in range(n):
if (i + 1) % 2 != 0:
oddlist.append(seq[i])
else:
evenlist.append(seq[i])
print(seq)
print(oddlist)
print(evenlist)
maxi = n / 2
mini = n / 2
if oddlist != evenlist:
for j in set(evenlist):
if evenlist.count(j) == int(n / 2):
maxi = 0
else:
if evenlist.count(j) < maxi:
maxi = evenlist.count(j)
else:
maxi = maxi
for k in set(oddlist):
if oddlist.count(k) == int(n / 2):
mini = 0
else:
if oddlist.count(k) < mini:
mini = oddlist.count(k)
else:
mini = mini
print(maxi + mini)
else:
print(2)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s879316431 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
v = list(map(int, input().split()))
even_map = {}
for i in range(0, n)[::2]:
if v[i] not in even_map:
even_map[v[i]] = 1
else:
even_map[v[i]] += 1
odd_map = {}
for i in range(1, n)[::2]:
if v[i] not in odd_map:
odd_map[v[i]] = 1
else:
odd_map[v[i]] += 1
odd_list = list(odd_map.items())
odd_list.sort(key=lambda x: x[1], reverse=True)
even_list = list(even_map.items())
even_list.sort(key=lambda x: x[1], reverse=True)
odd = odd_list[0][0]
even = even_list[0][0]
if odd == even:
if odd_list[0][1] > even_list[0][1]:
if len(even_list) > 1:
even = even_list[1][0]
else:
even = odd + 1
else:
if len(odd_list) > 1:
odd = odd_list[1][0]
else:
odd = even + 1
ans = 0
for k, v in odd_map.items():
if k != odd:
ans += v
for k, v in even_map.items():
if k != even:
ans += v
print(ans)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s043225522 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | from collections import defaultdict
n = int(input())
li_input = list(map(int, input().split()))
li_ki = li_input[0::2]
d_ki = defaultdict(int)
for ki in li_ki:
d_ki[ki] += 1
li_gu = li_input[1::2]
d_gu = defaultdict(int)
for gu in li_gu:
d_gu[gu] += 1
ki_sort = sorted([(k, v) for k, v in d_ki.items()], key=lambda x: x[1], reverse=True)
gu_sort = sorted([(k, v) for k, v in d_gu.items()], key=lambda x: x[1], reverse=True)
ki_cnt = 0
gu_cnt = 0
if ki_sort[0][1] >= gu_sort[0][1]:
ki_cnt = ki_sort[0][1]
for g in gu_sort:
if ki_sort[0][0] != g[0]:
gu_cnt = g[1]
break
else:
gu_cnt = gu_sort[0][1]
for k in ki_sort:
if gu_sort[0][0] != k[0]:
ki_cnt = k[1]
break
print(n - ki_cnt - gu_cnt)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s448914428 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | N = int(input())
v = list(map(int, input().rstrip().split()))
count_even = {}
count_odd = {}
if v.count(v[0]) == N:
print(N // 2)
exit()
for i in range(N):
num = v[i]
if i % 2 == 0:
value = count_odd.get(num)
if value == None:
count_odd[num] = 1
else:
count_odd[num] += 1
else:
value = count_even.get(num)
if value == None:
count_even[num] = 1
else:
count_even[num] += 1
count_even = sorted(count_even.items(), key=lambda x: x[1], reverse=True)
count_odd = sorted(count_odd.items(), key=lambda x: x[1], reverse=True)
if count_even[0][0] == count_odd[0][0]:
a, b = count_even[0][1], count_odd[0][1]
if a > b:
tmp = count_odd[0]
count_odd[0] = count_odd[1]
count_odd[1] = tmp
else:
tmp = count_even[0]
count_even[0] = count_even[1]
count_even[1] = tmp
count_even = [x[1] for x in count_even]
count_odd = [x[1] for x in count_odd]
answer = 0
if len(count_odd) > 1:
for i in range(1, len(count_odd)):
answer += count_odd[i]
if len(count_even) > 1:
for i in range(1, len(count_even)):
answer += count_even[i]
print(answer)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s986895626 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | n = int(input())
v = list(map(int, input().split()))
v_odd = []
v_even = []
for i in range(int(n / 2)):
v_odd.append(v[i * 2])
v_even.append(v[i * 2 + 1])
v_odd.sort()
v_even.sort()
v_odd_max_count = 0
v_even_max_count = 0
v_odd_max_num = 0
v_even_max_num = 0
a = 1
for i in range(int(n / 2) - 1):
if v_odd[i] != v_odd[i + 1]:
if a > v_odd_max_count:
v_odd_max_count = a
v_odd_max_num = v_odd[i]
a = 1
else:
a += 1
if a > v_odd_max_count:
v_odd_max_count = a
v_odd_max_num = v_odd[i]
a = 1
for i in range(int(n / 2) - 1):
if v_even[i] != v_even[i + 1]:
if a > v_even_max_count:
v_even_max_count = a
v_even_max_num = v_even[i]
a = 1
else:
a += 1
if a > v_even_max_count:
v_even_max_count = a
v_even_max_num = v_even[i]
if v_odd_max_num != v_even_max_num:
print(n - v_odd_max_count - v_even_max_count)
else:
v_odd_sec_count = 0
v_even_sec_count = 0
v_odd = [i for i in v_odd if not i == v_odd_max_num]
v_even = [i for i in v_even if not i == v_even_max_num]
if not v_odd:
v_odd_sec_count = 0
else:
a = 1
for i in range(len(v_odd) - 1):
if v_odd[i] != v_odd[i + 1]:
if a > v_odd_sec_count:
v_odd_sec_count = a
a = 1
else:
a += 1
if a > v_odd_sec_count:
v_odd_sec_count = a
if not v_even:
v_even_sec_count = 0
else:
a = 1
for i in range(len(v_even) - 1):
if v_even[i] != v_even[i + 1]:
if a > v_even_sec_count:
v_even_sec_count = a
a = 1
else:
a += 1
if a > v_even_sec_count:
v_even_sec_count = a
if v_odd_max_count + v_even_sec_count > v_odd_sec_count + v_even_max_count:
print(n - v_odd_max_count - v_even_sec_count)
else:
print(n - v_odd_sec_count - v_even_max_count)
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum number of elements that needs to be replaced.
* * * | s961688867 | Wrong Answer | p03244 | Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n | # -*- coding: utf-8 -*-
import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline
# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary
# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':
n = int(input().rstrip())
v = list(map(int, input().rstrip().split()))
v_even = dict()
v_odd = dict()
def solve(d1, d2):
d1_max = [[0, 0], [0, 0]]
d2_max = [[0, 0], [0, 0]]
for i in d1:
if d1_max[0][1] <= d1[i]:
d1_max[1] = d1_max[0]
d1_max[0] = [i, d1[i]]
for i in d2:
if d2_max[0][1] <= d2[i]:
d2_max[1] = d2_max[0]
d2_max[0] = [i, d2[i]]
print(d1_max)
print(d2_max)
if d1_max[0][0] != d2_max[0][0]:
return n - d1_max[0][1] - d2_max[0][1]
else:
return min(n - d1_max[1][1] - d2_max[0][1], n - d1_max[0][1] - d2_max[1][1])
for i in range(len(v)):
if i % 2 == 0:
if v[i] not in v_even:
v_even[v[i]] = 1
else:
v_even[v[i]] += 1
else:
if v[i] not in v_odd:
v_odd[v[i]] = 1
else:
v_odd[v[i]] += 1
print(solve(v_even, v_odd))
| Statement
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following
conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even. We would like
to make this sequence /\/\/\/ by replacing some of its elements. Find the
minimum number of elements that needs to be replaced. | [{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}] |
Print the minimum required number of operations
* * * | s078772665 | Runtime Error | p03614 | The input is given from Standard Input in the following format:
N
p_1 p_2 .. p_N | n=int(input())
a=[int(i) for i in input().split()]
r=0
t=0
while t<n:
if a[t]==t+1:
r+=1
t+=1+r
print(r)
| Statement
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can
perform the following operation any number of times (possibly zero):
Operation: Swap two **adjacent** elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of
operations to achieve this. | [{"input": "5\n 1 4 3 5 2", "output": "2\n \n\nSwap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the\ncondition. This is the minimum possible number, so the answer is 2.\n\n* * *"}, {"input": "2\n 1 2", "output": "1\n \n\nSwapping 1 and 2 satisfies the condition.\n\n* * *"}, {"input": "2\n 2 1", "output": "0\n \n\nThe condition is already satisfied initially.\n\n* * *"}, {"input": "9\n 1 2 4 9 5 8 7 3 6", "output": "3"}] |
Print the minimum required number of operations
* * * | s208868156 | Accepted | p03614 | The input is given from Standard Input in the following format:
N
p_1 p_2 .. p_N | import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def S():
return input()
def main():
n = I()
a = LI_()
r = 0
for i in range(n - 1):
if a[i] == i:
r += 1
a[i + 1] = i
if a[-1] == n - 1:
r += 1
return r
print(main())
| Statement
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can
perform the following operation any number of times (possibly zero):
Operation: Swap two **adjacent** elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of
operations to achieve this. | [{"input": "5\n 1 4 3 5 2", "output": "2\n \n\nSwap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the\ncondition. This is the minimum possible number, so the answer is 2.\n\n* * *"}, {"input": "2\n 1 2", "output": "1\n \n\nSwapping 1 and 2 satisfies the condition.\n\n* * *"}, {"input": "2\n 2 1", "output": "0\n \n\nThe condition is already satisfied initially.\n\n* * *"}, {"input": "9\n 1 2 4 9 5 8 7 3 6", "output": "3"}] |
Print the minimum required number of operations
* * * | s577090851 | Accepted | p03614 | The input is given from Standard Input in the following format:
N
p_1 p_2 .. p_N | (*p,) = map(int, open(0).read().split())
p += (0,)
a = 0
for i, t in enumerate(p):
if i == t:
a += 1
p[i + 1] = 0
print(a)
| Statement
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can
perform the following operation any number of times (possibly zero):
Operation: Swap two **adjacent** elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of
operations to achieve this. | [{"input": "5\n 1 4 3 5 2", "output": "2\n \n\nSwap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the\ncondition. This is the minimum possible number, so the answer is 2.\n\n* * *"}, {"input": "2\n 1 2", "output": "1\n \n\nSwapping 1 and 2 satisfies the condition.\n\n* * *"}, {"input": "2\n 2 1", "output": "0\n \n\nThe condition is already satisfied initially.\n\n* * *"}, {"input": "9\n 1 2 4 9 5 8 7 3 6", "output": "3"}] |
Print the minimum required number of operations
* * * | s768085268 | Wrong Answer | p03614 | The input is given from Standard Input in the following format:
N
p_1 p_2 .. p_N | n = int(input())
ar = list(map(int, input().split(" ")))
if n == 2:
if ar[0] == 1:
print(1)
else:
print(0)
exit()
else:
count = 0
if ar[0] == 1:
ar[0], ar[1] = ar[1], ar[0]
count += 1
elif ar[n - 1] == n:
ar[n - 1], ar[n - 2] = ar[n - 2], ar[n - 1]
count += 1
for i in range(1, n - 1):
if ar[i] == i + 1:
count += 1
print(count)
| Statement
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can
perform the following operation any number of times (possibly zero):
Operation: Swap two **adjacent** elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of
operations to achieve this. | [{"input": "5\n 1 4 3 5 2", "output": "2\n \n\nSwap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the\ncondition. This is the minimum possible number, so the answer is 2.\n\n* * *"}, {"input": "2\n 1 2", "output": "1\n \n\nSwapping 1 and 2 satisfies the condition.\n\n* * *"}, {"input": "2\n 2 1", "output": "0\n \n\nThe condition is already satisfied initially.\n\n* * *"}, {"input": "9\n 1 2 4 9 5 8 7 3 6", "output": "3"}] |
Print the minimum required number of operations
* * * | s450445184 | Runtime Error | p03614 | The input is given from Standard Input in the following format:
N
p_1 p_2 .. p_N | N = int(input())
p = input().split(' ')
ans = 1
for i in range(N):
if int(p[i])==i):
ans += 1
print(ans//2)
| Statement
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can
perform the following operation any number of times (possibly zero):
Operation: Swap two **adjacent** elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of
operations to achieve this. | [{"input": "5\n 1 4 3 5 2", "output": "2\n \n\nSwap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the\ncondition. This is the minimum possible number, so the answer is 2.\n\n* * *"}, {"input": "2\n 1 2", "output": "1\n \n\nSwapping 1 and 2 satisfies the condition.\n\n* * *"}, {"input": "2\n 2 1", "output": "0\n \n\nThe condition is already satisfied initially.\n\n* * *"}, {"input": "9\n 1 2 4 9 5 8 7 3 6", "output": "3"}] |
If there exists a graph that matches Snuke's memory, print `Yes`; otherwise,
print `No`.
* * * | s723125194 | Wrong Answer | p02906 | Input is given from Standard Input in the following format:
N M Q
A_0 B_0 C_0
A_1 B_1 C_1
\vdots
A_{Q-1} B_{Q-1} C_{Q-1} | N, M, Q = [int(_) for _ in input().split()]
Info0 = []
Info1 = []
for _ in range(Q):
a, b, c = [int(_) for _ in input().split()]
if c:
Info1 += [(a, b)]
else:
Info0 += [(a, b)]
size = N
UF = list(range(size))
SIZE = [1] * size # 0-indexed
def find(x):
stack = [x]
while True:
y = stack[-1]
if UF[y] != y:
stack += [UF[y]]
else:
break
for s in stack:
UF[s] = y
return y
def unite(x, y):
if not is_same(x, y):
X, Y = find(x), find(y)
SX, SY = SIZE[X], SIZE[Y]
if SX > SY:
m = UF[X] = Y
else:
m = UF[Y] = X
SIZE[m] = SX + SY
SIZE[X + Y - m] = 0
def is_same(x, y):
return find(x) == find(y)
def scan_uf():
length = len(UF)
for i in range(length):
find(i)
for a, b in Info0:
if is_same(a, b):
print("No")
exit()
else:
unite(a, b)
if len(Info1) == 0:
print("Yes")
exit()
for a, b in Info1:
if is_same(a, b):
print("No")
exit()
else:
unite(a, b)
scan_uf()
print("Yes" if len(set(UF)) > 1 else "No")
| Statement
Snuke's mother gave Snuke an undirected graph consisting of N vertices
numbered 0 to N-1 and M edges. This graph was connected and contained no
parallel edges or self-loops.
One day, Snuke broke this graph. Fortunately, he remembered Q clues about the
graph. The i-th clue (0 \leq i \leq Q-1) is represented as integers
A_i,B_i,C_i and means the following:
* If C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.
* If C_i=1: there were two or more simple paths from Vertex A_i to B_i.
Snuke is not sure if his memory is correct, and worried whether there is a
graph that matches these Q clues. Determine if there exists a graph that
matches Snuke's memory. | [{"input": "5 5 3\n 0 1 0\n 1 2 1\n 2 3 0", "output": "Yes\n \n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This\ngraph matches the clues.\n\n* * *"}, {"input": "4 4 3\n 0 1 0\n 1 2 1\n 2 3 0", "output": "No\n \n\n* * *"}, {"input": "10 9 9\n 7 6 0\n 4 5 1\n 9 7 0\n 2 9 0\n 2 3 0\n 4 1 0\n 8 0 0\n 9 1 0\n 3 0 0", "output": "No"}] |
In the first line, print the number of edges, M, in the graph you made. In the
i-th of the following M lines, print two integers a_i and b_i, representing
the endpoints of the i-th edge.
The output will be judged correct if the graph satisfies the conditions.
* * * | s699610707 | Accepted | p03090 | Input is given from Standard Input in the following format:
N | N = int(input())
aD = []
if N % 2:
aD.append([N])
for i in range(1, (N + 1) // 2):
aD.append([i, N - i])
else:
for i in range(1, (N // 2) + 1):
aD.append([i, N + 1 - i])
iD = len(aD)
aRes = []
def strfy(aD):
return " ".join(str(_) for _ in sorted(aD))
for i in range(iD):
for j in range(iD):
if i == j:
pass
else:
if len(aD[i]) == 1:
aRes.append(strfy([aD[i][0], aD[j][0]]))
aRes.append(strfy([aD[i][0], aD[j][1]]))
elif len(aD[j]) == 1:
aRes.append(strfy([aD[i][0], aD[j][0]]))
aRes.append(strfy([aD[i][1], aD[j][0]]))
else:
aRes.append(strfy([aD[i][0], aD[j][0]]))
aRes.append(strfy([aD[i][0], aD[j][1]]))
aRes.append(strfy([aD[i][1], aD[j][0]]))
aRes.append(strfy([aD[i][1], aD[j][1]]))
aRes = list(set(aRes))
print(len(aRes))
print(*aRes, sep="\n")
| Statement
You are given an integer N. Build an undirected graph with N vertices with
indices 1 to N that satisfies the following two conditions:
* The graph is simple and connected.
* There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.
It can be proved that at least one such graph exists under the constraints of
this problem. | [{"input": "3", "output": "2\n 1 3\n 2 3\n \n\n * For every vertex, the sum of the indices of the vertices adjacent to that vertex is 3."}] |
In the first line, print the number of edges, M, in the graph you made. In the
i-th of the following M lines, print two integers a_i and b_i, representing
the endpoints of the i-th edge.
The output will be judged correct if the graph satisfies the conditions.
* * * | s633500438 | Accepted | p03090 | Input is given from Standard Input in the following format:
N | def read_tokens():
return input().strip().split(" ")
def read_ints():
return [int(token) for token in read_tokens()]
def connected(edges):
n = len(edges)
vis = [False] * n
def dfs(u):
if vis[u]:
return
vis[u] = True
for v in edges[u]:
dfs(v)
dfs(0)
return all(vis)
def good(edges):
n = len(edges)
s = []
for i in range(n):
s.append(sum(edges[i]) + len(edges[i]))
return min(s) == max(s)
# n, = read_ints()
# m = n * (n - 1) // 2
# for mask in range(1, 2**m):
# edges = [[] for _ in range(n)]
# mm = mask
# for u in range(n):
# for v in range(u + 1, n):
# if mm % 2 > 0:
# edges[u].append(v)
# edges[v].append(u)
# mm = mm // 2
# # print(mask, edges)
# if connected(edges) and good(edges):
# print(edges)
def out(edges):
print(sum(len(a) for a in edges) // 2)
for idx, a in enumerate(edges):
for v in a:
if idx < v:
print(idx + 1, v + 1)
def even(n):
edges = [[] for _ in range(n)]
s = (n + 1) * (n - 2) // 2
sums = [s] * n
for i in reversed(range(n)):
# print(i, sums, edges)
for j in reversed(range(i)):
# if j + 1 <= sums[i] and i + 1 <= sums[j]:
if i + j != n - 1:
sums[i] -= j + 1
sums[j] -= i + 1
edges[i].append(j)
edges[j].append(i)
assert max(sums) == 0 and min(sums) == 0
return edges
def odd(n):
edges = [[] for _ in range(n)]
s = n * (n - 1) // 2
sums = [s] * n
for i in reversed(range(n)):
# print(i, sums, edges)
for j in reversed(range(i)):
# if j + 1 <= sums[i] and i + 1 <= sums[j]:
if i + j != n - 2:
sums[i] -= j + 1
sums[j] -= i + 1
edges[i].append(j)
edges[j].append(i)
assert max(sums) == 0 and min(sums) == 0
return edges
(n,) = read_ints()
if n % 2 == 0:
out(even(n))
else:
out(odd(n))
| Statement
You are given an integer N. Build an undirected graph with N vertices with
indices 1 to N that satisfies the following two conditions:
* The graph is simple and connected.
* There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.
It can be proved that at least one such graph exists under the constraints of
this problem. | [{"input": "3", "output": "2\n 1 3\n 2 3\n \n\n * For every vertex, the sum of the indices of the vertices adjacent to that vertex is 3."}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.