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 A + B is 10 or greater, print the string `error` (case-sensitive);
otherwise, print the value of A + B.
* * * | s170751262 | Runtime Error | p03697 | Input is given from Standard Input in the following format:
A B | a,b = map(int, input().split())
result = a+b if a+b < 10 else ‘Error’
print(result) | Statement
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output `error` instead. | [{"input": "6 3", "output": "9\n \n\n* * *"}, {"input": "6 4", "output": "error"}] |
Print the minimum number of new stones that Jiro needs to place for his
purpose.
* * * | s647288329 | Accepted | p03947 | The input is given from Standard Input in the following format:
S | S = input()
tmp = ""
N = len(S)
count = 0
for i in range(N):
if i == 0:
tmp = S[i]
count = 1
else:
if S[i] != tmp:
tmp = S[i]
count += 1
print(count - 1)
| Statement
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is
played on a board, using black and white stones. On the board, stones are
placed in a row, and each player places a new stone to either end of the row.
Similarly to the original game of Reversi, when a white stone is placed, all
black stones between the new white stone and another white stone, turn into
white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game.
The state of the board at this point is described by a string S. There are |S|
(the length of S) stones on the board, and each character in S represents the
color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in
S is `B`, it means that the color of the corresponding stone on the board is
black. Similarly, if the i-th character in S is `W`, it means that the color
of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose,
he will place new stones on the board according to the rules. Find the minimum
number of new stones that he needs to place. | [{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}] |
Print the minimum number of new stones that Jiro needs to place for his
purpose.
* * * | s901594363 | Accepted | p03947 | The input is given from Standard Input in the following format:
S | #!usr/bin/env python3
from collections import defaultdict
import math
def LI():
return list(map(int, input().split()))
def II():
return int(input())
def LS():
return input().split()
def S():
return input()
def IIR(n):
return [II() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
mod = 1000000007
# A
"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
if i * i == c:
print("Yes")
quit()
print("No")
"""
# B
"""
a,b = LI()
if a*b <= 0:
print("Zero")
else:
if b < 0:
if (a-b) %2 == 1:
print("Positive")
else:
print("Negative")
else:
print("Positive")
"""
# C
"""
n = II()
s = SR(n)
march = [[] for i in range(5)]
ch = list("MARCH")
for i in s:
for j in range(5):
if i[0] == ch[j]:
march[j].append(i)
ans = 0
for i in range(5):
for j in range(i):
for k in range(j):
if len(march[i])*len(march[j])*len(march[k]) == 0:
break
ans += len(march[i])*len(march[j])*len(march[k])
print(ans)
"""
# D
"""
n = II()
d = LIR(n)
q = II()
p = IIR(q)
d.insert(0,[0 for i in range(n+1)])
for i in range(n):
d[i+1].insert(0,0)
for i in range(n):
for j in range(n):
d[i+1][j+1] += d[i+1][j]+d[i][j+1]-d[i][j]
ans = [0 for i in range(n**2+1)]
for a in range(n+1):
for b in range(n+1):
for c in range(a):
for e in range(b):
ans[(a-c)*(b-e)] = max(ans[(a-c)*(b-e)],d[a][b]-d[c][b]-d[a][e]+d[c][e])
for i in p:
an = 0
for a in range(i+1):
an = max(an, ans[a])
print(an)
"""
# E
s = list(S())
ans = -1
s.insert(0, 0)
d = 0
for i in range(1, len(s)):
if s[i] != d:
d = s[i]
ans += 1
print(ans)
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T
| Statement
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is
played on a board, using black and white stones. On the board, stones are
placed in a row, and each player places a new stone to either end of the row.
Similarly to the original game of Reversi, when a white stone is placed, all
black stones between the new white stone and another white stone, turn into
white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game.
The state of the board at this point is described by a string S. There are |S|
(the length of S) stones on the board, and each character in S represents the
color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in
S is `B`, it means that the color of the corresponding stone on the board is
black. Similarly, if the i-th character in S is `W`, it means that the color
of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose,
he will place new stones on the board according to the rules. Find the minimum
number of new stones that he needs to place. | [{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}] |
Print the minimum number of new stones that Jiro needs to place for his
purpose.
* * * | s775812429 | Accepted | p03947 | The input is given from Standard Input in the following format:
S | import sys
sys.setrecursionlimit(10**6)
from math import floor, ceil, sqrt, factorial, log
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10**9 + 7
inf = float("inf")
ninf = -float("inf")
# 整数input
def ii():
return int(sys.stdin.readline().rstrip()) # int(input())
def mii():
return map(int, sys.stdin.readline().rstrip().split())
def limii():
return list(mii()) # list(map(int,input().split()))
def lin(n: int):
return [ii() for _ in range(n)]
def llint(n: int):
return [limii() for _ in range(n)]
# 文字列input
def ss():
return sys.stdin.readline().rstrip() # input()
def mss():
return sys.stdin.readline().rstrip().split()
def limss():
return list(mss()) # list(input().split())
def lst(n: int):
return [ss() for _ in range(n)]
def llstr(n: int):
return [limss() for _ in range(n)]
# 本当に貪欲法か? DP法では??
# 本当に貪欲法か? DP法では??
# 本当に貪欲法か? DP法では??
s = list(ss())
cnt = 0
chk = True
if s[0] == "B":
chk = False
for i in range(len(s) - 1):
if chk == True and s[i + 1] == "B":
chk = False
cnt += 1
elif chk == False and s[i + 1] == "W":
chk = True
cnt += 1
print(cnt)
| Statement
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is
played on a board, using black and white stones. On the board, stones are
placed in a row, and each player places a new stone to either end of the row.
Similarly to the original game of Reversi, when a white stone is placed, all
black stones between the new white stone and another white stone, turn into
white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game.
The state of the board at this point is described by a string S. There are |S|
(the length of S) stones on the board, and each character in S represents the
color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in
S is `B`, it means that the color of the corresponding stone on the board is
black. Similarly, if the i-th character in S is `W`, it means that the color
of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose,
he will place new stones on the board according to the rules. Find the minimum
number of new stones that he needs to place. | [{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}] |
Print the minimum number of new stones that Jiro needs to place for his
purpose.
* * * | s844940486 | Runtime Error | p03947 | The input is given from Standard Input in the following format:
S | a = input()
n, b = 0, 0
while True:
if a[n] != a[n + 1]:
b += 1
n += 1
if n + 1 == len(a):
break
print(b)
| Statement
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is
played on a board, using black and white stones. On the board, stones are
placed in a row, and each player places a new stone to either end of the row.
Similarly to the original game of Reversi, when a white stone is placed, all
black stones between the new white stone and another white stone, turn into
white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game.
The state of the board at this point is described by a string S. There are |S|
(the length of S) stones on the board, and each character in S represents the
color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in
S is `B`, it means that the color of the corresponding stone on the board is
black. Similarly, if the i-th character in S is `W`, it means that the color
of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose,
he will place new stones on the board according to the rules. Find the minimum
number of new stones that he needs to place. | [{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}] |
Print the minimum number of new stones that Jiro needs to place for his
purpose.
* * * | s894100818 | Accepted | p03947 | The input is given from Standard Input in the following format:
S | S = input()
if len(S) == 1:
print(0)
else:
ans = 0
for x, y in zip(S, S[1:]):
if x != y:
ans += 1
print(ans)
| Statement
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is
played on a board, using black and white stones. On the board, stones are
placed in a row, and each player places a new stone to either end of the row.
Similarly to the original game of Reversi, when a white stone is placed, all
black stones between the new white stone and another white stone, turn into
white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game.
The state of the board at this point is described by a string S. There are |S|
(the length of S) stones on the board, and each character in S represents the
color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in
S is `B`, it means that the color of the corresponding stone on the board is
black. Similarly, if the i-th character in S is `W`, it means that the color
of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose,
he will place new stones on the board according to the rules. Find the minimum
number of new stones that he needs to place. | [{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}] |
Print the minimum number of new stones that Jiro needs to place for his
purpose.
* * * | s198306270 | Runtime Error | p03947 | The input is given from Standard Input in the following format:
S |
s_long = input()
count = 0
prev = ''
for s in s_long:
if prev == ''
prev = s
continue
if prev != s:
count += 1
prev = s
print(count) | Statement
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is
played on a board, using black and white stones. On the board, stones are
placed in a row, and each player places a new stone to either end of the row.
Similarly to the original game of Reversi, when a white stone is placed, all
black stones between the new white stone and another white stone, turn into
white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game.
The state of the board at this point is described by a string S. There are |S|
(the length of S) stones on the board, and each character in S represents the
color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in
S is `B`, it means that the color of the corresponding stone on the board is
black. Similarly, if the i-th character in S is `W`, it means that the color
of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose,
he will place new stones on the board according to the rules. Find the minimum
number of new stones that he needs to place. | [{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}] |
Print the minimum number of new stones that Jiro needs to place for his
purpose.
* * * | s848755996 | Accepted | p03947 | The input is given from Standard Input in the following format:
S | print((lambda s: s.count("WB") + s.count("BW"))(input()))
| Statement
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is
played on a board, using black and white stones. On the board, stones are
placed in a row, and each player places a new stone to either end of the row.
Similarly to the original game of Reversi, when a white stone is placed, all
black stones between the new white stone and another white stone, turn into
white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game.
The state of the board at this point is described by a string S. There are |S|
(the length of S) stones on the board, and each character in S represents the
color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in
S is `B`, it means that the color of the corresponding stone on the board is
black. Similarly, if the i-th character in S is `W`, it means that the color
of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose,
he will place new stones on the board according to the rules. Find the minimum
number of new stones that he needs to place. | [{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}] |
Print the minimum number of new stones that Jiro needs to place for his
purpose.
* * * | s311793120 | Runtime Error | p03947 | The input is given from Standard Input in the following format:
S | s=input()
cnt=0
for i range(1,len(s)):
if s[i]!=s[i-1]:
cnt+=1
print(cnt) | Statement
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is
played on a board, using black and white stones. On the board, stones are
placed in a row, and each player places a new stone to either end of the row.
Similarly to the original game of Reversi, when a white stone is placed, all
black stones between the new white stone and another white stone, turn into
white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game.
The state of the board at this point is described by a string S. There are |S|
(the length of S) stones on the board, and each character in S represents the
color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in
S is `B`, it means that the color of the corresponding stone on the board is
black. Similarly, if the i-th character in S is `W`, it means that the color
of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose,
he will place new stones on the board according to the rules. Find the minimum
number of new stones that he needs to place. | [{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s558188899 | Wrong Answer | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | a = int(input())
vertices = [i for i in range(1, a + 1)]
color = {i: 0 for i in vertices}
for i in range(a - 1):
c = [int(s) for s in input().split()]
if c[2] % 2 == 0:
color[c[0]], color[c[1]] = 1, 1
for i in vertices:
print(color[i])
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s870004187 | Runtime Error | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | (n,), *t = [map(int, t.split()) for t in open(0)]
n += 1
(*e,) = eval("[]," * n)
q = [n]
f = [-1] * n
for v, w, c in t:
e[v] += (w * n + c,)
e[w] += (v * n + c,)
for v in q:
f[v // n] = v % n & 1
for w in e[v // n]:
q += [w + v % n] * (f[w // n] < 0)
print(*f[1:])
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s823510807 | Runtime Error | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | # AtCoder Beginner Contest 126
# https://atcoder.jp/contests/abc126
import sys
# import numpy as np
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
def main():
N = i2n()
uvw = ii2nnn(N - 1)
d = [[] for _ in range(N)]
for u, v, w in uvw:
b = w % 2 == 0
d[u - 1].append((v - 1, b))
d[v - 1].append((u - 1, b))
nn = [-1 for _ in range(N)]
nn[0] = 0
def main2(src):
links = d[src]
c = nn[src]
for dst, b in links:
if nn[dst] == -1:
nn[dst] = c if b else 1 - c
main2(dst)
main2(0)
for n in nn:
print(n)
main()
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s846614672 | Accepted | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | import collections
n = int(input())
ls = [list(map(int, input().split())) for _ in range(n - 1)]
es = [[] for _ in range(n + 1)]
for u, v, w in ls:
b = w % 2 == 0
es[u].append([v, b])
es[v].append([u, b])
cs = [-1 for _ in range(n + 1)]
cs[1] = 0
q = collections.deque([1])
while len(q) > 0:
x = q.popleft()
for y, b in es[x]:
if cs[y] >= 0:
continue
cs[y] = cs[x] if b else 1 - cs[x]
q.append(y)
print(*cs[1:], sep="\n")
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s311135700 | Wrong Answer | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | N = int(input())
# v0 o v1 o v2
# 1 0 1
# v0 e v1 o v2
# 1 1 0
# v0 e v1 e v2
# 1 1 1
# v0 o v1 e v2
# 1 0 0
class Color:
def __init__(self, c):
self.c = c
color = [None] * N
edge = []
for i in range(0, N - 1):
u, v, w = [int(x) for x in input().split()]
if w & 1 == 0:
edge.append((u - 1, v - 1, True))
else:
edge.append((u - 1, v - 1, False))
edge.sort()
for u, v, w in edge:
cu = color[u]
if cu:
if w:
color[v] = cu
else:
if color[v]:
color[v].c = 1 - cu.c
else:
color[v] = Color(1 - cu.c)
else:
if w:
if color[v]:
color[u] = color[v]
else:
color[v] = Color(0)
color[u] = color[v]
else:
if color[v]:
color[u] = Color(1 - color[v].c)
else:
color[v] = Color(0)
color[u] = Color(1)
for u, v, w in edge:
cu = color[u]
if cu:
if w:
color[v] = cu
else:
if color[v]:
color[v].c = 1 - cu.c
else:
color[v] = Color(1 - cu.c)
else:
if w:
if color[v]:
color[u] = color[v]
else:
color[v] = Color(0)
color[u] = color[v]
else:
if color[v]:
color[u] = Color(1 - color[v].c)
else:
color[v] = Color(0)
color[u] = Color(1)
for e in color:
print(e.c)
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s187414022 | Accepted | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | inpl = lambda: list(map(int, input().split()))
class ParityTree:
def __init__(self, N):
self.parent = [-1] * int(N)
self.parity = [0] * int(N)
def root(self, n):
if self.parent[n] < 0:
return n, 0
else:
m, p = self.root(self.parent[n])
self.parent[n] = m
self.parity[n] = (p + self.parity[n]) % 2
return m, self.parity[n]
def merge(self, m, n, parity):
rm, pm = self.root(m)
rn, pn = self.root(n)
if rm != rn:
if -self.parent[rm] < -self.parent[rn]:
rm, rn = rn, rm
self.parent[rm] += self.parent[rn]
self.parent[rn] = rm
self.parity[rn] = (pm + pn + parity) % 2
def size(self, n):
return -self.parent[self.root(n)]
def aresame(self, m, n):
return self.root(m) == self.root(n)
N = int(input())
pt = ParityTree(N)
for i in range(N - 1):
u, v, w = inpl()
pt.merge(u - 1, v - 1, w)
for i in range(N):
print(pt.root(i)[1])
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s851932489 | Wrong Answer | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | import sys
N = int(sys.stdin.readline())
uvw = sorted([list(map(int, sys.stdin.readline().split())) for _ in range(N - 1)])
w_list = []
b_list = []
ans_dic = {}
for i in range(N - 1):
if uvw[i][2] % 2 == 0:
if uvw[i][0] in w_list:
if str(uvw[i][1]) not in ans_dic.keys():
ans_dic[str(uvw[i][1])] = 0
w_list.append(uvw[i][1])
elif uvw[i][0] in b_list:
if str(uvw[i][1]) not in ans_dic.keys():
ans_dic[str(uvw[i][1])] = 1
b_list.append(uvw[i][1])
elif uvw[i][1] in w_list:
if str(uvw[i][0]) not in ans_dic.keys():
ans_dic[str(uvw[i][0])] = 0
w_list.append(uvw[i][0])
elif uvw[i][1] in b_list:
if str(uvw[i][0]) not in ans_dic.keys():
ans_dic[str(uvw[i][0])] = 1
b_list.append(uvw[i][0])
else:
ans_dic[str(uvw[i][0])] = 0
ans_dic[str(uvw[i][1])] = 0
w_list.append(uvw[i][0])
w_list.append(uvw[i][1])
else:
if uvw[i][0] in w_list:
if str(uvw[i][1]) not in ans_dic.keys():
ans_dic[str(uvw[i][1])] = 1
b_list.append(uvw[i][1])
elif uvw[i][0] in b_list:
if str(uvw[i][1]) not in ans_dic.keys():
ans_dic[str(uvw[i][1])] = 0
w_list.append(uvw[i][1])
elif uvw[i][1] in w_list:
if str(uvw[i][0]) not in ans_dic.keys():
ans_dic[str(uvw[i][0])] = 1
b_list.append(uvw[i][0])
elif uvw[i][1] in b_list:
if str(uvw[i][0]) not in ans_dic.keys():
ans_dic[str(uvw[i][0])] = 0
w_list.append(uvw[i][0])
else:
ans_dic[str(uvw[i][0])] = 0
ans_dic[str(uvw[i][1])] = 1
w_list.append(uvw[i][0])
b_list.append(uvw[i][1])
ans_dic = sorted(ans_dic.items())
for _, v in ans_dic:
print(v)
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s397370558 | Wrong Answer | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | N = int(input())
UVW = [list(map(int, input().split())) for _ in range(N - 1)]
# 奇数だったら塊の色を反転させる
class Bag:
def __init__(self, node, color):
self.bag = [node]
self.color = color
print(node, color)
# あるノードを追加する
def add(self, node):
self.bag.append(node)
# あるノードの色を変える:
def change_color(self, color):
self.color = color
# 同じ色は統合する
def union(self, Bag):
self.bag += Bag.bag
def find(self, num):
if num in self.bag:
return self.color
else:
return -1
def __repr__(self):
s = "["
for bg in self.bag:
s += str(bg) + ","
s += "]"
return s + "/" + str(self.color)
NODES = []
def find_all(node):
for n in range(len(NODES)):
i = NODES[n].find(node)
if i != -1:
return n
else:
return -1
color = 0
for uvw in UVW:
u = uvw[0] - 1
v = uvw[1] - 1
w = uvw[2]
# print(uvw, tree_color)
i = find_all(u)
j = find_all(v)
if i == -1 and j == -1:
bg = Bag(u, color)
if w % 2 == 0:
bg.add(v)
NODES.append(bg)
else:
NODES.append(bg)
bg2 = Bag(v, 1 - color)
NODES.append(bg2)
elif i != -1 and j == -1:
if w % 2 == 0:
NODES[i].add(v)
else:
bg2 = Bag(v, 1 - color)
NODES.append(bg2)
elif j != -1 and i == -1:
if w % 2 == 0:
NODES[j].add(v)
else:
bg2 = Bag(u, 1 - color)
NODES.append(bg2)
else:
if w % 2 == 0:
NODES[i].union(NODES[j])
del NODES[j]
else:
NODES[j].color = 1 - NODES[i].color
# print(NODES)
# for tc in tree_color:
# print(tc)
colors = [0 for _ in range(N)]
for n in NODES:
color = n.color
for nd in n.bag:
colors[nd] = color
for cl in colors:
print(cl)
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print a coloring of the vertices that satisfies the condition, in N lines. The
i-th line should contain `0` if Vertex i is painted white and `1` if it is
painted black.
If there are multiple colorings that satisfy the condition, any of them will
be accepted.
* * * | s497193425 | Wrong Answer | p03044 | Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1} | class branch:
def __init__(self, num: int, top: int, long: int):
self.num = num
self.top = [top]
self.long = [long]
N = 0
top = []
list = []
N = int(input())
for i in range(N + 1):
top.insert(i, 2)
for i in range(N + 1):
list.insert(i, None)
for i in range(N - 1):
Input = input().split()
num = [(int(Input[0]))]
num.append(int(Input[1]))
num.append(int(Input[2]))
if list[num[0]] == None:
list.insert(num[0], branch(1, num[1], num[2]))
else:
list[num[0]].num += 1
list[num[0]].top.append(num[1])
list[num[0]].long.append(num[2])
if list[num[1]] == None:
list.insert(num[1], branch(1, num[0], num[2]))
else:
list[num[1]].num += 1
list[num[1]].top.append(num[0])
list[num[1]].long.append(num[2])
for i in range(1, N + 1, 1):
if list[i] == None:
top[i] = 0
else:
if top[i] == 2:
top[i] = 0
for j in range(list[i].num):
if top[list[i].top[j]] != 2:
if list[i].long[j] % 2:
top[i] = top[list[i].top[j]] ^ 1
break
for j in range(list[i].num):
if list[i].long[j] % 2:
top[list[i].top[j]] = top[i] ^ 1
else:
for j in range(list[i].num):
if list[i].long[j] % 2:
top[list[i].top[j]] = top[i] ^ 1
print(top[i])
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree
connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is
to paint each vertex in the tree white or black (it is fine to paint all
vertices the same color) so that the following condition is satisfied:
* For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It
can be proved that at least one such coloring exists under the constraints of
this problem. | [{"input": "3\n 1 2 2\n 2 3 1", "output": "0\n 0\n 1\n \n\n* * *"}, {"input": "5\n 2 5 2\n 2 3 10\n 1 3 8\n 3 4 2", "output": "1\n 0\n 1\n 0\n 1"}] |
Print the number of white cells that will remain.
* * * | s632766629 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | H, M = map(int, input().split())
h, m = map(int, input().split())
print((H - h) * (M - m))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s579776338 | Runtime Error | p03101 | Input is given from Standard Input in the following format:
H W
h w | x = int(input())
print(2 * x * 3.14)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s468716950 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | import functools
import os
INF = float("inf")
def inp():
return int(input())
def inpf():
return float(input())
def inps():
return input()
def inl():
return list(map(int, input().split()))
def inlf():
return list(map(float, input().split()))
def inls():
return input().split()
def debug(fn):
if not os.getenv("LOCAL"):
return fn
@functools.wraps(fn)
def wrapper(*args, **kwargs):
print(
"DEBUG: {}({}) -> ".format(
fn.__name__,
", ".join(
list(map(str, args))
+ ["{}={}".format(k, str(v)) for k, v in kwargs.items()]
),
),
end="",
)
ret = fn(*args, **kwargs)
print(ret)
return ret
return wrapper
h, w = inl()
h2, w2 = inl()
print(h * w - h2 * w - w2 * h + h2 * w2)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s529626236 | Wrong Answer | p03101 | Input is given from Standard Input in the following format:
H W
h w | HW_list = [list(map(int, input().split())) for i in range(2)]
print(HW_list[0][0] * HW_list[0][1] - HW_list[1][0] * HW_list[1][1])
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s959030395 | Runtime Error | p03101 | Input is given from Standard Input in the following format:
H W
h w | import numpy as np
A, B = map(int, input().split())
b = np.arange(A, B + 1)
def bin2np(a):
return list(map(int, list(bin(a)[2:])))
# 1番長い二進数の配列を知る
max_length = len(bin2np(b[-1]))
## ここから、足りない分だけ前に挿入していく
bin2list = []
for a in b:
c = bin2np(a)
for _ in range(max_length - len(c)):
c.insert(0, 0)
# print(c)
bin2list.append(c)
bin2list = np.array(bin2list)
bin2s = list(map(str, np.where(np.sum(bin2list, axis=0) == 1, 1, 0)))
print(int("".join(bin2s), 2))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s091325580 | Wrong Answer | p03101 | Input is given from Standard Input in the following format:
H W
h w | # -*- Coding: utf-8 -*-
import numpy as np
INPUT = input().split()
Input = input().split()
H = int(INPUT[0])
W = int(INPUT[1])
h = int(Input[0])
w = int(Input[1])
mat = np.ones((H, W))
mat[0:h, :] = 0
mat[:, 0:w] = 0
print(mat.sum())
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s229107924 | Runtime Error | p03101 | Input is given from Standard Input in the following format:
H W
h w | a, b = map((int, input()).split())
c, d = map((int, input()).split())
print(a * b - c * b - d * a)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s396995346 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | x = input()
y = x.split(" ")
map = [int(i) for i in y]
x = input()
y = x.split(" ")
cell = [int(i) for i in y]
map[0] = map[0] - cell[0]
map[1] = map[1] - cell[1]
print(map[0] * map[1])
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s293772662 | Wrong Answer | p03101 | Input is given from Standard Input in the following format:
H W
h w | N, M = list(map(int, input().split()))
# Insert all the data into dictionary
stores = []
while 1:
try:
a, b = list(map(int, input().split()))
stores.append([a, b])
except:
break
stores = sorted(stores, key=lambda x: x[0])
m = 0
money = 0
for store in stores:
money += min(store[1], M - m) * store[0]
if m == M:
break
print(money)
print(stores)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s724651246 | Wrong Answer | p03101 | Input is given from Standard Input in the following format:
H W
h w | def main():
print("debug")
if __name__ == "__main__":
main()
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s717083599 | Wrong Answer | p03101 | Input is given from Standard Input in the following format:
H W
h w | a, s = map(int, input().split())
f, g = map(int, input().split())
print(a * s - f * g)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s278933394 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | N = [list(map(int, input().split())) for i in range(2)]
print((N[0][0] - N[1][0]) * (N[0][1] - N[1][1]))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s314749280 | Wrong Answer | p03101 | Input is given from Standard Input in the following format:
H W
h w | h1, w1 = list(map(int, input().split()))
h2, w2 = list(map(int, input().split()))
print((h1 - h2) * (w2 - w1))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s450211715 | Wrong Answer | p03101 | Input is given from Standard Input in the following format:
H W
h w | List = [list(map(int, input().split())) for i in range(2)]
print((List[0][0] - List[1][0]) * (List[0][1] * List[1][1]))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s672387189 | Runtime Error | p03101 | Input is given from Standard Input in the following format:
H W
h w | i = list()
for x in range(2):
i.append(map(int, input().split()))
print(i[0][0] - i[1][0]) * (i[0][1] - i[1][1])
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s599488263 | Wrong Answer | p03101 | Input is given from Standard Input in the following format:
H W
h w | p, q = input().split()
a, b = (int(p), int(q))
P, Q = input().split()
A, B = (int(P), int(Q))
print(int(a * b - A * B))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s655976048 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | A = input().split()
B = input().split()
Cell = int(A[0]) * int(A[1])
uni = int(A[0]) * int(B[1]) + int(A[1]) * int(B[0])
add = int(B[0]) * int(B[1])
ans = Cell - uni + add
print(ans)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s661369524 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | H, W = [int(HW) for HW in input().split()]
h, w = [int(hw) for hw in input().split()]
n = H * W - h * W - H * w + h * w
print(n)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s912753476 | Runtime Error | p03101 | Input is given from Standard Input in the following format:
H W
h w | N, M, C = map(int, (input()).split())
List_B = [int(i) for i in (input()).split()]
t = 0
for j in range(1, N + 1):
List_A = [int(k) for k in (input()).split()]
if sum([x * y for (x, y) in zip(List_A, List_B)]) > -C:
t += 1
print(t)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s246929768 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | line = input()
table = line.split(" ")
nuru = input()
nurut = nuru.split(" ")
table_sum = int(table[0]) * int(table[1])
table_sum = (
table_sum
- int(nurut[0]) * int(table[1])
- int(nurut[1]) * int(table[0])
+ int(nurut[0]) * int(nurut[1])
)
print(table_sum)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s343916739 | Runtime Error | p03101 | Input is given from Standard Input in the following format:
H W
h w | HW = input().split()
hw = input().split
print((HW[0] - hw[0]) * (HW[1] - hw[1]))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s331216863 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | n1, m1 = map(int, input().split())
n2, m2 = map(int, input().split())
print((n1 - n2) * (m1 - m2))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s016870448 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | tate, yoko = map(int, input().split())
tate_hiku, yoko_hiku = map(int, input().split())
zenbu = tate * yoko
tate_hiku_zenbu = tate_hiku * yoko
yoko_hiku_zenbu = yoko_hiku * tate
kasanari = tate_hiku * yoko_hiku
print(zenbu - tate_hiku_zenbu - yoko_hiku_zenbu + kasanari)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s131226584 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | usr1 = input()
usr2 = input()
lst1 = usr1.split()
lst2 = usr2.split()
numlst1 = []
numlst2 = []
for element in lst1:
numlst1.append(int(element))
for element in lst2:
numlst2.append(int(element))
print((numlst1[0] - numlst2[0]) * (numlst1[1] - numlst2[1]))
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s971419399 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | n = [input().split() for i in range(2)]
H = int(n[0][0])
W = int(n[0][1])
h = int(n[1][0])
w = int(n[1][1])
answer = H * W - h * W - w * H + h * w
print(answer)
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s939621064 | Accepted | p03101 | Input is given from Standard Input in the following format:
H W
h w | # n = int(input())
a, b = map(int, input().split()) # 横並び
x, y = map(int, input().split())
ret = x * b + a * y - x * y
print(a * b - ret)
# x=[int(input()) for i in range(3)] #縦に並んだのを配列に
# y=list(map(int,input().split())) #横に並んだのを配列に
# print('YNEOS'[1::2])
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
Print the number of white cells that will remain.
* * * | s195918493 | Runtime Error | p03101 | Input is given from Standard Input in the following format:
H W
h w | n, m = (int(i) for i in input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = sorted(a)
cnt = 0
money = 0
while True:
for x, y in b:
cnt += y
money += x * y
if m < cnt:
money -= (cnt - m) * x
print(money)
exit()
| Statement
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells
contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are
chosen. | [{"input": "3 2\n 2 1", "output": "1\n \n\nThere are 3 rows and 2 columns of cells. When two rows and one column are\nchosen and painted in black, there is always one white cell that remains.\n\n* * *"}, {"input": "5 5\n 2 3", "output": "6\n \n\n* * *"}, {"input": "2 4\n 2 4", "output": "0"}] |
For each dataset, output in a line the maximum number of blocks you can
remove. | s159968860 | Wrong Answer | p01096 | The input consists of multiple datasets. The number of datasets is at most 50.
Each dataset is in the following format.
_n_
_w_ 1 _w_ 2 … _w_ _n_
_n_ is the number of blocks, except Dharma on the top. _n_ is a positive
integer not exceeding 300. _w_ _i_ gives the weight of the _i_ -th block
counted from the bottom. _w_ _i_ is an integer between 1 and 1000, inclusive.
The end of the input is indicated by a line containing a zero. | n = int(input())
w = list(map(int, input().split()))
dp = [[-1 for j in range(n + 1)] for i in range(n + 1)]
def rec(l, r):
if dp[l][r] != -1:
return dp[l][r]
if abs(l - r) <= 1:
return 0
res = 0
if abs(w[l] - w[r - 1]) <= 1 and rec(l + 1, r - 1) == r - l - 2:
res = r - l
for mid in range(l + 1, r - 1):
res = max(res, rec(l, mid) + rec(mid, r))
dp[l][r] = res
return res
print(rec(0, n))
| Daruma Otoshi
You are playing a variant of a game called "Daruma Otoshi (Dharma Block
Striking)".
At the start of a game, several wooden blocks of the same size but with
varying weights are stacked on top of each other, forming a tower. Another
block symbolizing Dharma is placed atop. You have a wooden hammer with its
head thicker than the height of a block, but not twice that.
You can choose any two adjacent blocks, except Dharma on the top, differing at
most 1 in their weight, and push both of them out of the stack with a single
blow of your hammer. The blocks above the removed ones then fall straight
down, without collapsing the tower. You cannot hit a block pair with weight
difference of 2 or more, for that makes too hard to push out blocks while
keeping the balance of the tower. There is no chance in hitting three blocks
out at a time, for that would require superhuman accuracy.
The goal of the game is to remove as many blocks as you can. Your task is to
decide the number of blocks that can be removed by repeating the blows in an
optimal order.

Figure D1. Striking out two blocks at a time
In the above figure, with a stack of four blocks weighing 1, 2, 3, and 1, in
this order from the bottom, you can hit middle two blocks, weighing 2 and 3,
out from the stack. The blocks above will then fall down, and two blocks
weighing 1 and the Dharma block will remain. You can then push out the
remaining pair of weight-1 blocks after that. | [{"input": "1 2 3 4\n 4\n 1 2 3 1\n 5\n 5 1 2 3 6\n 14\n 8 7 1 4 3 5 4 1 6 8 10 4 6 5\n 5\n 1 3 5 1 3\n 0", "output": "4\n 2\n 12\n 0"}] |
Print X, the expected value of the total execution time of the code, as an
integer. It can be proved that, under the constraints in this problem, X is an
integer not exceeding 10^9.
* * * | s718228025 | Runtime Error | p03551 | Input is given from Standard Input in the following format:
N M | N = int(input())
a = [int(n) for n in input().split()]
infty = 10**15
res = 0
edge = [[0] * (N + 2) for _ in range(N + 2)]
for i, t in enumerate(a):
if t > 0:
edge[i][N + 1] = t
res += t
else:
edge[N][i] = -t
for i in range(1, N + 1):
for j in range(2, N // i + 1):
edge[i - 1][i * j - 1] = infty
def dfs(now):
checked[now] = True
if now == N + 1:
return 1
for nx in range(N + 2):
if nx != now and edge[now][nx] > 0 and checked[nx] == False:
if dfs(nx) > 0:
edge[now][nx] -= 1
edge[nx][now] += 1
return 1
return 0
# print(res)
while True:
checked = [False] * (N + 2)
checked[N] = True
if dfs(N) > 0:
res -= 1
else:
break
print(res)
| Statement
Takahashi is now competing in a programming contest, but he received TLE in a
problem where the answer is `YES` or `NO`.
When he checked the detailed status of the submission, there were N test cases
in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2
probability in 1900 milliseconds, and correctly solve each of the other N-M
cases without fail in 100 milliseconds.
Now, he goes through the following process:
* Submit the code.
* Wait until the code finishes execution on all the cases.
* If the code fails to correctly solve some of the M cases, submit it again.
* Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X
milliseconds. Print X (as an integer). | [{"input": "1 1", "output": "3800\n \n\nIn this input, there is only one case. Takahashi will repeatedly submit the\ncode that correctly solves this case with 1/2 probability in 1900\nmilliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts\nwith 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times\n1900) \\times 1/8 + ... = 3800.\n\n* * *"}, {"input": "10 2", "output": "18400\n \n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100\nmilliseconds in each of the 10-2=8 cases. The probability of the code\ncorrectly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\n* * *"}, {"input": "100 5", "output": "608000"}] |
Print X, the expected value of the total execution time of the code, as an
integer. It can be proved that, under the constraints in this problem, X is an
integer not exceeding 10^9.
* * * | s760503313 | Accepted | p03551 | Input is given from Standard Input in the following format:
N M | n, m = map(int, input().strip().split())
print((2**m) * ((n - m) * 100 + m * 1900))
| Statement
Takahashi is now competing in a programming contest, but he received TLE in a
problem where the answer is `YES` or `NO`.
When he checked the detailed status of the submission, there were N test cases
in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2
probability in 1900 milliseconds, and correctly solve each of the other N-M
cases without fail in 100 milliseconds.
Now, he goes through the following process:
* Submit the code.
* Wait until the code finishes execution on all the cases.
* If the code fails to correctly solve some of the M cases, submit it again.
* Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X
milliseconds. Print X (as an integer). | [{"input": "1 1", "output": "3800\n \n\nIn this input, there is only one case. Takahashi will repeatedly submit the\ncode that correctly solves this case with 1/2 probability in 1900\nmilliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts\nwith 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times\n1900) \\times 1/8 + ... = 3800.\n\n* * *"}, {"input": "10 2", "output": "18400\n \n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100\nmilliseconds in each of the 10-2=8 cases. The probability of the code\ncorrectly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\n* * *"}, {"input": "100 5", "output": "608000"}] |
Print X, the expected value of the total execution time of the code, as an
integer. It can be proved that, under the constraints in this problem, X is an
integer not exceeding 10^9.
* * * | s380446280 | Accepted | p03551 | Input is given from Standard Input in the following format:
N M | a, b = map(int, input().split(" "))
t = (a - b) * 100 + b * 1900
print(t * (2**b))
| Statement
Takahashi is now competing in a programming contest, but he received TLE in a
problem where the answer is `YES` or `NO`.
When he checked the detailed status of the submission, there were N test cases
in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2
probability in 1900 milliseconds, and correctly solve each of the other N-M
cases without fail in 100 milliseconds.
Now, he goes through the following process:
* Submit the code.
* Wait until the code finishes execution on all the cases.
* If the code fails to correctly solve some of the M cases, submit it again.
* Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X
milliseconds. Print X (as an integer). | [{"input": "1 1", "output": "3800\n \n\nIn this input, there is only one case. Takahashi will repeatedly submit the\ncode that correctly solves this case with 1/2 probability in 1900\nmilliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts\nwith 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times\n1900) \\times 1/8 + ... = 3800.\n\n* * *"}, {"input": "10 2", "output": "18400\n \n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100\nmilliseconds in each of the 10-2=8 cases. The probability of the code\ncorrectly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\n* * *"}, {"input": "100 5", "output": "608000"}] |
Print X, the expected value of the total execution time of the code, as an
integer. It can be proved that, under the constraints in this problem, X is an
integer not exceeding 10^9.
* * * | s407273419 | Accepted | p03551 | Input is given from Standard Input in the following format:
N M | n, m = map(int, input().split())
# one attempt 1/2^m
# two attempts (1-1/2^m) * 1/2^m
# x attempts (1 - 1/2^m)**(x-1) * 1/2^m
exec = m * 1900 + 100 * (n - m)
a = 1 / (2**m)
b = 1 - a
left = 1
x = 0
prob = 1
att = 0
while prob > 1e-9:
att += 1
prob = left * a
x += prob * att * exec
# print(prob, x)
left *= b
print(int(x + 0.5))
| Statement
Takahashi is now competing in a programming contest, but he received TLE in a
problem where the answer is `YES` or `NO`.
When he checked the detailed status of the submission, there were N test cases
in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2
probability in 1900 milliseconds, and correctly solve each of the other N-M
cases without fail in 100 milliseconds.
Now, he goes through the following process:
* Submit the code.
* Wait until the code finishes execution on all the cases.
* If the code fails to correctly solve some of the M cases, submit it again.
* Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X
milliseconds. Print X (as an integer). | [{"input": "1 1", "output": "3800\n \n\nIn this input, there is only one case. Takahashi will repeatedly submit the\ncode that correctly solves this case with 1/2 probability in 1900\nmilliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts\nwith 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times\n1900) \\times 1/8 + ... = 3800.\n\n* * *"}, {"input": "10 2", "output": "18400\n \n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100\nmilliseconds in each of the 10-2=8 cases. The probability of the code\ncorrectly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\n* * *"}, {"input": "100 5", "output": "608000"}] |
Print X, the expected value of the total execution time of the code, as an
integer. It can be proved that, under the constraints in this problem, X is an
integer not exceeding 10^9.
* * * | s168704378 | Runtime Error | p03551 | Input is given from Standard Input in the following format:
N M | data = input().split(" ")
n = int(data[0])
z = int(data[1])
w = int(data[2])
a = input().split(" ")
b = int(a[n - 2])
c = int(a[n - 1])
ans = abs(w - c)
if ans <= abs(b - c):
ans = abs(b - c)
print(ans)
| Statement
Takahashi is now competing in a programming contest, but he received TLE in a
problem where the answer is `YES` or `NO`.
When he checked the detailed status of the submission, there were N test cases
in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2
probability in 1900 milliseconds, and correctly solve each of the other N-M
cases without fail in 100 milliseconds.
Now, he goes through the following process:
* Submit the code.
* Wait until the code finishes execution on all the cases.
* If the code fails to correctly solve some of the M cases, submit it again.
* Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X
milliseconds. Print X (as an integer). | [{"input": "1 1", "output": "3800\n \n\nIn this input, there is only one case. Takahashi will repeatedly submit the\ncode that correctly solves this case with 1/2 probability in 1900\nmilliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts\nwith 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times\n1900) \\times 1/8 + ... = 3800.\n\n* * *"}, {"input": "10 2", "output": "18400\n \n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100\nmilliseconds in each of the 10-2=8 cases. The probability of the code\ncorrectly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\n* * *"}, {"input": "100 5", "output": "608000"}] |
Print X, the expected value of the total execution time of the code, as an
integer. It can be proved that, under the constraints in this problem, X is an
integer not exceeding 10^9.
* * * | s249750457 | Accepted | p03551 | Input is given from Standard Input in the following format:
N M | n, k = map(int, input().split())
# 無限等比級数的なアレ
s = (n - k) * 100 + k * 1900
p = 2**k
print(s * p)
| Statement
Takahashi is now competing in a programming contest, but he received TLE in a
problem where the answer is `YES` or `NO`.
When he checked the detailed status of the submission, there were N test cases
in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2
probability in 1900 milliseconds, and correctly solve each of the other N-M
cases without fail in 100 milliseconds.
Now, he goes through the following process:
* Submit the code.
* Wait until the code finishes execution on all the cases.
* If the code fails to correctly solve some of the M cases, submit it again.
* Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X
milliseconds. Print X (as an integer). | [{"input": "1 1", "output": "3800\n \n\nIn this input, there is only one case. Takahashi will repeatedly submit the\ncode that correctly solves this case with 1/2 probability in 1900\nmilliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts\nwith 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times\n1900) \\times 1/8 + ... = 3800.\n\n* * *"}, {"input": "10 2", "output": "18400\n \n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100\nmilliseconds in each of the 10-2=8 cases. The probability of the code\ncorrectly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\n* * *"}, {"input": "100 5", "output": "608000"}] |
Print X, the expected value of the total execution time of the code, as an
integer. It can be proved that, under the constraints in this problem, X is an
integer not exceeding 10^9.
* * * | s531868402 | Runtime Error | p03551 | Input is given from Standard Input in the following format:
N M | n, z, w = map(int, input().split())
a = list(map(int, input().split()))
cand1 = abs(a[-1] - a[-2])
cand2 = abs(a[-1] - w)
res = max(cand1, cand2)
print(res)
| Statement
Takahashi is now competing in a programming contest, but he received TLE in a
problem where the answer is `YES` or `NO`.
When he checked the detailed status of the submission, there were N test cases
in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2
probability in 1900 milliseconds, and correctly solve each of the other N-M
cases without fail in 100 milliseconds.
Now, he goes through the following process:
* Submit the code.
* Wait until the code finishes execution on all the cases.
* If the code fails to correctly solve some of the M cases, submit it again.
* Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X
milliseconds. Print X (as an integer). | [{"input": "1 1", "output": "3800\n \n\nIn this input, there is only one case. Takahashi will repeatedly submit the\ncode that correctly solves this case with 1/2 probability in 1900\nmilliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts\nwith 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times\n1900) \\times 1/8 + ... = 3800.\n\n* * *"}, {"input": "10 2", "output": "18400\n \n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100\nmilliseconds in each of the 10-2=8 cases. The probability of the code\ncorrectly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\n* * *"}, {"input": "100 5", "output": "608000"}] |
Print the answers for k = 1, 2, ..., N in order, each in its own line.
* * * | s491369924 | Accepted | p02710 | Input is given from Standard Input in the following format:
N
c_1 c_2 ... c_N
a_1 b_1
:
a_{N-1} b_{N-1} | import os
from collections import Counter, defaultdict
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N)]
for a, b in AB:
a -= 1
b -= 1
graph[a].append(b)
graph[b].append(a)
color_counts = [defaultdict(int) for _ in range(N + 1)]
for c in range(1, N + 1):
color_counts[c][0] = N
color_v_weights = [[] for _ in range(N + 1)]
color_v = [0 for _ in range(N + 1)]
color_v_next = [1 for _ in range(N + 1)]
# color_parents = [[] for _ in range(N + 1)]
# color_stack = [[] for _ in range(N + 1)]
# children_counts = defaultdict(int)
def dfs(v, p):
color = C[v]
color_v_prev = color_v[color]
children_cv = []
ret = 1
for u in graph[v]:
if u == p:
continue
cv = color_v_next[color]
children_cv.append(cv)
color_v[color] = cv
color_v_next[color] += 1
cnt = dfs(u, v)
ret += cnt
color_counts[color][cv] += cnt
color_v[color] = color_v_prev
color_counts[color][color_v_prev] -= ret
return ret
dfs(0, None)
counter = Counter(C)
for color, cc in enumerate(color_counts[1:], start=1):
ans = N * (N - 1) // 2 + counter[color]
for cnt in cc.values():
ans -= cnt * (cnt - 1) // 2
print(ans)
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree
connects Vertex a_i and b_i. Additionally, each vertex is painted in a color,
and the color of Vertex i is c_i. Here, the color of each vertex is
represented by an integer between 1 and N (inclusive). The same integer
corresponds to the same color; different integers correspond to different
colors.
For each k=1, 2, ..., N, solve the following problem:
* Find the number of simple paths that visit a vertex painted in the color k one or more times.
**Note:** The simple paths from Vertex u to v and from v to u are not
distinguished. | [{"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "5\n 4\n 0\n \n\nLet P_{i,j} denote the simple path connecting Vertex i and j.\n\nThere are 5 simple paths that visit a vertex painted in the color 1 one or\nmore times: \nP_{1,1}\\,,\\, P_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,3}\\,,\\, P_{3,3}\n\nThere are 4 simple paths that visit a vertex painted in the color 2 one or\nmore times: \nP_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,2}\\,,\\, P_{2,3}\n\nThere are no simple paths that visit a vertex painted in the color 3 one or\nmore times.\n\n* * *"}, {"input": "1\n 1", "output": "1\n \n\n* * *"}, {"input": "2\n 1 2\n 1 2", "output": "2\n 2\n \n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1 2\n 2 3\n 3 4\n 3 5", "output": "5\n 8\n 10\n 5\n 5\n \n\n* * *"}, {"input": "8\n 2 7 2 5 4 1 7 5\n 3 1\n 1 2\n 2 7\n 4 5\n 5 6\n 6 8\n 7 8", "output": "18\n 15\n 0\n 14\n 23\n 0\n 23\n 0"}] |
Print the answers for k = 1, 2, ..., N in order, each in its own line.
* * * | s730196863 | Accepted | p02710 | Input is given from Standard Input in the following format:
N
c_1 c_2 ... c_N
a_1 b_1
:
a_{N-1} b_{N-1} | import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
sys.setrecursionlimit(10**6)
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & (-i)
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & (-i)
def resolve():
N = ir()
c = lr()
ab = [[] for i in range(N)]
for i in range(N - 1):
a, b = lr()
ab[a - 1].append(b - 1)
ab[b - 1].append(a - 1)
tot = N * (N + 1) // 2
il = [0] * N
ol = [0] * N
cnt = [0]
def dfs(u, p):
cnt[0] += 1
il[u] = cnt[0]
for i in ab[u]:
if i != p:
dfs(i, u)
ol[u] = cnt[0]
dfs(0, -1)
vs = [[] for i in range(N)]
for i in range(N):
vs[c[i] - 1].append(i)
sl = Bit(N)
for i in range(1, N + 1):
sl.add(i, 1)
for i in range(N):
his = []
ans = tot
tvs = sorted(vs[i], key=lambda x: il[x])[::-1]
for v in tvs:
n = 1
for j in ab[v]:
if il[j] > il[v]:
tmp = sl.sum(ol[j]) - sl.sum(il[j] - 1)
ans -= tmp * (tmp + 1) // 2
n += tmp
sl.add(il[v], -n)
his.append([il[v], n])
tmp = sl.sum(ol[0]) - sl.sum(0)
ans -= tmp * (tmp + 1) // 2
for h in his:
sl.add(h[0], h[1])
print(ans)
resolve()
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree
connects Vertex a_i and b_i. Additionally, each vertex is painted in a color,
and the color of Vertex i is c_i. Here, the color of each vertex is
represented by an integer between 1 and N (inclusive). The same integer
corresponds to the same color; different integers correspond to different
colors.
For each k=1, 2, ..., N, solve the following problem:
* Find the number of simple paths that visit a vertex painted in the color k one or more times.
**Note:** The simple paths from Vertex u to v and from v to u are not
distinguished. | [{"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "5\n 4\n 0\n \n\nLet P_{i,j} denote the simple path connecting Vertex i and j.\n\nThere are 5 simple paths that visit a vertex painted in the color 1 one or\nmore times: \nP_{1,1}\\,,\\, P_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,3}\\,,\\, P_{3,3}\n\nThere are 4 simple paths that visit a vertex painted in the color 2 one or\nmore times: \nP_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,2}\\,,\\, P_{2,3}\n\nThere are no simple paths that visit a vertex painted in the color 3 one or\nmore times.\n\n* * *"}, {"input": "1\n 1", "output": "1\n \n\n* * *"}, {"input": "2\n 1 2\n 1 2", "output": "2\n 2\n \n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1 2\n 2 3\n 3 4\n 3 5", "output": "5\n 8\n 10\n 5\n 5\n \n\n* * *"}, {"input": "8\n 2 7 2 5 4 1 7 5\n 3 1\n 1 2\n 2 7\n 4 5\n 5 6\n 6 8\n 7 8", "output": "18\n 15\n 0\n 14\n 23\n 0\n 23\n 0"}] |
Print the answers for k = 1, 2, ..., N in order, each in its own line.
* * * | s397161057 | Accepted | p02710 | Input is given from Standard Input in the following format:
N
c_1 c_2 ... c_N
a_1 b_1
:
a_{N-1} b_{N-1} | import sys
input = sys.stdin.readline
N = int(input())
C = [0] + list(map(int, input().split()))
E = [[] for i in range(N + 1)]
for i in range(N - 1):
a, b = map(int, input().split())
E[a].append(b)
E[b].append(a)
from collections import deque
QUE = deque([1])
QUE2 = deque()
EULER = [0] # これが1からツアーで辿った点
USED = [0] * (N + 1)
Parent = [-1] * (N + 1)
TOP_SORT = [1]
Children = [[] for i in range(N + 1)]
while QUE:
x = QUE.pop()
EULER.append(x)
if USED[x] == 1:
continue
for to in E[x]:
if USED[to] == 0:
QUE2.append(to)
Parent[to] = x
Children[x].append(to)
TOP_SORT.append(to)
else:
QUE.append(to)
QUE.extend(QUE2)
QUE2 = deque()
USED[x] = 1
CE = [[] for i in range(N + 1)]
CTOP_SORT = [[] for i in range(N + 1)]
for x in TOP_SORT:
CTOP_SORT[C[x]].append(x)
EFIRST = [-1] * (N + 1)
ELAST = [-1] * (N + 1)
for i in range(len(EULER)):
if EFIRST[EULER[i]] == -1:
EFIRST[EULER[i]] = i
ELAST[EULER[i]] = i
CE[C[EULER[i]]].append(i)
Size = [1] * (N + 1)
for i in TOP_SORT[1:][::-1]:
Size[Parent[i]] += Size[i]
Size[0] = N + 1
LEN = len(EULER)
BIT = [0] * (LEN + 1) # 1-indexedなtree
def update(v, w): # index vにwを加える
while v <= LEN:
BIT[v] += w
v += v & (-v) # 自分を含む大きなノードへ. たとえばv=3→v=4
def getvalue(v): # [1,v]の区間の和を求める
ANS = 0
while v != 0:
ANS += BIT[v]
v -= v & (-v) # 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
return ANS
for i in range(1, N + 1):
update(EFIRST[i], 1)
for color in range(1, N + 1):
if CE[color] == []:
print(0)
continue
EULER2 = CE[color]
TOP_SORT2 = CTOP_SORT[color]
HISTORY = []
# print(EULER2,TOP_SORT2)
# print(BIT)
ANS = 0
for x in TOP_SORT2[::-1]:
for to in Children[x]:
sc = getvalue(ELAST[to]) - getvalue(EFIRST[to] - 1)
update(EFIRST[x], -sc)
HISTORY.append((EFIRST[x], sc))
ANS += sc * (sc + 1) // 2
update(EFIRST[x], -1)
HISTORY.append((EFIRST[x], 1))
# print(ANS)
sc = getvalue(len(EULER))
ANS += sc * (sc + 1) // 2
print(N * (N + 1) // 2 - ANS)
for x, y in HISTORY:
update(x, y)
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree
connects Vertex a_i and b_i. Additionally, each vertex is painted in a color,
and the color of Vertex i is c_i. Here, the color of each vertex is
represented by an integer between 1 and N (inclusive). The same integer
corresponds to the same color; different integers correspond to different
colors.
For each k=1, 2, ..., N, solve the following problem:
* Find the number of simple paths that visit a vertex painted in the color k one or more times.
**Note:** The simple paths from Vertex u to v and from v to u are not
distinguished. | [{"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "5\n 4\n 0\n \n\nLet P_{i,j} denote the simple path connecting Vertex i and j.\n\nThere are 5 simple paths that visit a vertex painted in the color 1 one or\nmore times: \nP_{1,1}\\,,\\, P_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,3}\\,,\\, P_{3,3}\n\nThere are 4 simple paths that visit a vertex painted in the color 2 one or\nmore times: \nP_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,2}\\,,\\, P_{2,3}\n\nThere are no simple paths that visit a vertex painted in the color 3 one or\nmore times.\n\n* * *"}, {"input": "1\n 1", "output": "1\n \n\n* * *"}, {"input": "2\n 1 2\n 1 2", "output": "2\n 2\n \n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1 2\n 2 3\n 3 4\n 3 5", "output": "5\n 8\n 10\n 5\n 5\n \n\n* * *"}, {"input": "8\n 2 7 2 5 4 1 7 5\n 3 1\n 1 2\n 2 7\n 4 5\n 5 6\n 6 8\n 7 8", "output": "18\n 15\n 0\n 14\n 23\n 0\n 23\n 0"}] |
Print the answers for k = 1, 2, ..., N in order, each in its own line.
* * * | s893296622 | Accepted | p02710 | Input is given from Standard Input in the following format:
N
c_1 c_2 ... c_N
a_1 b_1
:
a_{N-1} b_{N-1} | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def solve(N, C, AB):
def edges_to_array(A, B, N, M):
head = [-1] * (N + 1)
nxt = [0] * (M + M)
to = [0] * (M + M)
for i in range(M):
a = A[i]
b = B[i]
nxt[i << 1] = head[a]
to[i << 1] = b
head[a] = i << 1
nxt[i << 1 | 1] = head[b]
to[i << 1 | 1] = a
head[b] = i << 1 | 1
return head, nxt, to
def EulerTour(head, nxt, to, root=1):
N = len(head) - 1
parent = [0] * (N + 1)
ind_L = [0] * (N + 1)
ind_R = [0] * (N + 1)
i = -1
tour = []
stack = [-root, root]
stack[0] = -root
stack[1] = root
while stack:
v = stack.pop()
tour.append(v)
i += 1
if v > 0:
ind_L[v] = i
p = parent[v]
k = head[v]
while k != -1:
w = to[k]
if w == p:
k = nxt[k]
continue
parent[w] = v
stack.append(-w)
stack.append(w)
k = nxt[k]
else:
ind_R[-v] = i
return tour, ind_L, ind_R, parent
head, nxt, to = edges_to_array(AB[::2], AB[1::2], N, N - 1)
tour, ind_L, ind_R, parent = EulerTour(head, nxt, to)
removed = [0] * (N + 1)
answer = [N * (N + 1) // 2] * (N + 1)
memo = [0] * (N + 1)
for v in tour:
if v > 0:
memo[v] = removed[C[parent[v]]]
else:
v = -v
removed[C[v]] += 1
p = parent[v]
x = (ind_R[v] - ind_L[v]) // 2 + 1 # subtree size
x -= removed[C[p]] - memo[v]
answer[C[p]] -= x * (x + 1) // 2
removed[C[p]] += x
for i, x in enumerate(removed):
x = N - x
answer[i] -= x * (x + 1) // 2
return answer
N = int(readline())
C = (0,) + tuple(map(int, readline().split()))
AB = tuple(map(int, read().split()))
answer = solve(N, C, AB)
print("\n".join(map(str, answer[1:])))
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree
connects Vertex a_i and b_i. Additionally, each vertex is painted in a color,
and the color of Vertex i is c_i. Here, the color of each vertex is
represented by an integer between 1 and N (inclusive). The same integer
corresponds to the same color; different integers correspond to different
colors.
For each k=1, 2, ..., N, solve the following problem:
* Find the number of simple paths that visit a vertex painted in the color k one or more times.
**Note:** The simple paths from Vertex u to v and from v to u are not
distinguished. | [{"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "5\n 4\n 0\n \n\nLet P_{i,j} denote the simple path connecting Vertex i and j.\n\nThere are 5 simple paths that visit a vertex painted in the color 1 one or\nmore times: \nP_{1,1}\\,,\\, P_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,3}\\,,\\, P_{3,3}\n\nThere are 4 simple paths that visit a vertex painted in the color 2 one or\nmore times: \nP_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,2}\\,,\\, P_{2,3}\n\nThere are no simple paths that visit a vertex painted in the color 3 one or\nmore times.\n\n* * *"}, {"input": "1\n 1", "output": "1\n \n\n* * *"}, {"input": "2\n 1 2\n 1 2", "output": "2\n 2\n \n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1 2\n 2 3\n 3 4\n 3 5", "output": "5\n 8\n 10\n 5\n 5\n \n\n* * *"}, {"input": "8\n 2 7 2 5 4 1 7 5\n 3 1\n 1 2\n 2 7\n 4 5\n 5 6\n 6 8\n 7 8", "output": "18\n 15\n 0\n 14\n 23\n 0\n 23\n 0"}] |
Print the answers for k = 1, 2, ..., N in order, each in its own line.
* * * | s996653686 | Runtime Error | p02710 | Input is given from Standard Input in the following format:
N
c_1 c_2 ... c_N
a_1 b_1
:
a_{N-1} b_{N-1} | def s0():
return input()
def s1():
return input().split()
def s2(n):
return [input() for x in range(n)]
def s3(n):
return [[input().split()] for _ in range(n)]
def n0():
return int(input())
def n1():
return [int(x) for x in input().split()]
def n2(n):
return [int(input()) for _ in range(n)]
def n3(n):
return [[int(x) for x in input().split()] for _ in range(n)]
n = n0()
c = n1()
ab = [(x[0], x[1]) for x in n3(n - 1)]
import networkx as nx
G = nx.Graph()
G.add_nodes_from(range(1, n + 1))
G.add_edges_from(ab)
dict_color = {i: 0 for i in range(1, n + 1)}
for j in c:
dict_color[j] += 1
for i in range(1, n + 1):
for line in list(
nx.all_simple_paths(G, source=i, target=[x for x in range(i + 1, n + 1)])
):
path_color = [c[x - 1] for x in line]
for i in set(path_color):
dict_color[i] += 1
for i in dict_color:
print(dict_color[i])
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree
connects Vertex a_i and b_i. Additionally, each vertex is painted in a color,
and the color of Vertex i is c_i. Here, the color of each vertex is
represented by an integer between 1 and N (inclusive). The same integer
corresponds to the same color; different integers correspond to different
colors.
For each k=1, 2, ..., N, solve the following problem:
* Find the number of simple paths that visit a vertex painted in the color k one or more times.
**Note:** The simple paths from Vertex u to v and from v to u are not
distinguished. | [{"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "5\n 4\n 0\n \n\nLet P_{i,j} denote the simple path connecting Vertex i and j.\n\nThere are 5 simple paths that visit a vertex painted in the color 1 one or\nmore times: \nP_{1,1}\\,,\\, P_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,3}\\,,\\, P_{3,3}\n\nThere are 4 simple paths that visit a vertex painted in the color 2 one or\nmore times: \nP_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,2}\\,,\\, P_{2,3}\n\nThere are no simple paths that visit a vertex painted in the color 3 one or\nmore times.\n\n* * *"}, {"input": "1\n 1", "output": "1\n \n\n* * *"}, {"input": "2\n 1 2\n 1 2", "output": "2\n 2\n \n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1 2\n 2 3\n 3 4\n 3 5", "output": "5\n 8\n 10\n 5\n 5\n \n\n* * *"}, {"input": "8\n 2 7 2 5 4 1 7 5\n 3 1\n 1 2\n 2 7\n 4 5\n 5 6\n 6 8\n 7 8", "output": "18\n 15\n 0\n 14\n 23\n 0\n 23\n 0"}] |
Print the answers for k = 1, 2, ..., N in order, each in its own line.
* * * | s453540432 | Wrong Answer | p02710 | Input is given from Standard Input in the following format:
N
c_1 c_2 ... c_N
a_1 b_1
:
a_{N-1} b_{N-1} | from copy import deepcopy
n = int(input())
col = list(map(int, input().split()))
children = [[] for i in range(n)]
n_path = [0] * n
c_path = [[0] * n for i in range(n)]
checked = [False] * n
num_check = 0
is_inv = False
for i in range(n):
col[i] -= 1
for i in range(n - 1):
a, b = map(int, input().split())
children[a - 1].append(b - 1)
for i in children:
for j in range(len(i)):
if checked[j]:
is_inv = True
break
checked[j] = True
if is_inv:
tmp_children = deepcopy(children)
children = [[] for i in range(n)]
for i in range(n):
for j in range(len(tmp_children[i])):
children[tmp_children[i][j]].append(i)
checked = [False] * n
while num_check < n:
for parent in range(n):
if checked[parent]:
continue
computable = True
for child in children[parent]:
if not checked[child]:
computable = False
break
if not computable:
continue
checked[parent] = True
num_check += 1
for child in children[parent]:
n_path[parent] += n_path[child]
for col_i in range(n):
c_path[parent][col_i] += (
n_path[child] if col[parent] == col_i else c_path[child][col_i]
)
n_path[parent] += 1
c_path[parent][col[parent]] += 1
for col_i in range(n):
ans = 0
for p in range(n):
if col[p] == col_i:
ans += n_path[p]
for c1 in children[p]:
for c2 in children[p]:
if c1 >= c2:
continue
ans += n_path[c1] * n_path[c2]
else:
ans += c_path[p][col_i]
for c1 in children[p]:
for c2 in children[p]:
if c1 == c2:
continue
ans += c_path[c1][col_i] * (
n_path[c2] if c2 > c1 else n_path[c2] - c_path[c2][col_i]
)
print(ans)
| Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree
connects Vertex a_i and b_i. Additionally, each vertex is painted in a color,
and the color of Vertex i is c_i. Here, the color of each vertex is
represented by an integer between 1 and N (inclusive). The same integer
corresponds to the same color; different integers correspond to different
colors.
For each k=1, 2, ..., N, solve the following problem:
* Find the number of simple paths that visit a vertex painted in the color k one or more times.
**Note:** The simple paths from Vertex u to v and from v to u are not
distinguished. | [{"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "5\n 4\n 0\n \n\nLet P_{i,j} denote the simple path connecting Vertex i and j.\n\nThere are 5 simple paths that visit a vertex painted in the color 1 one or\nmore times: \nP_{1,1}\\,,\\, P_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,3}\\,,\\, P_{3,3}\n\nThere are 4 simple paths that visit a vertex painted in the color 2 one or\nmore times: \nP_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,2}\\,,\\, P_{2,3}\n\nThere are no simple paths that visit a vertex painted in the color 3 one or\nmore times.\n\n* * *"}, {"input": "1\n 1", "output": "1\n \n\n* * *"}, {"input": "2\n 1 2\n 1 2", "output": "2\n 2\n \n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1 2\n 2 3\n 3 4\n 3 5", "output": "5\n 8\n 10\n 5\n 5\n \n\n* * *"}, {"input": "8\n 2 7 2 5 4 1 7 5\n 3 1\n 1 2\n 2 7\n 4 5\n 5 6\n 6 8\n 7 8", "output": "18\n 15\n 0\n 14\n 23\n 0\n 23\n 0"}] |
Print the answer.
* * * | s374905411 | Wrong Answer | p03802 | The input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda: sys.stdin.readline().rstrip()
def SCC(E):
n = len(E)
rev = [[] for _ in range(n)]
for v in range(n):
for nv in E[v]:
rev[nv].append(v)
used = [0] * n
order = []
for v in range(n):
if used[v]:
continue
used[v] = 1
stack = [~v, v]
while stack:
v = stack.pop()
if v >= 0:
if used[v]:
continue
for nv in E[v]:
if not used[nv]:
used[nv] = 1
stack.append(~nv)
stack.append(nv)
else:
if used[~v] == 2:
continue
used[~v] = 2
order.append(~v)
cnt = 0
color = [-1] * n
for v in order[::-1]:
if color[v] != -1:
continue
color[v] = cnt
queue = [v]
for v in queue:
for nv in rev[v]:
if color[nv] == -1:
color[nv] = cnt
queue.append(nv)
cnt += 1
return color
from bisect import bisect_left, bisect_right
def resolve():
n = int(input())
ZI = []
for i in range(n):
x, y = map(int, input().split())
ZI.append((x, i)), ZI.append((y, i))
ZI.sort()
pair = [[] for _ in range(n)]
for i, p in enumerate(ZI):
pair[p[1]].append(i)
Z = [p[0] for p in ZI]
n *= 2
n2 = n * 2
def check(d):
N = 1 << (n2 - 1).bit_length()
E = [[] for _ in range(N * 2)]
for i in range(N - 1, 0, -1):
E[i].append(i << 1)
E[i].append(i << 1 | 1)
for u, v in pair:
E[u + N].append(v + n + N)
E[u + n + N].append(v + N)
E[v + N].append(u + n + N)
E[v + n + N].append(u + N)
for i, z in enumerate(Z):
L = bisect_right(Z, z - d)
R = bisect_left(Z, z + d)
for l, r in [(L + n, i + n), (i + 1 + n, R + n)]:
l += N
r += N
while l < r:
if l & 1:
E[i + N].append(l)
l += 1
if r & 1:
r -= 1
E[i + N].append(r)
l >>= 1
r >>= 1
res = SCC(E)
return all(res[i + N] != res[i + n + N] for i in range(n))
l = 0
r = max(Z)
while r - l > 1:
m = (l + r) // 2
if check(m):
l = m
else:
r = m
print(l)
resolve()
| Statement
Snuke loves flags.
Snuke is placing N flags on a line.
The i-th flag can be placed at either coordinate x_i or coordinate y_i.
Snuke thinks that the flags look nicer when the smallest distance between two
of them, d, is larger. Find the maximum possible value of d. | [{"input": "3\n 1 3\n 2 5\n 1 9", "output": "4\n \n\nThe optimal solution is to place the first flag at coordinate 1, the second\nflag at coordinate 5 and the third flag at coordinate 9. The smallest distance\nbetween two of the flags is 4 in this case.\n\n* * *"}, {"input": "5\n 2 2\n 2 2\n 2 2\n 2 2\n 2 2", "output": "0\n \n\nThere can be more than one flag at the same position.\n\n* * *"}, {"input": "22\n 93 6440\n 78 6647\n 862 11\n 8306 9689\n 798 99\n 801 521\n 188 206\n 6079 971\n 4559 209\n 50 94\n 92 6270\n 5403 560\n 803 83\n 1855 99\n 42 504\n 75 484\n 629 11\n 92 122\n 3359 37\n 28 16\n 648 14\n 11 269", "output": "17"}] |
Print the answer.
* * * | s546022545 | Wrong Answer | p03802 | The input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
def readln():
_res = list(map(int, str(input()).split(" ")))
return _res
def pos(p):
return p % n
def number(p, x):
if x == 1:
return p + n
return p
def tuning(p, x, v, s, e):
if v[p]:
return s[p] == x
v[p] = True
s[p] = x
for j in e[number(p, x)]:
if s[pos(j)] != 0:
if j == number(pos(j), s[pos(j)]):
if not tuning(pos(j), -s[pos(j)], v, s, e):
return False
return True
def add(p, x, s, e):
tmp = s[:]
s[p] = x
v = [False for i in range(0, p + 1)]
if tuning(p, x, v, s, e):
return True
else:
s = tmp[:]
return False
def ok(d):
e = [[] for i in range(0, m)]
for i in range(0, m):
for j in range(0, i):
if abs(x[i] - x[j]) < d and i - j != n:
e[i].append(j)
e[j].append(i)
s = [0 for i in range(0, n)]
for i in range(0, n):
if (not add(i, 1, s, e)) and (not add(i, -1, s, e)):
return False
return True
n = int(input())
m = n * 2
x = [0 for i in range(0, m)]
for i in range(0, n):
a = readln()
x[i], x[i + n] = a[0], a[1]
l = 0
r = max(x[0], x[1], x[n], x[n + 1]) - min(x[0], x[1], x[n], x[n + 1]) + 1
while l < r - 1:
mid = (l + r) // 2
if ok(mid):
l = mid
else:
r = mid
print(l)
# 3
# 1 3
# 2 5
# 1 9
# 4
# 22
# 93 6440
# 78 6647
# 862 11
# 8306 9689
# 798 99
# 801 521
# 188 206
# 6079 971
# 4559 209
# 50 94
# 92 6270
# 5403 560
# 803 83
# 1855 99
# 42 504
# 75 484
# 629 11
# 92 122
# 3359 37
# 28 16
# 648 14
# 11 269
# 17
| Statement
Snuke loves flags.
Snuke is placing N flags on a line.
The i-th flag can be placed at either coordinate x_i or coordinate y_i.
Snuke thinks that the flags look nicer when the smallest distance between two
of them, d, is larger. Find the maximum possible value of d. | [{"input": "3\n 1 3\n 2 5\n 1 9", "output": "4\n \n\nThe optimal solution is to place the first flag at coordinate 1, the second\nflag at coordinate 5 and the third flag at coordinate 9. The smallest distance\nbetween two of the flags is 4 in this case.\n\n* * *"}, {"input": "5\n 2 2\n 2 2\n 2 2\n 2 2\n 2 2", "output": "0\n \n\nThere can be more than one flag at the same position.\n\n* * *"}, {"input": "22\n 93 6440\n 78 6647\n 862 11\n 8306 9689\n 798 99\n 801 521\n 188 206\n 6079 971\n 4559 209\n 50 94\n 92 6270\n 5403 560\n 803 83\n 1855 99\n 42 504\n 75 484\n 629 11\n 92 122\n 3359 37\n 28 16\n 648 14\n 11 269", "output": "17"}] |
Print the answer.
* * * | s420589036 | Wrong Answer | p03802 | The input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | from functools import cmp_to_key
n = int(input())
a = list(map(int, input().split()))
def group(a):
d = {}
for i, x in enumerate(a):
d.setdefault(x, []).append(i)
return list(
map(
lambda x: [x[0], x[1][0], len(x[1])],
sorted(d.items(), key=cmp_to_key(lambda x, y: x[0] - y[0]), reverse=True),
)
)
ans = [0] * n
g = group(a)
g.append([0, 0, 0])
for c, n in zip(g[:-1], g[1:]):
ans[c[1]] += (c[0] - n[0]) * c[2]
n[1] = min(c[1], n[1])
n[2] += c[2]
[print(a) for a in ans]
| Statement
Snuke loves flags.
Snuke is placing N flags on a line.
The i-th flag can be placed at either coordinate x_i or coordinate y_i.
Snuke thinks that the flags look nicer when the smallest distance between two
of them, d, is larger. Find the maximum possible value of d. | [{"input": "3\n 1 3\n 2 5\n 1 9", "output": "4\n \n\nThe optimal solution is to place the first flag at coordinate 1, the second\nflag at coordinate 5 and the third flag at coordinate 9. The smallest distance\nbetween two of the flags is 4 in this case.\n\n* * *"}, {"input": "5\n 2 2\n 2 2\n 2 2\n 2 2\n 2 2", "output": "0\n \n\nThere can be more than one flag at the same position.\n\n* * *"}, {"input": "22\n 93 6440\n 78 6647\n 862 11\n 8306 9689\n 798 99\n 801 521\n 188 206\n 6079 971\n 4559 209\n 50 94\n 92 6270\n 5403 560\n 803 83\n 1855 99\n 42 504\n 75 484\n 629 11\n 92 122\n 3359 37\n 28 16\n 648 14\n 11 269", "output": "17"}] |
Print the answer.
* * * | s225337215 | Runtime Error | p03802 | The input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | N=int(input())
xy=[[int(i) for i in input().split()] for i in range(N)]
flag=[False for i in range(N)]
z=[[xy[i][0],i] for i in range(N)]
z.extend([[xy[i][1],i] for i in range(N)])
z.sort()
dist=[z[i+1]-z[i] for i in range(2N-1)]
dist.sort()
| Statement
Snuke loves flags.
Snuke is placing N flags on a line.
The i-th flag can be placed at either coordinate x_i or coordinate y_i.
Snuke thinks that the flags look nicer when the smallest distance between two
of them, d, is larger. Find the maximum possible value of d. | [{"input": "3\n 1 3\n 2 5\n 1 9", "output": "4\n \n\nThe optimal solution is to place the first flag at coordinate 1, the second\nflag at coordinate 5 and the third flag at coordinate 9. The smallest distance\nbetween two of the flags is 4 in this case.\n\n* * *"}, {"input": "5\n 2 2\n 2 2\n 2 2\n 2 2\n 2 2", "output": "0\n \n\nThere can be more than one flag at the same position.\n\n* * *"}, {"input": "22\n 93 6440\n 78 6647\n 862 11\n 8306 9689\n 798 99\n 801 521\n 188 206\n 6079 971\n 4559 209\n 50 94\n 92 6270\n 5403 560\n 803 83\n 1855 99\n 42 504\n 75 484\n 629 11\n 92 122\n 3359 37\n 28 16\n 648 14\n 11 269", "output": "17"}] |
Print the answer.
* * * | s683053725 | Runtime Error | p03802 | The input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | from functools import cmp_to_key
n = int(input())
a = list(map(int, input().split()))
def group(a):
d = {}
for i, x in enumerate(a):
d.setdefault(x, []).append(i)
s = sorted(d.items(), key=cmp_to_key(lambda x, y: x[0] - y[0]),
reverse=True)
return list(map(lambda x: [x[0], x[1][0], len(x[1])], s))
ans = [0] * n
g = group(a)
g.append([0, 0, 0])
for c, n in zip(g[:-1], g[1:]):
ans[c[1]] += (c[0] - n[0]) * c[2]
n[1] = min(c[1], n[1])
n[2] += c[2]
[print(a) for a in ans] | Statement
Snuke loves flags.
Snuke is placing N flags on a line.
The i-th flag can be placed at either coordinate x_i or coordinate y_i.
Snuke thinks that the flags look nicer when the smallest distance between two
of them, d, is larger. Find the maximum possible value of d. | [{"input": "3\n 1 3\n 2 5\n 1 9", "output": "4\n \n\nThe optimal solution is to place the first flag at coordinate 1, the second\nflag at coordinate 5 and the third flag at coordinate 9. The smallest distance\nbetween two of the flags is 4 in this case.\n\n* * *"}, {"input": "5\n 2 2\n 2 2\n 2 2\n 2 2\n 2 2", "output": "0\n \n\nThere can be more than one flag at the same position.\n\n* * *"}, {"input": "22\n 93 6440\n 78 6647\n 862 11\n 8306 9689\n 798 99\n 801 521\n 188 206\n 6079 971\n 4559 209\n 50 94\n 92 6270\n 5403 560\n 803 83\n 1855 99\n 42 504\n 75 484\n 629 11\n 92 122\n 3359 37\n 28 16\n 648 14\n 11 269", "output": "17"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s603386176 | Accepted | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | n, *a = map(int, open(0).readlines())
a.sort()
if n % 2:
b = a[: n // 2]
c = a[n // 2 :]
for i in range(n // 2):
b[i] *= 2
for i in range(2, n // 2 + 1):
c[i] *= 2
m = sum(c) - sum(b)
b = a[: n // 2 + 1]
c = a[n // 2 + 1 :]
for i in range(n // 2 - 1):
b[i] *= 2
for i in range(n // 2):
c[i] *= 2
m = max(m, sum(c) - sum(b))
else:
b = a[: n // 2]
c = a[n // 2 :]
for i in range(n // 2 - 1):
b[i] *= 2
for i in range(1, n // 2):
c[i] *= 2
m = sum(c) - sum(b)
print(m)
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s000399064 | Runtime Error | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | import itertools
import sys
H, W = [int(i) for i in input().split(" ")]
cross = [[0] * (H + W - 1) for _ in range(H + W - 1)]
for i, line in enumerate(sys.stdin):
for j, c in enumerate(line.strip()):
if c == "#":
cross[i + j][i - j + W - 1] = 1
across = [[0] + list(itertools.accumulate(xs)) for xs in cross]
r_cross = [[xs[i] for xs in cross] for i in range(H + W - 1)]
across2 = [[0] + list(itertools.accumulate(xs)) for xs in r_cross]
r = 0
for i in range(H + W - 1):
for j in range(H + W - 1):
if cross[i][j] != 1:
continue
for k in range(j + 1, H + W - 1):
if cross[i][k] == 1:
if i - (k - j) >= 0:
r += across[i - (k - j)][k + 1] - across[i - (k - j)][j]
if i + (k - j) < H + W - 1:
r += across[i + (k - j)][k + 1] - across[i + (k - j)][j]
for i in range(H + W - 1):
for j in range(H + W - 1):
if cross[j][i] != 1:
continue
for k in range(j + 1, H + W - 1):
if cross[k][i] == 1:
if i - (k - j) >= 0:
r += across2[i - (k - j)][k] - across2[i - (k - j)][j + 1]
if i + (k - j) < H + W - 1:
r += across2[i + (k - j)][k] - across2[i + (k - j)][j + 1]
print(r)
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s168487746 | Runtime Error | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
"""
tenka1-2018 E
"""
from itertools import product
from itertools import combinations
h, w = map(int, input().split())
slili = [list(input()) for i in range(h)]
coinsetli = [set() for i in range(h + w)]
for i, j in product(range(h), range(w)):
if slili[i][j] == "#":
coinsetli[i + j + 1].add(j - i)
coinacumdictli = [{} for i in range(h + w)]
for i in range(1, h + w):
tmp = 0
for j in range(-300, 301):
if j in coinsetli[i]:
tmp += 1
coinacumdictli[i][j] = tmp
ansdouble = 0
for i in range(1, h + w):
for x, y in combinations(coinsetli[i], 2):
j = abs(x - y)
x, y = (min(x, y), max(x, y))
if i - j >= 1:
ansdouble += (
coinacumdictli[i - j][y]
+ coinacumdictli[i - j][y - 1]
- coinacumdictli[i - j][x]
- coinacumdictli[i - j][x - 1]
)
if i + j <= h + w - 1:
ansdouble += (
coinacumdictli[i + j][y]
+ coinacumdictli[i + j][y - 1]
- coinacumdictli[i + j][x]
- coinacumdictli[i + j][x - 1]
)
# repeat after reversing along the vertical axis
for i in range(h):
slili[i].reverse()
coinsetli = [set() for i in range(h + w)]
for i, j in product(range(h), range(w)):
if slili[i][j] == "#":
coinsetli[i + j + 1].add(j - i)
coinacumdictli = [{} for i in range(h + w)]
for i in range(1, h + w):
tmp = 0
for j in range(-300, 301):
if j in coinsetli[i]:
tmp += 1
coinacumdictli[i][j] = tmp
for i in range(1, h + w):
for x, y in combinations(coinsetli[i], 2):
j = abs(x - y)
x, y = (min(x, y), max(x, y))
if i - j >= 1:
ansdouble += (
coinacumdictli[i - j][y]
+ coinacumdictli[i - j][y - 1]
- coinacumdictli[i - j][x]
- coinacumdictli[i - j][x - 1]
)
if i + j <= h + w - 1:
ansdouble += (
coinacumdictli[i + j][y]
+ coinacumdictli[i + j][y - 1]
- coinacumdictli[i + j][x]
- coinacumdictli[i + j][x - 1]
)
print(ansdouble // 2)
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s766669808 | Runtime Error | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | def distance(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
n = 0
H, W = input().split()
H = int(H)
W = int(W)
r = []
for i in range(H):
r.append(input().split())
stones = []
print(r)
for i in range(H):
for j in range(W):
if r[i][0][j] == "#":
stones.append([j, i])
for i in range(len(stones)):
for j in range(i + 1, len(stones)):
d = distance(stones[i], stones[j])
for k in range(j + 1, len(stones)):
if distance(stones[i], stones[k]) > d or distance(stones[j], stones[k]) > d:
continue
if distance(stones[i], stones[k]) == distance(stones[j], stones[k]) == d:
n += 1
print(stones[i], stones[j], stones[k])
print(n)
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s185436377 | Accepted | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | N, *a = map(int, open(0))
n = N // 2 - 1
a.sort()
print(
2 * sum(a[n + 2 :])
- 2 * sum(a[:n])
+ a[n + 1]
- a[n]
- N % 2 * min(a[~n] + a[n], 2 * a[n + 1])
)
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s358939342 | Wrong Answer | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | print(1)
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s491656769 | Runtime Error | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | try:
# raise ModuleNotFoundError
import numpy
def dprint(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)
dprint("debug mode")
except Exception:
def dprint(*args, **kwargs):
pass
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s728126957 | Runtime Error | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | N = int(input())
A = []
for _ in range(N):
A.append(int(input()))
A.sort()
B = []
for i in range(N):
if i==0 or i==N-1:
B[].append((-1)**i)
else:
B[i].append(((-1)**i)*2)
B.sort()
print(max(abs(sum([A[i]*B[i] for i in range(N)])),abs(sum([A[i]*B[N-1-i] for i in range(N)])))) | Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s631350657 | Wrong Answer | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | n = int(input())
l = [int(input()) for _ in range(n)]
l.sort()
if n % 2:
s = l[: (n - 1) // 2]
b = l[(n - 1) // 2 :]
t = sum(b) * 2 - sum(s) * 2 - sum(b[:2])
else:
s = l[: n // 2]
b = l[n // 2 :]
t = sum(b) * 2 - sum(s) * 2 - b[0] + s[-1]
print(t)
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s698303356 | Accepted | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | from itertools import permutations
N = int(input())
A = sorted(int(input()) for _ in range(N))
def helper(L):
s = abs(L[N // 2] - L[0])
for i in range((N + 1) // 2 - 1):
s += abs(L[-i - 1] - L[i])
s += abs(L[-i - 1] - L[i + 1])
if N % 2 == 1:
s -= abs(L[N // 2 + 1] - L[N // 2])
return s
print(max(helper(A), helper(A[::-1])))
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s680080228 | Accepted | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | n = int(input())
a = [int(input()) for _ in range(n)]
if n == 2:
print(abs(a[0] - a[1]))
elif n == 3:
print(
max(
abs(a[0] - a[1]) + abs(a[0] - a[2]),
abs(a[1] - a[2]) + abs(a[1] - a[0]),
abs(a[2] - a[1]) + abs(a[2] - a[0]),
)
)
else:
b = sorted(a)
ans = [0] * n
if n % 2 == 0:
for i in range(2, n - 1, 2):
ans[i] = b[(i // 2) - 1]
# print(i, ans[i])
for i in range(1, n - 1, 2):
ans[i] = b[-1 - ((i - 1) // 2)]
# print(i, ans[i])
ans[0] = b[n // 2 - 1]
ans[n - 1] = b[n // 2]
else:
ans[0] = b[n // 2]
if b[n // 2 + 1] + b[n // 2 - 1] >= 2 * b[n // 2]:
for i in range(2, n - 1, 2):
ans[i] = b[(i // 2) - 1]
for i in range(1, n - 1, 2):
ans[i] = b[-1 - ((i - 1) // 2)]
ans[n - 1] = b[n // 2 - 1]
# ans[n-2] = b[n // 2 + 1]
else:
for i in range(1, n - 1, 2):
ans[i] = b[((i - 1) // 2)]
for i in range(2, n - 1, 2):
ans[i] = b[-1 - ((i - 2) // 2)]
ans[n - 1] = b[n // 2 + 1]
# ans[n-2] = b[n // 2 - 1]
# print(ans)
print(sum([abs(ans[i] - ans[i + 1]) for i in range(n - 1)]))
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s216780561 | Accepted | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | N = int(input())
lis = [int(input()) for n in range(N)]
lis = sorted(lis)
half = len(lis) // 2
low = lis[:half]
high = lis[: half - 1 : -1]
def output(low_lis, high_lis):
ll, hl = len(low_lis), len(high_lis)
if ll > hl:
return calc(low_lis, high_lis)
return calc(high_lis, low_lis)
def calc(lis1, lis2):
left = lis1[0]
right = left
res = 0
try:
for n in range((len(lis1) + 1) // 2):
res += abs(left - lis1[2 * n])
res += abs(right - lis2[2 * n])
res += abs(lis1[2 * n + 1] - lis2[2 * n])
res += abs(lis2[2 * n + 1] - lis1[2 * n])
right = lis1[2 * n + 1]
left = lis2[2 * n + 1]
return res
except IndexError:
return res
res1 = output(low, high)
res2 = 0
if len(lis) % 2:
low = lis[: half + 1]
high = lis[:half:-1]
res2 = output(low, high)
print(max(res1, res2))
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s224993073 | Wrong Answer | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | def read():
N = int(input().strip())
A = []
for _ in range(N):
a = int(input().strip())
A.append(a)
return N, A
def solve(N, A):
A = sorted(A)
low = A[: N // 2]
high = A[N // 2 :] # 奇数ならlen(low) + 1
B = [0] * N
for i in range(len(high)):
B[i * 2] = high.pop()
for i in range(len(low)):
B[i * 2 + 1] = low.pop(0)
sub = [0] * N
for i in range(N):
sub[i] = abs(B[i] - B[(i - 1) % N])
return sum(sub[1 : N - 1]) + max(sub[0], sub[N - 1])
if __name__ == "__main__":
inputs = read()
print("%d" % solve(*inputs))
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s679479537 | Accepted | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | n = int(input())
l = [int(input()) for _ in range(n)]
l.sort()
m = sorted(
(-1) ** (i + 1) if i == 0 or i == n - 1 else 2 * ((-1) ** (i + 1)) for i in range(n)
)
f = lambda x, y: x * y
a = abs(sum(map(f, l, m)))
b = abs(sum(map(f, l[::-1], m)))
print(max(a, b))
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s800753637 | Wrong Answer | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | import sys
sys.setrecursionlimit(10**6)
def main():
n = int(input())
lst = []
for _ in range(n):
lst += [int(input())]
lst.sort()
ylst = lst[::-1]
mini = 10000000000
ans = 0
zlst = []
if n % 2 == 1:
zlst = [lst[0]]
for i in range(int((n - 1) / 2)):
if i % 2 == 0:
zlst = [ylst[i]] + zlst + [ylst[i + 1]]
else:
zlst = [lst[i]] + zlst + [lst[i + 1]]
for i in range(n - 1):
ans += abs(zlst[i + 1] - zlst[i])
print(ans)
else:
for i in range(int(n / 2)):
zlst += [lst[i], ylst[i]]
for i in range(n):
ans += abs(zlst[(i + 1) % n] - zlst[i])
mini = min(mini, abs(zlst[(i + 1) % n] - zlst[i]))
print(ans - mini)
return
main()
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the maximum possible sum of the absolute differences between the
adjacent elements after arranging the given integers in a row in any order you
like.
* * * | s631954117 | Accepted | p03223 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return map(int, stdin.readline().split())
def li_():
return map(lambda x: int(x) - 1, stdin.readline().split())
def lf():
return map(float, stdin.readline().split())
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
from collections import deque
n = ni()
a = []
for _ in range(n):
a.append(ni())
mx_cent = [ai for ai in a]
mn_cent = [ai for ai in a]
a.sort()
a = deque(a)
mx_cent = deque([ai for ai in a])
mn_cent = deque([ai for ai in a])
bmx = deque([mx_cent.pop()])
bmn = deque([mn_cent.popleft()])
cnt = 0
while len(mx_cent) > 1:
lf = 0
rt = 0
if cnt % 2 == 0:
lf = mx_cent.popleft()
rt = mx_cent.popleft()
else:
lf = mx_cent.pop()
rt = mx_cent.pop()
bmx.appendleft(lf)
bmx.append(rt)
if cnt % 2 == 0:
lf = mn_cent.pop()
rt = mn_cent.pop()
else:
lf = mn_cent.popleft()
rt = mn_cent.popleft()
bmn.appendleft(lf)
bmn.append(rt)
cnt += 1
if len(mx_cent) == 1:
last = mx_cent.pop()
if abs(bmx[0] - last) > abs(bmx[-1] - last):
bmx.appendleft(last)
else:
bmx.append(last)
last = mn_cent.pop()
if abs(bmn[0] - last) > abs(bmn[-1] - last):
bmn.appendleft(last)
else:
bmn.append(last)
diffmx, diffmn = 0, 0
for i in range(n - 1):
diffmx += abs(bmx[i + 1] - bmx[i])
diffmn += abs(bmn[i + 1] - bmn[i])
print(max(diffmx, diffmn))
| Statement
You are given N integers; the i-th of them is A_i. Find the maximum possible
sum of the absolute differences between the adjacent elements after arranging
these integers in a row in any order you like. | [{"input": "5\n 6\n 8\n 1\n 2\n 3", "output": "21\n \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n 3\n 1\n 4\n 1\n 5\n 9", "output": "25\n \n\n* * *"}, {"input": "3\n 5\n 5\n 1", "output": "8"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s935623856 | Wrong Answer | p03389 | Input is given from Standard Input in the following format:
A B C | li1 = [int(x) for x in input().split()]
if li1[0] == li1[1] and li1[1] == li1[2]:
print(0)
m1 = min(li1)
li1.remove(m1)
m2 = min(li1)
li1.remove(m2)
m3 = min(li1)
if (m2 - m1) % 2 == 0:
print(int((m2 - m1) / 2 + (m3 - m2)))
else:
print(int((m2 - m1) // 2 + (m3 - m2) + 2))
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s395627092 | Wrong Answer | p03389 | Input is given from Standard Input in the following format:
A B C | def same_integers():
li1 = [int(x) for x in input().split()]
if li1[0] == li1[1] and li1[1] == li1[2]:
return 0
m1 = min(li1)
li1.remove(m1)
m2 = min(li1)
li1.remove(m2)
m3 = min(li1)
if (m2 - m1) % 2 == 0:
return int((m2 - m1) / 2 + (m3 - m2))
else:
return int((m2 - m1) // 2 + (m3 - m2) + 2)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s780479717 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | A, B, C = sorted(map(int, input().split()))
a, b = divmod(2 * C - A - B, 2)
print(a + b * 2)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s779351008 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | a = list(map(int, input().split()))
count = 0
while a[0] != a[1] or a[1] != a[2]:
a.sort()
if a[1] != a[2]:
a[0] += 1
a[1] += 1
else:
a[0] += 2
count += 1
print(count)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s258780018 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | import collections
visited = set()
def is_goal(nums):
A, B, C = nums
return A == B == C
def bfs(nums):
q = collections.deque()
visited.add(nums)
q.append(nums + (0,))
if is_goal(nums):
return 0
while len(q) != 0:
n = q.popleft()
if is_goal(n[:3]):
return n[3]
for i in range(3):
new_n = list(n[:])
for j in range(3):
if i != j:
new_n[j] += 1
new_n[3] += 1
new_n = tuple(new_n)
if new_n[:3] not in visited:
visited.add(new_n[:3])
q.append(new_n)
for i in range(3):
new_n = list(n[:])
new_n[i] += 2
new_n[3] += 1
new_n = tuple(new_n)
if new_n[:3] not in visited:
visited.add(new_n[:3])
q.append(new_n)
return -1
A, B, C = map(int, input().split())
print(bfs((A, B, C)))
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s127876206 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | A, B, C = map(int, input().split())
M = max(A, B, C)
cnt = 0
dev_result = 0
for i in [A, B, C]:
cnt += (M - i) // 2
if (M - i) % 2 == 1:
dev_result += 1
if dev_result == 1:
print(cnt + 2)
elif dev_result == 2:
print(cnt + 1)
else:
print(cnt)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s408483326 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | # N = int(input())
lis = []
N = 1
for T in range(N):
c = list(map(int, input().split()))
maxi = max(c)
sum = 0
for i in c:
sum = sum + (maxi - i)
if sum % 2 == 0:
lis.append(sum // 2)
else:
lis.append((sum + 3) // 2)
for i in lis:
print(i)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s830075158 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | a, b, c = map(int, input().split())
l = sorted([a, b, c])
a, b, c = l[0], l[1], l[2]
if (c - a) % 2 == 0 and (c - b) % 2 == 0:
print((c - a) // 2 + (c - b) // 2)
elif (c - a) % 2 == 1 and (c - b) % 2 == 1:
a += 1
b += 1
print((c - a) // 2 + (c - b) // 2 + 1)
else:
if (c - a) % 2 == 1:
c += 1
b += 1
print((c - a) // 2 + (c - b) // 2 + 1)
else:
c += 1
a += 1
print((c - a) // 2 + (c - b) // 2 + 1)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s698765583 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | a = sorted(list(map(int, input().split())))
x = 0
i = (a[1] - a[0]) // 2
x += i
a[1] -= i * 2
a[2] -= i * 2
i = a[2] - a[1]
a[2] -= i
x += i
print(x + sum(a) - a[0] * 3)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s661728411 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | list = list(map(int, input().split()))
list.sort(reverse=True)
Even = ["Odd", "Odd", "Odd"]
m, n = 0, 0
for i in range(len(list)):
if list[i] % 2 == 0:
Even[i] = "Even"
if Even[0] == Even[1] and Even[0] == Even[2]:
m = 0
n = (2 * list[0] - list[1] - list[2]) / 2
elif Even[0] != Even[1] and Even[0] != Even[2]:
m = list[0] - list[1]
n = (list[1] - list[2]) / 2
else:
m = 1
n = (2 * list[0] - list[1] - list[2] + 1) / 2
print(int(m + n))
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s201004818 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | A = list(map(int, input().split()))
M = max(A)
S = sum(A)
M += M % 2 != S % 2
print((3 * M - S) // 2)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s262075091 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | n = sorted(list(map(int, input().split())))
n21 = n[2] - n[1]
n20 = n[2] - n[0]
print((n21 + n20) // 2 if (n21 + n20) % 2 == 0 else (n21 + n20) // 2 + 2)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s792847724 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | a, b, c = sorted(list(map(int, input().split())))
cnt = 0
while b < c:
a += 1
b += 1
cnt += 1
while a < c:
a += 2
cnt += 1
print(cnt if a == c else cnt + 1)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s539186991 | Runtime Error | p03389 | Input is given from Standard Input in the following format:
A B C | s=list(map(int,input().split()))
a=max(s)*3-sum(s)
if a%2==1
a+=3
print(a//2) | Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s236552775 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | ints = list(map(int, input().split()))
ints.sort()
a, b, c = ints
da = c - a
db = c - b
result = db
da -= db
result += da // 2
if da % 2 == 1:
result += 2
print(result)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s267021244 | Runtime Error | p03389 | Input is given from Standard Input in the following format:
A B C | in = [int(i) for i in input().split(' ')]
A,B,C = in[0],in[1],in[2]
if (A+B+C - max(A,B,C)) % 2 == 0:
print((3*max(A,B,C) - A - B - C)/2)
else:
print((3*max(A,B,C) - A - B - C - 1)/2) + 2 | Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s124145492 | Runtime Error | p03389 | Input is given from Standard Input in the following format:
A B C | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
_do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
_s<<"{";
for(It _it=_ita;_it!=_itb;_it++)
{
_s<<(_it==_ita?"":",")<<*_it;
}
_s<<"}";
return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
string scope_name;
chrono::high_resolution_clock::time_point start_time;
public:
Timer (string name) : scope_name(name) {
start_time = chrono::high_resolution_clock::now();
}
~Timer () {
auto stop_time = chrono::high_resolution_clock::now();
auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
double mlength = double(length) * 0.001;
debug(scope_name, mlength);
}
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN =
int a, b, c;
int ans = 0;
int mx = 0;
int dif = 0;
void fix (int x) {
ans += (mx-x)/2;
dif += (mx-x)%2;
}
/********** Good Luck :) **********/
int main () {
TIME(main);
IOS();
cin >> a >> b >> c;
mx = max({a, b, c});
fix(a);
fix(b);
fix(c);
if (dif == 2) {
ans++;
} else if (dif == 1) {
ans +=2;
}
cout << ans << endl;
return 0;
}
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s793951295 | Runtime Error | p03389 | Input is given from Standard Input in the following format:
A B C | N = int(input())
c = -1
s = 0
for i in range(N):
ai, bi = map(int, input().split())
s += ai
if ai > bi:
if c == -1:
c = bi
if bi < c:
c = bi
if c == -1:
print(0)
else:
print(s - c)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s316901040 | Wrong Answer | p03389 | Input is given from Standard Input in the following format:
A B C | s = list(input())
n = len(s)
a = [0] * n
MOD = 998244353
for i in range(n):
a[i] = ord(s[i]) - ord("a")
if max(a) == min(a):
print(1)
exit()
elif n == 3:
def solver(m):
x = m // 100
y = (m % 100) // 10
z = m % 10
if x != y:
c = (3 - x - y) % 3
temp = c * 110 + z
if temp not in ans:
ans.add(temp)
solver(temp)
if y != z:
c = (3 - y - z) % 3
temp = x * 100 + c * 11
if temp not in ans:
ans.add(temp)
solver(temp)
t = a[0] * 100 + a[1] * 10 + a[2]
ans = set()
ans.add(t)
solver(t)
print(len(ans))
exit()
elif n == 2:
print(2)
exit()
dp = [[0, 0, 0] for _ in range(3)]
dp[0][0] = 1
dp[1][1] = 1
dp[2][2] = 1
for i in range(n - 1):
T = [[0, 0, 0] for _ in range(3)]
T[0][0] = (dp[1][0] + dp[2][0]) % MOD
T[0][1] = (dp[1][1] + dp[2][1]) % MOD
T[0][2] = (dp[1][2] + dp[2][2]) % MOD
T[1][0] = (dp[0][2] + dp[2][2]) % MOD
T[1][1] = (dp[0][0] + dp[2][0]) % MOD
T[1][2] = (dp[0][1] + dp[2][1]) % MOD
T[2][0] = (dp[0][1] + dp[1][1]) % MOD
T[2][1] = (dp[0][2] + dp[1][2]) % MOD
T[2][2] = (dp[0][0] + dp[1][0]) % MOD
dp, T = T, dp
m = sum(a) % 3
ans = 3 ** (n - 1) - (dp[0][m] + dp[1][m] + dp[2][m])
check = 1
for i in range(n - 1):
if a[i] == a[i + 1]:
check = 0
break
ans += check
# print(dp, 2 ** (n-1))
print(ans % MOD)
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Print the minimum number of operations required to make A, B and C all equal.
* * * | s217555713 | Accepted | p03389 | Input is given from Standard Input in the following format:
A B C | def noofrupees(x, y, z):
if x == y and x == z:
return 0
elif x == y:
if x < z:
return z - x
else:
if x % 2 == 0 and z % 2 == 0:
return int((x - z) / 2)
elif x % 2 != 0 and z % 2 != 0:
return int((x - z) / 2)
else:
z = z - 1
return int((x - z) / 2) + 1
elif x == z:
if x < y:
return y - x
else:
if x % 2 == 0 and y % 2 == 0:
return int((x - y) / 2)
elif x % 2 != 0 and y % 2 != 0:
return int((x - y) / 2)
else:
y = y - 1
return int((x - y) / 2) + 1
elif y == z:
if y < x:
return x - y
else:
if y % 2 == 0 and x % 2 == 0:
return int((y - x) / 2)
elif y % 2 != 0 and x % 2 != 0:
return int((y - x) / 2)
else:
x = x - 1
return int((y - x) / 2) + 1
# t= int(input())
t = 1
for v in range(t):
x, y, z = map(int, input().split())
if x != y and x != z and y != z:
list1 = [x, y, z]
list1.sort()
s = list1[2] - list1[1]
list1[0] += s
list1[1] += s
print(s + noofrupees(list1[0], list1[1], list1[2]))
else:
print(noofrupees(x, y, z))
| Statement
You are given three integers A, B and C. Find the minimum number of operations
required to make A, B and C all equal by repeatedly performing the following
two kinds of operations in any order:
* Choose two among A, B and C, then increase both by 1.
* Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly
performing these operations. | [{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.