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 |
|---|---|---|---|---|---|---|---|
Print the correct choice.
* * * | s571050114 | Runtime Error | p02829 | Input is given from Standard Input in the following format:
A
B | A=map(int,input())
B=map(int,input())
if (A=1 and B=2)or(A=2 and B=1):
print(3)
if (A=2 and B=3)or(A=3 and B=2):
print(1)
else:
print(2) | Statement
Takahashi is solving quizzes. He has easily solved all but the last one.
The last quiz has three choices: 1, 2, and 3.
With his supernatural power, Takahashi has found out that the choices A and B
are both wrong.
Print the correct choice for this problem. | [{"input": "3\n 1", "output": "2\n \n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\n* * *"}, {"input": "1\n 2", "output": "3"}] |
Print the correct choice.
* * * | s536815976 | Runtime Error | p02829 | Input is given from Standard Input in the following format:
A
B | a = int(input())
b = int(input())
if (a not 3) and (b not 3):
print("3")
elif (a not 2) and (b not 2):
print("2")
else:
print("1") | Statement
Takahashi is solving quizzes. He has easily solved all but the last one.
The last quiz has three choices: 1, 2, and 3.
With his supernatural power, Takahashi has found out that the choices A and B
are both wrong.
Print the correct choice for this problem. | [{"input": "3\n 1", "output": "2\n \n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\n* * *"}, {"input": "1\n 2", "output": "3"}] |
Print the correct choice.
* * * | s612020076 | Runtime Error | p02829 | Input is given from Standard Input in the following format:
A
B | A = int(input())
B = int(input())
ans = 0
if A == 1 and B == 2:
ans = 3
elif A == 1 and B == 3:
ans = 2
elif A == 2 and B == 1:
ans = 3
elif A == 2 and B == 3:
ans = 1
elif A == 3 and B == 1:
ans = 2
elif A == 3 and B == 2:
elif = 1
print(ans) | Statement
Takahashi is solving quizzes. He has easily solved all but the last one.
The last quiz has three choices: 1, 2, and 3.
With his supernatural power, Takahashi has found out that the choices A and B
are both wrong.
Print the correct choice for this problem. | [{"input": "3\n 1", "output": "2\n \n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\n* * *"}, {"input": "1\n 2", "output": "3"}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s755683295 | Runtime Error | p02983 | Input is given from Standard Input in the following format:
L R | l, r = map(int, input().split())
flag = 0
for i in range(l, r+1):
if i % 2019 == 0:
flag = 1
break
if flag == 0:
a = (l % 2019) * ((l+1) % 2019)) % 2019
print(a)
elif flag == 1:
print(0)
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s226849067 | Wrong Answer | p02983 | Input is given from Standard Input in the following format:
L R | print(1)
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s509721927 | Wrong Answer | p02983 | Input is given from Standard Input in the following format:
L R | l, r = map(lambda s: int(s) % 2019, input().split())
print((0, (l * (l + 1)) % 2019)[l < r])
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s271995709 | Wrong Answer | p02983 | Input is given from Standard Input in the following format:
L R | l, r = map(int, input().split())
mod1 = []
mod2 = []
for i in range(l, r + 1):
mod1.append(i % 2019)
print(mod1)
for i in range(len(mod1) - 1):
for j in range(i + 1, len(mod1)):
mod2.append((mod1[i] * mod1[j]) % 2019)
print(mod2)
print(min(mod2))
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s848497975 | Wrong Answer | p02983 | Input is given from Standard Input in the following format:
L R | l, r = map(int, input().split())
dp = float("inf")
for i in range(2020):
for k in range(2020):
test = ((l + i) * (r + k)) % 2019
dp = min(dp, test)
print(dp)
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s933978342 | Wrong Answer | p02983 | Input is given from Standard Input in the following format:
L R | l = list(map(int, input().split()))
s = 2017 * 2018
for i in range(l[0], l[1]):
for j in range(i + 1, l[1] + 1):
if (i % 2019) * (j % 2019) <= s:
s = (i % 2019) * (j % 2019)
print(s)
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s765280260 | Accepted | p02983 | Input is given from Standard Input in the following format:
L R | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list(map(lambda x: int(x) - 1, stdin.readline().split()))
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# A
def A():
n, a, b = LI()
print(min(n * a, b))
return
# B
def B():
n, d = LI()
x = LIR(n)
a = list(itertools.combinations(range(n), 2))
ans = 0
for a1, a2 in a:
b = 0
for bi in range(d):
b += (x[a1][bi] - x[a2][bi]) ** 2
if float.is_integer(math.sqrt(b)):
ans += 1
print(ans)
return
# C
def C():
l, r = LI()
ans = 2018
if l // 2019 == r // 2019:
for i in range(l, r + 1):
for k in range(i + 1, r + 1):
ans = min(ans, (i * k) % 2019)
print(ans)
else:
print(0)
return
# D
def D():
n = II()
a = LI()
return
# E
def E():
return
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
C()
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s834916656 | Wrong Answer | p02983 | Input is given from Standard Input in the following format:
L R | p = m = 2019
a, b = [int(x) for x in input().split()]
a = a % p
b = b % p if b // p > 1 else b
for i in range(a, b):
for j in range(i + 1, b):
m = min(m, i * j % p)
print(m)
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s651949520 | Wrong Answer | p02983 | Input is given from Standard Input in the following format:
L R | # coding: utf-8
import sys
# import bisect
# import math
# import numpy as np
# from fractions import gcd
"""Template"""
class IP:
"""
入力を取得するクラス
"""
def __init__(self):
self.input = sys.stdin.readline
def I(self):
"""
1文字の取得に使います
:return: int
"""
return int(self.input())
def S(self):
"""
1文字の取得(str
:return: str
"""
return self.input()
def IL(self):
"""
1行を空白で区切りリストにします(int
:return: リスト
"""
return list(map(int, self.input().split()))
def SL(self):
"""
1行の文字列を空白区切りでリストにします
:return: リスト
"""
return list(map(str, self.input().split()))
def ILS(self, n):
"""
1列丸々取得します(int
:param n: 行数
:return: リスト
"""
return [int(self.input()) for _ in range(n)]
def SLS(self, n):
"""
1列丸々取得します(str
:param n: 行数
:return: リスト
"""
return [self.input() for _ in range(n)]
def SILS(self, n):
"""
Some Int LineS
横に複数、縦にも複数
:param n: 行数
:return: list
"""
return [self.IL() for _ in range(n)]
def SSLS(self, n):
"""
Some String LineS
:param n: 行数
:return: list
"""
return [self.SL() for _ in range(n)]
class Idea:
def __init__(self):
pass
def HF(self, p):
"""
Half enumeration
半分全列挙です
pの要素の和の組み合わせを作ります。
ソート、重複削除行います
:param p: list : 元となるリスト
:return: list : 組み合わせられた和のリスト
"""
return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))
def Bfs2(self, a):
"""
bit_full_search2
bit全探索の改良版
全探索させたら2進数のリストと10進数のリストを返す
:return: list2つ : 1個目 2進数(16桁) 2個目 10進数
"""
# 参考
# https://blog.rossywhite.com/2018/08/06/bit-search/
# https://atcoder.jp/contests/abc105/submissions/4088632
value = []
for i in range(1 << len(a)):
output = []
for j in range(len(a)):
if self.bit_o(i, j):
"""右からj+1番目のiが1かどうか判定"""
# output.append(a[j])
output.append(a[j])
value.append([format(i, "b").zfill(16), sum(output)])
value.sort(key=lambda x: x[1])
bin = [value[k][0] for k in range(len(value))]
val = [value[k][1] for k in range(len(value))]
return bin, val
def S(self, s, r=0, m=-1):
"""
ソート関係行います。色々な設定あります。
:param s: 元となるリスト
:param r: reversするかどうか 0=False 1=True
:param m: (2次元配列)何番目のインデックスのソートなのか
:return: None
"""
r = bool(r)
if m == -1:
s.sort(reverse=r)
else:
s.sort(reverse=r, key=lambda x: x[m])
def bit_n(self, a, b):
"""
bit探索で使います。0以上のときにTrue出します
自然数だからn
:param a: int
:param b: int
:return: bool
"""
return bool((a >> b & 1) > 0)
def bit_o(self, a, b):
"""
bit探索で使います。1のときにTrue出すよ
oneで1
:param a: int
:param b: int
:return: bool
"""
return bool(((a >> b) & 1) == 1)
def ceil(self, x, y):
"""
Round up
小数点切り上げ割り算
:param x: int
:param y: int
:return: int
"""
return -(-x // y)
def ave(self, a):
"""
平均を求めます
:param a: list
:return: int
"""
return sum(a) / len(a)
def gcd(self, x, y):
if y == 0:
return x
else:
return self.gcd(y, x % y)
def lcm(self, x, y):
return (x * y) // self.gcd(x, y)
"""ここからメインコード"""
def main():
# 1文字に省略
r, e = range, enumerate
ip = IP()
id = Idea()
"""この下から書いてね"""
l, r = ip.IL()
a = l % 2019
b = r % 2019
# print(a, b)
memo1 = id.ceil(l, 2019) * 2019
# print(memo1)
if memo1 <= r:
if memo1 + 2019 >= 2019:
print(0)
else:
print(2)
else:
memo2 = l // 2019 * 2019
memo3 = id.ceil(r, 2019) * 2019
# print(memo2, memo3)
if l - memo2 <= memo3 - r:
# print("koko")
print((l * (l + 1)) % 2019)
else:
print((r * (r - 1)) % 2019)
main()
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s880928471 | Runtime Error | p02983 | Input is given from Standard Input in the following format:
L R | x, y = map(int, input().split())
print([x, -1][x % y])
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s421369154 | Wrong Answer | p02983 | Input is given from Standard Input in the following format:
L R | print(0)
| Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and
j are chosen under the given condition.
* * * | s735252096 | Runtime Error | p02983 | Input is given from Standard Input in the following format:
L R | L, R = map(int, input().split(' '))
N = 2019
ans = 2019
for i in range(L, R):
for j in range(i + 1, R + 1):
mod = (i * j) % N
if ans > mod:
ans = mod
if ans = 0:
print(ans)
exit(0)
print(ans) | Statement
You are given two non-negative integers L and R. We will choose two integers i
and j such that L \leq i < j \leq R. Find the minimum possible value of (i
\times j) \mbox{ mod } 2019. | [{"input": "2020 2040", "output": "2\n \n\nWhen (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.\n\n* * *"}, {"input": "4 5", "output": "20\n \n\nWe have only one choice: (i, j) = (4, 5)."}] |
Print the number of pairs (i,\ j) (1 ≤ i < j ≤ N) such that the condition is
held.
* * * | s834976037 | Runtime Error | p03691 | Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M | import sys
from itertools import combinations
n, m = map(int, input().split())
survivors = {v: {v + 1} for v in range(n)}
for x, y in reversed(map(int, line.split()) for line in sys.stdin.readlines()):
for v, srv in survivors.copy().items():
if x in srv:
if y in srv:
del survivors[v]
else:
srv.add(y)
elif y in srv:
srv.add(x)
print(sum(su.isdisjoint(sv) for su, sv in combinations(survivors.values(), 2)))
| Statement
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the
following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 ≤ i < j ≤ N) such that the following
condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0. | [{"input": "3 1\n 1 2", "output": "2\n \n\n(i,\\ j) = (1,\\ 3), (2,\\ 3) satisfy the condition.\n\n* * *"}, {"input": "4 3\n 1 2\n 3 4\n 2 3", "output": "1\n \n\n(i,\\ j) = (1,\\ 4) satisfies the condition. Both turkeys 1 and 4 are alive if:\n\n * The first man eats turkey 2.\n * The second man eats turkey 3.\n * The third man does nothing.\n\n* * *"}, {"input": "3 2\n 1 2\n 1 2", "output": "0\n \n\n* * *"}, {"input": "10 10\n 8 9\n 2 8\n 4 6\n 4 9\n 7 8\n 2 8\n 1 8\n 3 4\n 3 4\n 2 7", "output": "5"}] |
Print the specified string: `YYMM`, `MMYY`, `AMBIGUOUS` or `NA`.
* * * | s744645116 | Wrong Answer | p03042 | Input is given from Standard Input in the following format:
S | import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
input_int = lambda: int(input())
input_ints = lambda: map(int, input().split())
input_ints_list = lambda: list(input_ints())
input_str = lambda: input()
input_strs = lambda: input().split()
input_lines = lambda n, input_func: [input_func() for _ in range(n)]
import importlib
import_module = lambda module_name: importlib.import_module(module_name)
init_array_1dim = lambda value, n: [value] * n # 1次元配列を生成
init_array_2dim = lambda value, n, m: [
init_array_1dim(value, n) for _ in range(m)
] # 2次元配列を生成
gcd_base = lambda value1, value2: import_module("fractions").gcd(
value1, value2
) # 最大公約数(2値)
gcd = lambda lst: import_module("functools").reduce(
gcd_base, lst
) # 最大公約数(リスト)
lcm_base = lambda value1, value2: (value1 * value2) // gcd_base(
value1, value2
) # 最小公倍数(2値)
lcm = lambda lst: import_module("functools").reduce(
lcm_base, lst, 1
) # 最小公倍数(リスト)
permutations = lambda lst, n: import_module("itertools").permutations(lst, n) # 順列
combinations = lambda lst, n: import_module("itertools").combinations(
lst, n
) # 組み合わせ
product = lambda lst1, lst2: import_module("itertools").product(
lst1, lst2
) # 二つのリストの直積
round = lambda value: round(value) # 四捨五入
ceil = lambda value: import_module("math").ceil(value) # 切り上げ
floor = lambda value: import_module("math").floor(value) # 切り捨て
# キュー
init_q = lambda lst: import_module("collections").deque(lst)
q_pop = lambda q: q.popleft() # 先頭から取り出し
q_push = lambda q, value: q.appendleft(value) # 先頭に追加(値)
q_pushlist = lambda q, lst: q.extendleft(lst) # 先頭に追加(リスト)
q_append = lambda q, value: q.append(value) # 末尾に追加(値)
q_appendlist = lambda q, lst: q.extend(lst) # 末尾に追加(リスト)
# プライオリティキュー
init_heap = lambda a: import_module("heapq").heapify(a)
heap_push = lambda a, v: import_module("heapq").heappush(a, v)
heap_pop = lambda a: import_module("heapq").heappop(a) # 最小値を取り出す
def solution():
# ここに実装
S = input_str()
month_1 = False
year_1 = False
if "01" <= S[:2] <= "12":
month_1 = True
if "01" <= S[:2] <= "19":
year_1 = True
month_2 = False
year_2 = False
if "01" <= S[2:] <= "12":
month_2 = True
if "01" <= S[2:] <= "19":
year_2 = True
if month_1 and month_2:
print("AMBIGUOUS")
return
if month_1 and year_2:
print("MMYY")
return
if month_2 and year_1:
print("YYMM")
return
print("NA")
if __name__ == "__main__":
solution()
| Statement
You have a digit sequence S of length 4. You are wondering which of the
following formats S is in:
* YYMM format: the last two digits of the year and the two-digit representation of the month (example: `01` for January), concatenated in this order
* MMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order
If S is valid in only YYMM format, print `YYMM`; if S is valid in only MMYY
format, print `MMYY`; if S is valid in both formats, print `AMBIGUOUS`; if S
is valid in neither format, print `NA`. | [{"input": "1905", "output": "YYMM\n \n\nMay XX19 is a valid date, but 19 is not valid as a month. Thus, this string is\nonly valid in YYMM format.\n\n* * *"}, {"input": "0112", "output": "AMBIGUOUS\n \n\nBoth December XX01 and January XX12 are valid dates. Thus, this string is\nvalid in both formats.\n\n* * *"}, {"input": "1700", "output": "NA\n \n\nNeither 0 nor 17 is valid as a month. Thus, this string is valid in neither\nformat."}] |
Print the specified string: `YYMM`, `MMYY`, `AMBIGUOUS` or `NA`.
* * * | s443122824 | Wrong Answer | p03042 | Input is given from Standard Input in the following format:
S | print("NA")
| Statement
You have a digit sequence S of length 4. You are wondering which of the
following formats S is in:
* YYMM format: the last two digits of the year and the two-digit representation of the month (example: `01` for January), concatenated in this order
* MMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order
If S is valid in only YYMM format, print `YYMM`; if S is valid in only MMYY
format, print `MMYY`; if S is valid in both formats, print `AMBIGUOUS`; if S
is valid in neither format, print `NA`. | [{"input": "1905", "output": "YYMM\n \n\nMay XX19 is a valid date, but 19 is not valid as a month. Thus, this string is\nonly valid in YYMM format.\n\n* * *"}, {"input": "0112", "output": "AMBIGUOUS\n \n\nBoth December XX01 and January XX12 are valid dates. Thus, this string is\nvalid in both formats.\n\n* * *"}, {"input": "1700", "output": "NA\n \n\nNeither 0 nor 17 is valid as a month. Thus, this string is valid in neither\nformat."}] |
Print the specified string: `YYMM`, `MMYY`, `AMBIGUOUS` or `NA`.
* * * | s787343476 | Wrong Answer | p03042 | Input is given from Standard Input in the following format:
S | a = input()
i = 0
n = []
while i < len(a):
n.append(a[i])
i += 1
pd = n[0] + n[1]
sd = n[2] + n[3]
pd = int(pd)
sd = int(sd)
if pd > 12:
if sd >= 1 and sd <= 12:
print("YYMM")
elif sd > 12:
print("NA")
elif sd < 1:
print("NA")
elif pd == 0:
if sd > 12:
print("NA")
if sd > 0 and sd <= 12:
print("YYMM")
elif pd <= 12:
if sd > 12:
print("MMYY")
elif sd == 0:
print("MMYY")
elif sd <= 12 and sd != 0:
print("AMBIGUOUS")
| Statement
You have a digit sequence S of length 4. You are wondering which of the
following formats S is in:
* YYMM format: the last two digits of the year and the two-digit representation of the month (example: `01` for January), concatenated in this order
* MMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order
If S is valid in only YYMM format, print `YYMM`; if S is valid in only MMYY
format, print `MMYY`; if S is valid in both formats, print `AMBIGUOUS`; if S
is valid in neither format, print `NA`. | [{"input": "1905", "output": "YYMM\n \n\nMay XX19 is a valid date, but 19 is not valid as a month. Thus, this string is\nonly valid in YYMM format.\n\n* * *"}, {"input": "0112", "output": "AMBIGUOUS\n \n\nBoth December XX01 and January XX12 are valid dates. Thus, this string is\nvalid in both formats.\n\n* * *"}, {"input": "1700", "output": "NA\n \n\nNeither 0 nor 17 is valid as a month. Thus, this string is valid in neither\nformat."}] |
Print the number of different strings that x can be after Snuke finishes doing
operations, modulo (10^9+7).
* * * | s558095127 | Runtime Error | p02653 | Input is given from Standard Input in the following format:
N A B | S = list(input())
N = int(input())
"""
ordの位置
#z = 122
#a = 97
左の文字からNで'a'に出来るかを確認
aに出来るならaにして使った分をNから引く
繰り返して行き一番最後にあまりをすべて使う"""
for i, s in enumerate(S):
if ord(s) - 97 > 0 and 122 - ord(s) < N:
S[i] = "a"
N -= 123 - ord(s)
else:
S[i] = chr((ord(S[i]) + N) % 122)
print("".join(S))
| Statement
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing
operations. This count can be enormous, so compute it modulo (10^9+7). | [{"input": "4 2 3", "output": "11\n \n\nFor example, x can be `0011` or `1111` in the end, but cannot be `0110`.\n\n* * *"}, {"input": "10 7 2", "output": "533\n \n\n* * *"}, {"input": "1000 100 10", "output": "828178524"}] |
Print the maximum possible sum of the chosen elements.
* * * | s227631931 | Runtime Error | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | n = int(input())
s = list(map(int, input().split()))
ans = -1000000000000000
dp = [{} for _ in range(n)]
dp[0][1] = s[0]
dp[1][1] = s[1]
dp[2][1] = s[2]
for i in range(n):
for x in dp[i].keys():
y = dp[i][x]
if x == n // 2:
ans = max(ans, y)
else:
if (n - (i + 2) + 1) // 2 >= n // 2 - (x + 1) and i + 2 <= n - 1:
if x + 1 in dp[i + 2].keys():
dp[i + 2][x + 1] = max(dp[i + 2][x + 1], dp[i][x] + s[i + 2])
else:
dp[i + 2][x + 1] = dp[i][x] + s[i + 2]
if (n - (i + 3) + 1) // 2 >= n // 2 - (x + 1) and i + 3 <= n - 1:
if x + 1 in dp[i + 3].keys():
dp[i + 3][x + 1] = max(dp[i + 3][x + 1], dp[i][x] + s[i + 3])
else:
dp[i + 3][x + 1] = dp[i][x] + s[i + 3]
if (n - (i + 4) + 1) // 2 >= n // 2 - (x + 1) and i + 4 <= n - 1:
if x + 1 in dp[i + 4].keys():
dp[i + 4][x + 1] = max(dp[i + 4][x + 1], dp[i][x] + s[i + 4])
else:
dp[i + 4][x + 1] = dp[i][x] + s[i + 4]
print(ans)
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s794590306 | Wrong Answer | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | k = int(input())
l = list(map(int, input().split()))
odd = 0
even = 0
ct = 0
c = 0
le = []
lo = []
odd_mn = -1000000001
odd_mn1 = -1000000001
even_mn = -1000000001
even_mn = -1000000001
for i in range(k):
if i % 2 == 0:
if l[i] >= 0:
c += 1
even += l[i]
if l[i] > even_mn and l[i] < 0:
even_mn = l[i]
ind = i
le.append(l[i])
else:
if l[i] >= 0:
odd += l[i]
ct += 1
if l[i] > odd_mn and l[i] < 0:
odd_mn = l[i]
ino = i
lo.append(l[i])
if c == 1:
even += even_mn
if ct == 1:
odd += odd_mn
if c == 0:
even += even_mn
even_mn = -1000000001
for i in range(len(le)):
if l[i] > even_mn and ind != i // 2:
even_mn = l[i]
even += even_mn
if ct == 0:
odd += odd_mn
odd_mn = -1000000001
for i in range(len(lo)):
if l[i] > odd_mn and ino != (i // 2 + 1):
odd_mn = l[i]
odd += odd_mn
if odd > even:
print(odd)
else:
print(even)
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s237963990 | Runtime Error | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | n = int(input())
a = int(input())
if n % 2 == 0: # n/2が偶数の場合
a1 = list([a[::2]])
a2 = list([a[1::2]])
print(max(sum(a1), sum(a2)))
else:
print("奇数は無理なんじゃ")
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s554699776 | Wrong Answer | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | s = [input() for i in range(2)]
s[1] = s[1].split(" ")
n = 0
j = 0
for k in s[1]:
m = int(k)
if m % 2 == 0:
j += m
if m % 2 != 0:
n += m
if n < j:
print(j)
else:
print(n)
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s717940883 | Runtime Error | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | n = int(input())
a = [int(e) for e in input().split()]
ans = 0
for i in range(n / 2):
ans += a(-1 - (i * 2))
print(ans)
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s518278625 | Wrong Answer | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | N = int(input())
A = list(map(int, input().split()))
out = 0
if N % 2 == 0:
for i in range(N // 2):
out += max(A[2 * i], A[2 * i + 1])
print(out)
else:
X = []
Y = []
for i in range(N):
if i % 2 == 0:
X.append(A[i])
else:
Y.append(A[i])
Z = []
W = []
for i in range(N // 2):
Z.append(X[i] - Y[i])
W.append(X[i + 1] - Y[i])
P = [0] * (N // 2 + 1)
Q = [0] * (N // 2 + 1)
max1 = 0
max2 = 0
sum1 = 0
sum2 = 0
for i in range(N // 2):
sum1 += Z[i]
if max1 < sum1:
max1 = sum1
sum2 += W[N // 2 - 1 - i]
if max2 < sum2:
max2 = sum2
P[i + 1] = max1
Q[-1 * i - 1 - 1] = max2
R = []
for i in range(N // 2 + 1):
R.append(P[i] + Q[i])
# print(Z)
# print(W)
# print(P)
# print(Q)
# print(sum(Y))
print(sum(Y) + max(max(R), 0))
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s518310941 | Wrong Answer | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | def main():
# from sys import stdin, setrecursionlimit
# setrecursionlimit(10**9)
# r = input()
# n = int(input())
# a, b = map(int, input().split())
# s, y = input().split()
# a = input().split()
# a = list(map(int, input().split()))
# a = [list(input().split()) for i in range(n)]
# a = [int(input()) for i in range(n)]
# a = [list(map(int, input().split())) for i in range(n)]
# a = [int(s) - 1 for s in input().split()]
# l=[int(input()) for _ in range(int(input()))]
# res = 0
n = int(input())
a = sorted(list(map(int, input().split())))
if n % 2 == 0:
print(sum(a[1::2]))
else:
print(sum(a[::2]))
if __name__ == "__main__":
main()
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s372489985 | Accepted | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
a.append(-float("inf"))
n += 1
if n == 3:
print(max(a))
exit()
p0 = a[0]
z0 = -float("inf")
z1 = a[1]
y0 = a[0] + a[2]
y1 = -float("inf")
y2 = a[2]
x0 = -float("inf")
x1 = max(p0, z1) + a[3]
x2 = -float("inf")
for i in range(4, n - 1):
w0 = y0 + a[i]
w1 = max(y1, z0) + a[i]
w2 = max(y2, z1, p0) + a[i]
p0 = z0
z0 = y0
z1 = y1
y0 = x0
y1 = x1
y2 = x2
x0 = w0
x1 = w1
x2 = w2
w0 = y0 + a[n - 1]
w1 = max(y1, z0) + a[n - 1]
w2 = max(y2, z1, p0) + a[n - 1]
print(max(y0, x1, w2))
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s852940638 | Runtime Error | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | n = input()
List = list(map(int, input().split()))
def find(List):
if len(List) == 1:
return int(List[0])
elif len(List) == 3:
if List[0] >= List[1]:
if List[0] >= List[2]:
return int(List[0])
else:
if List[1] >= List[2]:
return int(List[1])
else:
return int(List[2])
else:
if List[1] >= List[2]:
return int(List[1])
else:
if List[0] >= List[2]:
return int(List[0])
else:
return int(List[2])
else:
if len(List) == 2:
if List[0] >= List[1]:
return int(List[0])
else:
return int(List[1])
else:
if len(List) % 2 == 0:
List2 = []
List3 = []
for i in range(0, len(List) - 2):
List2.append(List[i])
for i in range(0, len(List) - 3):
List3.append(List[i])
sub1 = int(int(List[len(List) - 1]) + find(List2))
sub2 = int(int(List[len(List) - 2]) + find(List3))
if sub1 >= sub2:
return sub1
else:
return sub2
else:
List2 = []
List3 = []
for i in range(0, len(List) - 2):
List2.append(List[i])
for i in range(0, len(List) - 3):
List3.append(List[i])
sub1 = int(int(List[len(List)] - 1) + find(List2))
sub2 = int(int(List[len(List) - 2]) + find(List3))
sub3 = 0
for i in range(0, len(List) // 2):
sub3 += List[2 * i]
if sub1 >= sub2:
if sub1 >= sub3:
return sub1
else:
if sub3 >= sub2:
return sub3
else:
return sub2
else:
if sub2 >= sub3:
return sub2
else:
if sub3 >= sub1:
return sub3
else:
return sub1
print(find(List))
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s307473761 | Wrong Answer | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | Nin = int(input())
guki = Nin % 2
N = Nin // 2
A = list(map(int, input().split()))
summost = sum(A[1::2])
if guki == 0:
for a in range(0, N):
if summost < sum(A[: 2 * a : 2] + A[2 * a + 1 :: 2]):
summost = sum(A[: 2 * a : 2] + A[2 * a + 1 :: 2])
else:
for a in range(0, N):
for b in range(a, N):
if summost < sum(
A[: 2 * a : 2] + A[2 * a + 1 : 2 * b + 1 : 2] + A[2 * b + 2 :: 2]
):
summost = sum(
A[: 2 * a : 2] + A[2 * a + 1 : 2 * b + 1 : 2] + A[2 * b + 2 :: 2]
)
print(summost)
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s564628756 | Wrong Answer | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | N = int(input())
A = list(map(int, input().split()))
inf = 10**10
if N % 2 == 0:
dp = [[[0] * 2 for __ in range(2)] for _ in range(N)]
dp[0][0][0] = A[0]
dp[0][0][1] = -inf
dp[0][1][0] = -inf
dp[0][1][1] = 0
dp[1][0][0] = -inf
dp[1][0][1] = -inf
dp[1][1][0] = A[1]
dp[1][1][1] = -inf
for i in range(2, N):
dp[i][0][0] = dp[i - 2][0][0] + A[i]
dp[i][0][1] = -inf
dp[i][1][0] = max(dp[i - 1][1][1], dp[i - 2][1][0]) + A[i]
dp[i][1][1] = dp[i - 2][0][0]
print(max(dp[-1][1]))
else:
dp = [[[0] * 2 for __ in range(3)] for _ in range(N)]
dp[0][0][0] = A[0]
dp[0][0][1] = -inf
dp[0][1][0] = -inf
dp[0][1][1] = 0
dp[0][2][0] = -inf
dp[0][2][1] = -inf
dp[1][0][0] = -inf
dp[1][0][1] = -inf
dp[1][1][0] = A[1]
dp[1][1][1] = -inf
dp[1][2][0] = -inf
dp[1][2][1] = 0
for i in range(2, N):
dp[i][0][0] = dp[i - 2][0][0] + A[i]
dp[i][0][1] = -inf
dp[i][1][0] = max(dp[i - 1][1][1], dp[i - 2][1][0]) + A[i]
dp[i][1][1] = dp[i - 2][0][0]
dp[i][2][0] = max(dp[i - 1][2][1], dp[i - 2][2][0]) + A[i]
dp[i][2][1] = max(dp[i - 1][1][1], dp[i - 2][1][0])
print(max(dp[-1][2]))
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print the maximum possible sum of the chosen elements.
* * * | s283577302 | Accepted | p02716 | Input is given from Standard Input in the following format:
N
A_1 ... A_N | N = int(input())
A = [0] + list(map(int, input().split(" ")))
dp_list = [{0, 0}, {0: 0, 1: A[1]}, {0: 0, 1: A[1] if A[1] > A[2] else A[2]}]
for i in range(3, N + 1):
b = (i - 1) // 2
f = (i + 1) // 2
dp_list.append({})
for j in range(b, f + 1):
if j in dp_list[i - 1]:
dp_list[i][j] = (
dp_list[i - 2][j - 1] + A[i]
if dp_list[i - 2][j - 1] + A[i] > dp_list[i - 1][j]
else dp_list[i - 1][j]
)
else:
dp_list[i][j] = dp_list[i - 2][j - 1] + A[i]
print(dp_list[-1][N // 2])
| Statement
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from
this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x. | [{"input": "6\n 1 2 3 4 5 6", "output": "12\n \n\nChoosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.\n\n* * *"}, {"input": "5\n -1000 -100 -10 0 10", "output": "0\n \n\nChoosing -10 and 10 makes the sum 0, which is the maximum possible value.\n\n* * *"}, {"input": "10\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nWatch out for overflow.\n\n* * *"}, {"input": "27\n 18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49", "output": "295"}] |
Print `Yes` if the template image B is contained in the image A. Print `No`
otherwise.
* * * | s944984518 | Runtime Error | p03804 | The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M | n, m = map(int, input().split())
a = []
for i in range(n):
a.append(input())
b = []
for i in range(m):
b.append(input())
def func(base, target):
for i in range(n-m+1):
check = base[i:i+m]
for j in range(n-m+1):
check2 = [line[j:j+m] for line in check]
if check2 == target:
return print('Yes')
return print('No')
func(a,b)
| Statement
You are given an image A composed of N rows and N columns of pixels, and a
template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a
square of size 1×1.
Also, the given images are binary images, and the color of each pixel is
either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a
white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row
and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row
and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only
parallel shifts can be applied to the images. | [{"input": "3 2\n #.#\n .#.\n #.#\n #.\n .#", "output": "Yes\n \n\nThe template image B is identical to the upper-left 2 \u00d7 2 subimage and the\nlower-right 2 \u00d7 2 subimage of A. Thus, the output should be `Yes`.\n\n* * *"}, {"input": "4 1\n ....\n ....\n ....\n ....\n #", "output": "No\n \n\nThe template image B, composed of a black pixel, is not contained in the image\nA composed of white pixels."}] |
Print `Yes` if the template image B is contained in the image A. Print `No`
otherwise.
* * * | s195393147 | Runtime Error | p03804 | The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M | n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
a.append(input())
for j in range(m):
b.append(input())n,m=map(int,input().split())
a=[]
b=[]
l=0
k=0
temp=[]
res=False
for i in range(n):
a.append(input())
for j in range(m):
b.append(input())
#print(a)
while k<=n-m+1:
while l+m<=n:
for o in range(m):
temp.append(a[o+k][l:l+m])
print(o,m,k)
l+=1
print(temp)
temp=[]
k+=1 | Statement
You are given an image A composed of N rows and N columns of pixels, and a
template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a
square of size 1×1.
Also, the given images are binary images, and the color of each pixel is
either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a
white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row
and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row
and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only
parallel shifts can be applied to the images. | [{"input": "3 2\n #.#\n .#.\n #.#\n #.\n .#", "output": "Yes\n \n\nThe template image B is identical to the upper-left 2 \u00d7 2 subimage and the\nlower-right 2 \u00d7 2 subimage of A. Thus, the output should be `Yes`.\n\n* * *"}, {"input": "4 1\n ....\n ....\n ....\n ....\n #", "output": "No\n \n\nThe template image B, composed of a black pixel, is not contained in the image\nA composed of white pixels."}] |
Print `Yes` if the template image B is contained in the image A. Print `No`
otherwise.
* * * | s195289111 | Runtime Error | p03804 | The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M | N, M = [int(x) for x in input().split()]
A = [None]*N
for i in range(N):
A[i] = input()
B = [None]*M
for i in range(M):
B[i] = input()
def check():
for x in range(N-M+1):
for y in range(N-M+1):
if all(all(A[r+x][c+y] == B[r][c] for c in range(M)) for r range(M))
return "Yes"
return "No"
print(check())
| Statement
You are given an image A composed of N rows and N columns of pixels, and a
template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a
square of size 1×1.
Also, the given images are binary images, and the color of each pixel is
either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a
white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row
and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row
and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only
parallel shifts can be applied to the images. | [{"input": "3 2\n #.#\n .#.\n #.#\n #.\n .#", "output": "Yes\n \n\nThe template image B is identical to the upper-left 2 \u00d7 2 subimage and the\nlower-right 2 \u00d7 2 subimage of A. Thus, the output should be `Yes`.\n\n* * *"}, {"input": "4 1\n ....\n ....\n ....\n ....\n #", "output": "No\n \n\nThe template image B, composed of a black pixel, is not contained in the image\nA composed of white pixels."}] |
Print `Yes` if the template image B is contained in the image A. Print `No`
otherwise.
* * * | s080032001 | Runtime Error | p03804 | The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M | x
| Statement
You are given an image A composed of N rows and N columns of pixels, and a
template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a
square of size 1×1.
Also, the given images are binary images, and the color of each pixel is
either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a
white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row
and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row
and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only
parallel shifts can be applied to the images. | [{"input": "3 2\n #.#\n .#.\n #.#\n #.\n .#", "output": "Yes\n \n\nThe template image B is identical to the upper-left 2 \u00d7 2 subimage and the\nlower-right 2 \u00d7 2 subimage of A. Thus, the output should be `Yes`.\n\n* * *"}, {"input": "4 1\n ....\n ....\n ....\n ....\n #", "output": "No\n \n\nThe template image B, composed of a black pixel, is not contained in the image\nA composed of white pixels."}] |
Print `Yes` if the template image B is contained in the image A. Print `No`
otherwise.
* * * | s093275757 | Runtime Error | p03804 | The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M | N,M=map(int, input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
for i in range(N):
if B[0] in A[i]:
if all(B[j] in A[i+j] for j in range(1,min(M,N-i)):
print('Yes')
exit(0)
print('No')
| Statement
You are given an image A composed of N rows and N columns of pixels, and a
template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a
square of size 1×1.
Also, the given images are binary images, and the color of each pixel is
either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a
white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row
and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row
and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only
parallel shifts can be applied to the images. | [{"input": "3 2\n #.#\n .#.\n #.#\n #.\n .#", "output": "Yes\n \n\nThe template image B is identical to the upper-left 2 \u00d7 2 subimage and the\nlower-right 2 \u00d7 2 subimage of A. Thus, the output should be `Yes`.\n\n* * *"}, {"input": "4 1\n ....\n ....\n ....\n ....\n #", "output": "No\n \n\nThe template image B, composed of a black pixel, is not contained in the image\nA composed of white pixels."}] |
For each getSum operation, print the sum in a line. | s884557689 | Runtime Error | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | a = list(map(int, input().split()))
b = []
ss = 1
f = 0
for i in range(a[0]):
k = int(input())
ss *= k
b.append(ss)
if k == 0:
print(a[0])
f = 1
break
k = 0
ss = 0
if f == 0:
for i in range(a[0]):
for j in range(a[0] - i):
k = b[a[0] - 1 - j] / b[i]
if k <= a[1]:
if a[0] - j - i >= ss:
ss = a[0] - i - j
print(ss)
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s827206961 | Runtime Error | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | import math, sys
# ??°????????????????????§????¨????????????¨???????????°??????????????????????§????
class SegmentTree:
def __init__(self, n):
self.TreeRange = pow(2, math.ceil(math.log2(n)))
self.List = [0] * (2 * self.TreeRange - 1)
def add(self, i, x):
i += self.TreeRange - 1
self.List[i] += x
while i > 0:
i = (i - 1) // 2
self.List[i] += x
def getsum(self, s, t, i=0, left=0, right=float("inf")):
# ??¢?´¢????±?????????????????????§????????°0????????????
if right <= s or t <= left:
return 0
# ??¢?´¢????±?????????????????????§????????°??????????????????????????????
elif s <= left <= right <= t:
return self.List[i]
# ??¢?´¢????±????????????????????????????????????°????????????????????°
else:
l = self.getsum(s, t, i * 2 + 1, left, (left + right) // 2)
r = self.getsum(s, t, i * 2 + 2, (left + right) // 2, right)
return l + r
_input = sys.stdin.readlines()
n, q = map(int, _input[0].split())
qlist = map(lambda x: x.split(), _input[1:])
ST = SegmentTree(n)
for q in qlist:
cmd, x, y = map(int, q)
if cmd == 0:
ST.add(x, y)
elif cmd == 1:
print(ST.getsum(x, y + 1, right=ST.TreeRange))
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s942347616 | Wrong Answer | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | import math
import functools
class SegmentTree:
def __init__(self, a: list, default: int, op):
real_size = len(a)
self.elem_size = 1 << math.ceil(math.log2(real_size))
self.tree_size = 2 * self.elem_size + 1
self.tree = (
[default] * (self.elem_size - 1)
+ a
+ [default] * (self.elem_size - real_size)
)
self.operation = op
def get_range_index(self, x, y, k=0, l_end=0, r_end=None):
if r_end is None:
r_end = self.elem_size
if l_end == x and y == r_end - 1:
return [k]
elif not l_end <= x <= y < r_end:
return []
mid = (l_end + r_end) // 2
left_y = y if y < mid - 1 else mid - 1
right_x = x if x > mid else mid
left = self.get_range_index(x, left_y, 2 * k + 1, l_end, mid)
right = self.get_range_index(right_x, y, 2 * k + 2, mid, r_end)
return left + right
def get_value(self, x, y):
tree = self.tree
index_list = self.get_range_index(x, y)
op = self.operation
return functools.reduce(op, (tree[n] for n in index_list))
def update_tree(self, i: int):
op = self.operation
k = self.elem_size - 1 + 1
tree = self.tree
while k > 0:
k = (k - 1) // 2
left, right = tree[2 * k + 1], tree[2 * k + 2]
tree[k] = op(left, right)
def set_value(self, i: int, value: int, op: str):
k = self.elem_size - 1 + i
if op == "=":
self.tree[k] = value
elif op == "+":
self.tree[k] += value
self.update_tree(i)
n, q = map(int, input().split())
rsq = SegmentTree([0] * n, 0, lambda x, y: x + y)
ans = []
for _ in [0] * q:
c, x, y = map(int, input().split())
if c == 0:
rsq.set_value(x - 1, y - 1, "+")
else:
ans.append(rsq.get_value(x, y))
print("\n".join([str(n) for n in ans]))
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s573634091 | Accepted | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | class RSQ(object):
INIT = 0
def __init__(self, num) -> None:
n = 1
while n <= num:
n = n * 2
self.n = n
self.val = [self.INIT] * (2 * n - 1)
@staticmethod
def merge(a: int, b: int) -> int:
return a + b
def update(self, k: int, x: int) -> None:
k = k + self.n - 1
self.val[k] += x
while k:
k = (k - 1) // 2
self.val[k] = self.merge(self.val[k * 2 + 1], self.val[k * 2 + 2])
def dfs(self, beg: int, end: int, k: int, l: int, r: int) -> int:
if end <= l or r <= beg:
return self.INIT
if beg <= l and r <= end:
return self.val[k]
vl = self.dfs(beg, end, k * 2 + 1, l, (l + r) // 2)
vr = self.dfs(beg, end, k * 2 + 2, (l + r) // 2, r)
return self.merge(vl, vr)
def query(self, beg: int, end: int) -> int:
return self.dfs(beg, end, 0, 0, self.n)
if __name__ == "__main__":
n, q = map(lambda x: int(x), input().split())
rmq = RSQ(n)
for _ in range(q):
com, x, y = map(lambda x: int(x), input().split())
if 0 == com:
rmq.update(x, y)
else:
print(rmq.query(x, y + 1))
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s412075901 | Accepted | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | class RSQ:
def __init__(self, n_):
self.n_ = n_
self.n = 1
while self.n < n_:
self.n *= 2
self.st = [0] * (2 * self.n - 1)
def update(self, k, x):
k += self.n - 1
self.st[k] += x
while k > 0:
k = (k - 1) // 2
self.st[k] = self.st[2 * k + 1] + self.st[2 * k + 2]
def search(self, a, b, k, l, r):
if r <= a or b <= l:
return 0
if a <= l and r <= b:
return self.st[k]
L = self.search(a, b, k * 2 + 1, l, (l + r) // 2)
R = self.search(a, b, k * 2 + 2, (l + r) // 2, r)
return L + R
def query(self, a, b):
return self.search(a, b, 0, 0, self.n)
def main():
n, q = map(int, input().split())
ST = RSQ(n)
for _ in range(q):
a, b, c = map(int, input().split())
if a == 0:
ST.update(b - 1, c)
else:
print(ST.query(b - 1, c))
if __name__ == "__main__":
main()
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s187060962 | Accepted | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | class SegTree:
"""Segment Tree:
Data structure to answer queries on segments of a sequence.
"""
def __init__(self, n, init_num, func):
"""Create a segment tree.
:param n: Size
:type n: int or float (number)
:param init_num: Initialization number
:type init_num: int or float (number)
:param func: Function to use
:type func: function
"""
self.func = func
self.init_num = init_num
self.size = 2 ** (len(bin(n - 1)) - 2) * 2 - 1
self.tree = [init_num for i in range(self.size)]
def data(self):
"""Return data."""
return self.tree[self.size // 2 :]
def update(self, i, x, update_func):
"""Update the i-th data by update_func.
example:
a[i]<-update_func(a[i],x)
"""
i = self.size // 2 + i
self.tree[i] = update_func(self.tree[i], x)
while 1:
i = (i - 1) // 2
self.tree[i] = self.func(self.tree[i * 2 + 1], self.tree[i * 2 + 2])
if i <= 0:
break
def _check(self, s, t, l, r, _p=0):
if s <= l and r <= t:
return self.tree[_p]
elif r < s or t < l:
return self.init_num
else:
return self.func(
self._check(s, t, l, l + (r - l) // 2, _p * 2 + 1),
self._check(s, t, l + (r - l) // 2 + 1, r, _p * 2 + 2),
)
def find(self, s, t):
"""Answer queries on [s,t]segment"""
return self._check(s, t, 0, self.size // 2)
n, q = map(int, input().split())
st = SegTree(n, 0, lambda x, y: x + y)
for i in range(q):
c, x, y = map(int, input().split())
if c:
print(st.find(x - 1, y - 1))
else:
st.update(x - 1, y, lambda x, y: x + y)
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s938384307 | Accepted | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | class TemplateTree:
def __init__(self, iterable):
self.iter_size = self.get_size(iterable)
self.size = self.iter_size * 2 - 1
self.value = [None] * self.size
for i, v in enumerate(iterable):
self.value[self.iter_size + i - 1] = v
self.set_value(0)
self.range = [None] * self.size
self.set_range(0, 0, self.iter_size - 1)
def get_size(self, iterable):
ret = 1
x = len(iterable)
while ret < x:
ret *= 2
return ret
def set_range(self, x, left, right):
self.range[x] = (left, right)
if left != right:
self.set_range(x * 2 + 1, left, (right + left) // 2)
self.set_range(x * 2 + 2, (right + left) // 2 + 1, right)
def set_value(self, x):
if x >= self.iter_size - 1:
return self.value[x]
a = self.set_value(x * 2 + 1)
b = self.set_value(x * 2 + 2)
if a == None and b == None:
self.value[x] = None
elif a == None:
self.value[x] = b
elif b == None:
self.value[x] = a
else:
self.value[x] = a + b
return self.value[x]
def update(self, i, x):
target = self.iter_size + i - 1
while target >= 0:
self.value[target] += x
target = (target - 1) // 2
def query(self, x, left, right):
x_left, x_right = self.range[x]
if right < x_left or x_right < left:
return 0
if left <= x_left and x_right <= right:
return self.value[x]
return self.query(x * 2 + 1, left, right) + self.query(x * 2 + 2, left, right)
def print_tree(self):
print(self.value)
print(self.range)
n, q = map(int, input().split())
tree = TemplateTree([0] * n)
for _ in range(q):
c, x, y = map(int, input().split())
if c == 0:
tree.update(x - 1, y)
else:
print(tree.query(0, x - 1, y - 1))
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s140810950 | Accepted | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | class SegTree:
"""
内部実装1-indexed.
set_valやfoldには0-indexedでアクセス.
2べきに直さなくてよい.
Range Sum Query.
X_unit 0 X_f sum
"""
from operator import add
X_unit = 0
X_f = add
def __init__(self, N):
self.N = N
self.X = [self.X_unit] * (N + N)
def build(self, seq):
for i, x in enumerate(seq, self.N):
self.X[i] = x
for i in range(self.N - 1, 0, -1):
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
def set_val(self, i, x):
i += self.N
self.X[i] += x
while i > 1:
i >>= 1
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
def fold(self, L, R):
L += self.N
R += self.N
vL = self.X_unit
vR = self.X_unit
while L < R:
if L & 1:
vL = self.X_f(vL, self.X[L])
L += 1
if R & 1:
R -= 1
vR = self.X_f(self.X[R], vR)
L >>= 1
R >>= 1
return self.X_f(vL, vR)
def main():
N, Q = (int(i) for i in input().split())
seg = SegTree(N)
for _ in range(Q):
com, x, y = (int(i) for i in input().split())
if com == 0:
seg.set_val(x - 1, y)
else:
print(seg.fold(x - 1, y))
if __name__ == "__main__":
main()
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s839861162 | Accepted | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 5
0 1 1
0 2 2
0 3 3
1 1 2
1 2 2
output:
3
2
"""
import sys
class BinaryIndexedTree(object):
__slots__ = ("length", "dat")
def __init__(self, n):
"""
Init a BIT with update and find for range sum queries.
"""
self.length = int(n)
self.dat = [0] * (self.length + 1)
# sum(A[1] ... A[i])
def __init_sum(self, i):
_sum = 0
while i > 0:
_sum += self.dat[i]
i -= i & (-i)
return _sum
def get_sum(self, s, t):
return self.__init_sum(t) - self.__init_sum(s - 1)
# A[i] += x
def get_add(self, i, x):
while i <= self.length:
self.dat[i] += x
i += i & (-i)
return None
def action(cmd_list):
case = BinaryIndexedTree(n_num)
for query in cmd_list:
cmd, ele_1, ele_2 = map(int, query)
if cmd == 0:
case.get_add(ele_1, ele_2)
elif cmd == 1:
res = case.get_sum(ele_1, ele_2)
print(res)
return case
if __name__ == "__main__":
_input = sys.stdin.readlines()
n_num, q_num = map(int, _input[0].split())
q_list = map(lambda x: x.split(), _input[1:])
ans = action(q_list)
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
For each getSum operation, print the sum in a line. | s425053148 | Accepted | p02346 | n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, q queries are given where com represents the type of
queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi). | # operator.add(a, b)
# operator.mul(a, b)
"""
https://komiyam.hatenadiary.org/entry/20131202/1385992406
大雑把に言って、平衡二分探索木からinsert,delete,split,mergeなどができないよう制限したのがsegment treeで、
segment treeの区間[L,R)に対するクエリをL=0に制限したのがbinary indexed treeだと見なすことができます。
"""
class SegmentTree:
"""
update, get を提供するSegmentTree
Attributes
----------
__n : int
葉の数。2 ^ i - 1
__dot :
Segment function
__e: int
単位元
__node: list
Segment Tree
"""
def __init__(self, A, dot, e):
"""
Parameters
----------
A : list
対象の配列
dot :
Segment function
e : int
単位元
"""
n = 2 ** (len(A) - 1).bit_length()
self.__n = n
self.__dot = dot
self.__e = e
self.__node = [e] * (2 * n)
for i in range(len(A)):
self.__node[i + n] = A[i]
for i in range(n - 1, 0, -1):
self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
def update(self, i, c):
i += self.__n
node = self.__node
node[i] = c
while i > 1:
i //= 2
node[i] = self.__dot(node[2 * i], node[2 * i + 1])
def get(self, l, r):
vl, vr = self.__e, self.__e
l += self.__n
r += self.__n
while l < r:
if l & 1:
vl = self.__dot(vl, self.__node[l])
l += 1
l //= 2
if r & 1:
r -= 1
vr = self.__dot(vr, self.__node[r])
r //= 2
return self.__dot(vl, vr)
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
def AOJ_DSL_2_A():
n, q = map(int, input().split())
e = (1 << 31) - 1
A = [e] * n
seg = SegmentTree(A, min, e)
for i in range(q):
t, x, y = map(int, input().split())
if t == 0:
seg.update(x, y)
else:
print(seg.get(x, y + 1))
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B
def AOJ_DSL_2_B():
from operator import add
import sys
n, q = map(int, input().split())
e = 0
A = [e] * n
seg = SegmentTree(A, add, e)
query = sys.stdin.readlines()
for i in range(q):
t, x, y = map(int, query[i].split())
x -= 1
if t == 0:
A[x] += y
seg.update(x, A[x])
else:
y -= 1
print(seg.get(x, y + 1))
def ABC125_C():
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
seg = SegmentTree(A, gcd, 0)
ans = 0
for i in range(N):
ans = max(ans, gcd(seg.get(0, i), seg.get(i + 1, N)))
print(ans)
# AOJ_DSL_2_A()
AOJ_DSL_2_B()
# ABC125_C()
| Range Sum Query
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the
following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0. | [{"input": "3 5\n 0 1 1\n 0 2 2\n 0 3 3\n 1 1 2\n 1 2 2", "output": "3\n 2"}] |
Print the maximum number of cubes that can be removed.
* * * | s465479291 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | S = list(map(int, list(input())))
print(2 * min(sum(S), len(S) - sum(S)))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s652252098 | Runtime Error | p03107 | Input is given from Standard Input in the following format:
S | n = int(input())
input_list = list(map(int, input().split()))
ans_list = input_list[::-2] + input_list[n % 2 :: 2]
print(*ans_list)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s092025362 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | l = [int(s) for s in list(input())]
n0 = l.count(0)
n1 = l.count(1)
print(len(l) - abs(n1 - n0))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s861374658 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | S = [int(c) for c in input()]
zeros = S.count(0)
ones = S.count(1)
print(2 * min(zeros, ones))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s644892159 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | S = [int(_) for _ in list(input())]
print(len(S) - abs(2 * sum(S) - len(S)))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s467529835 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | S = [int(i) for i in input().split()[0]]
print(2 * min(S.count(0), S.count(1)))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s986056009 | Wrong Answer | p03107 | Input is given from Standard Input in the following format:
S | S = input()
lenS = len(S)
ls = []
ls.append(S[0])
for i in range(1, lenS):
if len(ls) == 0:
ls.append(S[0])
continue
tmp = ls.pop(-1)
if tmp == S[i]:
ls.append(tmp)
ls.append(S[0])
print(lenS - len(ls))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s966799588 | Runtime Error | p03107 | Input is given from Standard Input in the following format:
S | n_list = list(input())
n_len_o = len(n_list)
# print(n_list)
a = 0
while 1:
flag = "ng"
n_len = len(n_list)
for i in range(a, n_len - 1):
if n_list[i] != n_list[i + 1]:
n_list.pop(i, i + 1)
if a != 0:
a = i - 1
flag = "ok"
break
if flag == "ng":
break
print(n_len_o - len(n_list))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s962236953 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/3
Solved on 2019/3/3
@author: shinjisu
"""
# ABC 120
# import math
def getInt():
return int(input())
def getIntList():
return [int(x) for x in input().split()]
def zeros(n):
return [0] * n
def getIntLines(n):
return [int(input()) for i in range(n)]
def getIntMat(n):
mat = []
for i in range(n):
mat.append(getIntList())
return mat
def zeros2(n, m):
return [zeros(m)] * n
ALPHABET = [chr(i + ord("a")) for i in range(26)]
DIGIT = [chr(i + ord("0")) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**12
def dmp(x, cmt=""):
global debug
if debug:
if cmt != "":
print(cmt, ": ", end="")
print(x)
return x
def prob_B():
A, B, K = getIntList()
dmp((A, B, K))
count = 0
i = 1
while count < K:
if A % i == 0 and B % i == 0:
count += 1
if count == K:
break
i += 1
return i
def prob_C():
S = input()
red = 0
blue = 0
for cube in S:
if cube == "0":
red += 1
else:
blue += 1
dmp((red, blue))
return min(red, blue) * 2
debug = False # True False
ans = prob_C()
print(ans)
# for row in ans:
# print(row)
def prob_D():
N = getInt()
A = getIntList()
dmp((N, A))
return 123
def prob_A():
A, B, C = getIntList()
dmp((A, B, C))
count = min(B // A, C)
return count
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s824017384 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | s = list(map(str, input()))
n0 = s.count("0")
n1 = s.count("1")
print(min(n0, n1) * 2)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s049964366 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | bs = list(input())
h = {}
h["1"] = 0
h["0"] = 0
for b in bs:
h[b] += 1
print(min([h["1"], h["0"]]) * 2)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s176491426 | Wrong Answer | p03107 | Input is given from Standard Input in the following format:
S | l = list(map(str, input()))
print(2 * (min(l.count(0), l.count(1))))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s650064443 | Wrong Answer | p03107 | Input is given from Standard Input in the following format:
S | S = input()
flg = 1
ans = S
while flg == 1:
flg = 0
for i in range(len(ans) - 1):
if ans[i] == ans[i + 1]:
ans = ans[:i] + ans[i + 2 :]
flg = 1
break
print(len(S) - len(ans))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s628275076 | Wrong Answer | p03107 | Input is given from Standard Input in the following format:
S | # -*- coding: utf-8 -*-
# 入力された文字列
string = input()
# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)
# 削除した文字数
del_count = 0
# 削除があった場合True
del_flg = True
# 削除文字がなくなるまでループする
while del_flg:
del_flg = False
#
for idx in range(max):
if idx == max or idx > max:
break
# 照合対象の文字を切り出す
target = string[idx : idx + 2]
if target == "01" or target == "10":
# 削除文字に一致した場合、元の文字列からそれを削除しカウントを進め、
# 削除フラグを立てる
string = string.replace(string[idx : idx + 2], "")
del_count += 2
max -= 2
del_flg = True
print(del_count)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s640313963 | Runtime Error | p03107 | Input is given from Standard Input in the following format:
S | in_str = input()
# input_list = list(map(int,in_str.split()))
in_str = "0b" + in_str
# print(in_str)
# print(int(in_str, 0))
int_in = int(in_str, 0)
div = 0
while True:
int_in = int(int_in / 2)
if int_in == 1:
break
div += 1
print(div)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s035903001 | Runtime Error | p03107 | Input is given from Standard Input in the following format:
S | # https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = map(int,input().split()) | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
# import math
# import numpy as np
# import copy
# from collections import defaultdict, Counter
# from itertools import product
# from bisect import bisect_left, bisect_right
def inpl():
return list(map(int, input().split()))
S = list(input())
N = len(S)
while True:
flag = False
for i in range(1, len(S) - 2):
l = S[i - 1]
mid = S[i : i + 2]
r = S[i + 2]
if mid == ["0", "1"] or mid == ["1", "0"]:
if (l == "0" and r == "1") or (l == "1" and r == "0"):
del S[i : i + 2]
i += 2
flag = True
if i >= len(N) - 3:
break
if flag:
continue
nN = len(S)
for i in range(0, len(S) - 1):
mid = S[i : i + 2]
if mid == ["0", "1"] or mid == ["1", "0"]:
del S[i : i + 2]
i += 2
if i >= len(nN) - 2:
break
break
print(N - len(S))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s840233222 | Wrong Answer | p03107 | Input is given from Standard Input in the following format:
S | a = [i for i in input().split()]
print(a)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s239680347 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | x = str(input())
print(min(x.count("0"), x.count("1")) * 2)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s989739241 | Wrong Answer | p03107 | Input is given from Standard Input in the following format:
S | s = input().count(min("0", "1"))
print(s * 2)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s506912563 | Runtime Error | p03107 | Input is given from Standard Input in the following format:
S | s = str(input())
n = s.size()
cntz = 0
cnto = 0
for i in range(n):
if s[i] == "0":
cntz += 1
elif s[i] == "1":
cnto += 1
print(min(cnto, cntz))
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s015059261 | Wrong Answer | p03107 | Input is given from Standard Input in the following format:
S | S = input()
prev_len = len(S)
while S.find("01") != -1 or S.find("10") != -1:
S = S.strip("01")
S = S.strip("10")
curr_len = len(S)
print(prev_len - curr_len)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the maximum number of cubes that can be removed.
* * * | s876983668 | Accepted | p03107 | Input is given from Standard Input in the following format:
S | n = input()
s = len(n)
if s % 2 == 0:
l0 = n[: s // 2].count("0")
l1 = s // 2 - l0
r0 = n[s // 2 :].count("0")
r1 = s // 2 - r0
print(min(l0, r1) * 2 + min(l1, r0) * 2)
if s % 2 == 1:
l0 = n[: s // 2].count("0")
l1 = s // 2 - l0
r0 = n[s // 2 + 1 :].count("0")
r1 = s // 2 - r0
tmp = min(l0, r1) * 2 + min(l1, r0) * 2
if n[s // 2] == "0":
if r1 - l0 > 0 or r0 - l1 > 0:
tmp += 2
else:
if l0 - r1 > 0 or l1 - r0 > 0:
tmp += 2
print(tmp)
| Statement
There are N cubes stacked vertically on a desk.
You are given a string S of length N. The color of the i-th cube from the
bottom is red if the i-th character in S is `0`, and blue if that character is
`1`.
You can perform the following operation any number of times: choose a red cube
and a blue cube that are adjacent, and remove them. Here, the cubes that were
stacked on the removed cubes will fall down onto the object below them.
At most how many cubes can be removed? | [{"input": "0011", "output": "4\n \n\nAll four cubes can be removed, by performing the operation as follows:\n\n * Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n * Remove the first and second cubes from the bottom.\n\n* * *"}, {"input": "11011010001011", "output": "12\n \n\n* * *"}, {"input": "0", "output": "0"}] |
Print the number of different altars that Ringo can build.
* * * | s030001334 | Accepted | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | import sys
sys.setrecursionlimit(4100000)
import math
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
# from collections import defaultdict
# d = defaultdict(list)
# from itertools import combinations
# comb = combinations(range(N), 2)
# 累積和
from itertools import accumulate
# _list = list(accumulate(a_list)
def C(x, ub):
return x < ub
def resolve():
# S = [x for x in sys.stdin.readline().split()][0] # 文字列 一つ
N = [int(x) for x in sys.stdin.readline().split()][0] # int 一つ
# N, D = [int(x) for x in sys.stdin.readline().split()] # 複数int
a_list = [int(x) for x in sys.stdin.readline().split()] # 複数int
b_list = [int(x) for x in sys.stdin.readline().split()] # 複数int
c_list = [int(x) for x in sys.stdin.readline().split()] # 複数int
# grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)] # 文字列grid
# v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
# grid = [[int(x) for x in sys.stdin.readline().split()]
# for _ in range(N)] # int grid
logger.debug("{}".format([]))
a_list = sorted(a_list, reverse=True)
b_list = sorted(b_list, reverse=True)
c_list = sorted(c_list, reverse=True)
total_count = 0
i_b_upper = -1
i_a_upper = -1
b_count_list = None
for c in c_list:
if b_list[-1] >= c or a_list[-1] >= c:
break
i_b_lower = N
while i_b_lower - i_b_upper > 1:
i_b_middle = (i_b_lower + i_b_upper) // 2
if C(b_list[i_b_middle], c):
i_b_lower = i_b_middle
else:
i_b_upper = i_b_middle
if b_count_list is None:
b_count_list = [0 for _ in range(N)]
for i in range(i_b_lower, N):
b = b_list[i]
if a_list[-1] >= b:
break
i_a_lower = N
while i_a_lower - i_a_upper > 1:
i_a_middle = (i_a_lower + i_a_upper) // 2
if C(a_list[i_a_middle], b):
i_a_lower = i_a_middle
else:
i_a_upper = i_a_middle
b_count_list[i] = N - i_a_lower
total_count += N - i_a_lower
b_count_list = reversed(b_count_list)
b_count_list = list(reversed(list(accumulate(b_count_list))))
else:
total_count += b_count_list[i_b_lower]
print(total_count)
if __name__ == "__main__":
resolve()
# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2
1 5
2 4
3 6"""
output = """3"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """3
1 1 1
2 2 2
3 3 3"""
output = """27"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288"""
output = """87"""
self.assertIO(input, output)
if __name__ == "__main__":
unittest.main()
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s007582987 | Accepted | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | N = int(input())
size = [list(sorted(map(int, input().split()))) for i in range(3)]
dp = [[1] * (N + 1), [0] * (N + 1), [0] * (N + 1)]
dp[0][0] = 0
for i in range(1, 3):
pos = 1
for j in range(1, N + 1):
dp[i][j] += dp[i][j - 1]
for k in range(pos, N + 1):
if size[i][j - 1] <= size[i - 1][k - 1]:
break
dp[i][j] += dp[i - 1][k]
pos += 1
print(sum(dp[2]))
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s693696843 | Wrong Answer | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | # encoding: utf-8
N = int(input())
ABC = [list(map(int, input().split())) for i in range(3)]
memo = [[None] * N for i in range(3)] # row 0 is dummy ?
def stack(height, base, base_idx):
if height == 3:
return 1
elif memo[height][base_idx] != None:
return memo[height][base_idx]
ret = 0
for i, width in enumerate(ABC[2 - height]):
if width < base:
ret += stack(height + 1, width, i)
if memo[height][base_idx] == None:
memo[height][base_idx] = ret
return ret
print(stack(0, 10**5, 0))
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s829753477 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | def sup(A, j):
if A[0] >= j:
return 0
l = 0
r = len(A) - 1
while True:
i = (l+r) // 2
if i == len(A) - 1 and A[i] < j:
return len(A)
elif A[i]<j and A[i+1]>=j:
return i+1
else:
if A[i] >= j:
r = i-1
else: # A[i+1] < j
l = i+1
def inf(A, j):
if A[-1] <= j:
return 0
l = 0
r = len(A) - 1
while True:
i = (l+r) // 2
if i == 0 and A[i]>j:
return len(A)
elif A[i]>j and A[i-1]<=j:
return len(A)-i
else:
if A[i] <= j:
l = i+1
else: # A[i-1] > j
r = i-1
N = int(input())
[A, B, C] = [sorted([int(i) for i in input().split()]) for j in range(3)]
ans = 0
for j in B:
ans += sup(A, j) * inf(C, j)
print(ans) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s951696076 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
def binary_search(lst, value, high):
if high:
value += 0.5
else:
value -= 0.5
l = 0
r = N - 1
while l <= r:
mid = (l + r) // 2
if lst[mid] < value:
l = mid + 1
elif lst[mid] > value:
r = mid - 1
if high:
return l
else:
return r
def main():
ans = 0
for middle in B:
lower = binary_search(A, middle, False) + 1
higher = N - binary_search(C, middle, True)
ans += lower * higher
print(ans)
if __name__ == "__main__":
main() | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s916312823 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | =int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
small=0
large=0
for i in range(N):
for k in range(small,N):
if A[k]>=B[i]:
small=k
break
else: small=N
for k in range(large,N):
if C[k]>B[i]:
large=k
break
else: large=N
ans+=small*(N-large)
print(ans) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s363314136 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | def sup(A, j):
if A[0] >= j:
return 0
l = 0
r = len(A) - 1
while True:
i = (l+r) // 2
if i == len(A) - 1 and A[i] < j:
return len(A)
elif A[i]<j and A[i+1]>=j:
return i+1
else:
if A[i] >= j:
r = i-1
else: # A[i+1] < j
l = i+1
def inf(A, j):
if A[-1] <= j:
return 0
l = 0
r = len(A) - 1
while True:
i = (l+r) // 2
if i == 0 and A[i]>j:
return len(A)
elif A[i]>j and A[i-1]<=j:
return len(A)-i
else:
if A[i] <= j:
l = i+1
else: # A[i-1] > j
r = i-1
N = int(input())
[A, B, C] = [sorted([int(i) for i in input().split()]) for j in range(3)]
ans = 0
for j in B:
ans += sup(A, j) * inf(C, j)
print(ans) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s004606223 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
#リストをソート
a=sorted(a)
b=sorted(b)
c=sorted(c)
#二分探索(x以上の最小値index) !同じ物は一個下げる
def lower_bound(arr,x):
l=0
r=len(arr)-1#数列arrの最後尾のインデックス
while l<=r:
mid=(l+r)//2#中央値検索
if x==arr[mid]:#ちょうど中央値に存在したとき
return mid+1
elif x<arr[mid]:#xが左側の配列に存在するとき
r=mid-1
else:#xが右側の配列に存在するとき
l=mid+1
#print(mid,r,l)
return r+1
#二分探索(x以下の最大値)
def upper_bound(arr,x):
l=0
r=len(arr)-1#数列arrの最後尾のインデックス
while l<=r:
mid=(l+r)//2#中央値検索
if x==arr[mid]:#ちょうど中央値に存在したとき
return mid-1
elif x<arr[mid]:#xが左側の配列に存在するとき
r=mid-1
else:#xが右側の配列に存在するとき
l=mid+1
#print(mid,r,l)
return r
#個数をカウント
count=0
for i in range(n):
if min(a)>=b[i] or max(c)<=b[i]:
count=0
elif:
a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
count+=a_count*(len(c)-c_count+1)
#print(upper_bound(a,b[i]),lower_bound(c,b[i]))
#print(a_count,len(c),c_count,len(c)-c_count+1)
#print(count)
print(count)
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s172572818 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | (defun lower-bound (predicate &optional (ok 0) (ng (expt 10 10)))
(if (<= (abs (- ng ok)) 1)
ok
(let ((mid (floor (+ ng ok) 2)))
(if (funcall predicate mid)
(lower-bound predicate mid ng)
(lower-bound predicate ok mid)))))
(defun smaller-p (xs index b-size)
(< (aref xs index) b-size))
(defun bigger-p (xs index b-size)
(> (aref xs index) b-size))
(defun solve (a b c &optional (res 0))
(declare (type (array fixnum) a b c)
(type integer res))
(declare (optimize (speed 3) (safety 0)))
(the integer
(dotimes (j (length b) res)
(incf res (* (lower-bound #'(lambda (x)
(smaller-p a x (aref b j)))
0
(length a))
(lower-bound #'(lambda (x)
(bigger-p c x (aref b j)))
0
(length c)))))))
(defparameter *inf* (1+ (expt 10 9)))
(locally
(declare (inline sort))
(let* ((n (read))
(a (make-array (1+ n) :element-type 'fixnum))
(b (make-array n :element-type 'fixnum))
(c (make-array (1+ n) :element-type 'fixnum)))
(declare (type fixnum n))
(setf (aref a (1- (length a))) 0)
(setf (aref c (1- (length c))) *inf*)
(dotimes (i n)
(setf (aref a i) (read)))
(dotimes (i n)
(setf (aref b i) (read)))
(dotimes (i n)
(setf (aref c i) (read)))
(sort a #'<)
(sort c #'>)
(princ (solve a b c))
(fresh-line)))
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s945803114 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | def lower_elements(A, b):
lower_bound = -1
upper_bound = len(A)
while upper_bound - lower_bound > 1: # ア
middle = (lower_bound + upper_bound) // 2
if A[middle] < b: # イ
lower_bound = middle
else:
upper_bound = middle
return lower_bound + 1 # ウ upper_boundでも可
def upper_elements(C, b):
lower_bound = -1
upper_bound = len(C)
while upper_bound - lower_bound > 1: # ア
middle = (lower_bound + upper_bound) // 2
if C[middle] <= b:
lower_bound = middle
else:
upper_bound = middle
return len(C) - upper_bound
def answer(N: int, A: list, B: list, C: list):
assert N == len(A) == len(B) == len(C)
A.sort()
B.sort()
C.sort()
count = 0
for b in B:
count += lower_elements(A, b) * upper_elements(C, b)
return count
def snuke_festival():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
print(str(answer(N, A, B, C)) + '¥n')
if __name__ == '__main__': | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s432464033 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
#リストをソート
a=sorted(a)
b=sorted(b)
c=sorted(c)
#二分探索(x以上の最小値index) !同じ値の時はindex+1をする
def lower_bound(arr,x):
l=0
r=len(arr)-1#数列arrの最後尾のインデックス
while l<=r:
mid=(l+r)//2#中央値検索
if x==arr[mid]:#ちょうど中央値に存在したとき
return mid+1
elif x<arr[mid]:#xが左側の配列に存在するとき
r=mid-1
else:#xが右側の配列に存在するとき
l=mid+1
#print(mid,r,l)
if x>arr[-1]:
return -1
else:
return r+1
#二分探索(x以下の最大値) !同じ値の時はindex-1をする
def upper_bound(arr,x):
l=0
r=len(arr)-1#数列arrの最後尾のインデックス
while l<=r:
mid=(l+r)//2#中央値検索
if x==arr[mid]:#ちょうど中央値に存在したとき
return mid-1
elif x<arr[mid]:#xが左側の配列に存在するとき
r=mid-1
else:#xが右側の配列に存在するとき
l=mid+1
#print(mid,r,l)
if x<arr[0]:
return -1
else:
return r
#個数をカウント
count=0
for i in range(n):
a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
if a_count=-1 or c_count=-1:
count=0
else:
count+=a_count*(len(c)-c_count+1)
#print(upper_bound(a,b[i]),lower_bound(c,b[i]))
#print(a_count,len(c),c_count,len(c)-c_count+1)
#print(count)
print(count)
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s873478163 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | N = int(input())
A = list(sorted(map(int, input().split())))
B = list(sorted(map(int, input().split()))
C = list(sorted(map(int, input().split())))
import bisect
upper_condition = [bisect.bisect_left(A, b) for b in B]
lower_condition = [N - bisect.bisect_right(C, b) for b in B]
print(sum(map(lambda x: x[0]*x[1], zip(upper_condition, lower_condition)))) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s591668008 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
num = 0
#a.sort
#b.sort
#c.sort
for i in range(n):
for j in range(n):
if a[i] < b[i]:
for k in range(n):
b[j] < c[k]:
num += 1
print(num) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s188016307 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | #参考
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
a.sort()
b.sort()
c.sort()
for j in range(n):
ans += bisect.bisect_left(a,b[j])*(n-bisect.bisect_right(c,b[j]))
print(ans) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s708353814 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split
a.sort()
b.sort()
c.sort()
from bisect import bisect_left,bisect_right
ans = 0
for i in b:
count_a = bisect_right(a,i)
count_c = n - bisect_right(c,i)
ans += count_a * count_c
print(ans) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s098061687 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | import bisect
input()
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])
ans=0
for b in B:
ans+=bisect.bisect_left(A,b)*bisect.bisect_right(C,b
print(ans) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s156555284 | Wrong Answer | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | n = int(input())
print(int(n**0.5) ** 2)
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s822687904 | Wrong Answer | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | # わからなかった
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s448421218 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]res = 0
cnt_a = 0
cnt_c = 0
for b in B:
for ca in range(cnt_a, N):
if A[ca] >= b:
cnt_a = ca
break
if ca == N-1:
if A[ca] < b:
ca = N
cnt_a = N
break
for cc in range(cnt_c, N):
if C[cc] > b:
cnt_c = cc
break
if cc == N-1:
if b > C[cc]:
cc = N
cnt_c = N
break
res += (N - cc) * ca
print(res) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s505938620 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
sum = 0
for i in range(0,N):
a = A[i]
for j in range(1,N):
b = B[j]
c_min = b-a+1
c_max = a+b-1
l = bisect.bisect_left(C,c_min,lo = j+1)
if l! = N:
r = bisect.bisect_right(C,c_max,lo = j+1)
if r:
r = r-1
if r >= l:
sum += r-l+1
print(sum) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s497003167 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
dp_b = [0] * n
j = 0
for i in range(n):
while j < n:
if B[i] >= C[j]:
dp_b[i] = j
break
j += 1
if j == n:
dp_b[i] = n
for i in range(1, n):
dp_b[i] = dp_b[i] + dp_b[i-1]
ans = 0
j = 0
for i in range
while j < n:
if A[i] >= B[j]:
if j == 0:
break
else:
ans += B[j-1]
break
j += 1
if j == n:
ans += B[n-1]
print(ans) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s346427570 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
count = 0
Ai = -1
Ci = -1
for i in range(N):
if Ai < N - 1:
while A[Ai + 1] < B[i]:
Ai += 1
if Ai == N - 1:
break
if Ci < N - 1:
while C[Ci + 1] <= B[i]:
Ci += 1
if Ci == N - 1:
break
count += (Ai + 1) * (N - (Ci + 1))
return count
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s681704221 | Runtime Error | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
def lower(n,l):
left=-1
right=len(l)
while right>left+1:
mid=left+right
mid=mid//2
if n>l[mid]:
left=mid
elif n<l[mid]:
right=mid
return left+1
def upper(n,l):
def lower(n,l):
left=-1
right=len(l)
while right>left+1:
mid=left+right
mid=mid//2
if n>l[mid]:
left=mid
elif n<l[mid]:
right=mid
return len(l)-right
c=0
for i in lb:
c+=lower(i,la)*upper(i,lb)
print(c) | Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s987039474 | Accepted | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = SR()
return l
mod = 1000000007
# A
def A():
s = S()
t = S()
if s + t == t[::-1] + s[::-1]:
print("YES")
else:
print("NO")
# B
def B():
n = I()
for i in range(int(n**0.5) + 2)[::-1]:
if i * i <= n:
print(i * i)
quit()
# C
def C():
n = I()
a = LI()
b = LI()
c = LI()
q = [0 for i in range(n)]
ans = 0
a.sort()
b.sort()
c.sort()
for i in range(n):
j = bisect.bisect_left(a, b[i])
q[i] = j
for i in range(n - 1):
q[i + 1] += q[i]
q.insert(0, 0)
for i in range(n):
j = bisect.bisect_left(b, c[i])
ans += q[j]
print(ans)
# D
def D():
return
# E
def E():
return
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
C()
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
Print the number of different altars that Ringo can build.
* * * | s533782563 | Accepted | p03557 | Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X))))
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N = I()
A, B, C = ILL(3)
A.sort()
B.sort()
C.sort()
B2 = []
for b in B:
p = bisect.bisect_left(A, b)
if B2 == []:
B2.append(p)
else:
B2.append(B2[-1] + p)
C2 = []
for i in range(N):
c = C[i]
p = bisect.bisect_left(B, c)
if C2 == []:
if p == 0:
C2.append(0)
else:
C2.append(B2[p - 1])
else:
if p == 0:
C2.append(C2[-1])
else:
C2.append(C2[-1] + B2[p - 1])
print(C2[-1])
| Statement
The season for Snuke Festival has come again this year. First of all, Ringo
will perform a ritual to summon Snuke. For the ritual, he needs an altar,
which consists of three parts, one in each of the three categories: upper,
middle and lower.
He has N parts for each of the three categories. The size of the i-th upper
part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than
that of the upper part, and the size of the lower part must be strictly
greater than that of the middle part. On the other hand, any three parts that
satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered
different when at least one of the three parts used is different. | [{"input": "2\n 1 5\n 2 4\n 3 6", "output": "3\n \n\nThe following three altars can be built:\n\n * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n 1 1 1\n 2 2 2\n 3 3 3", "output": "27\n \n\n* * *"}, {"input": "6\n 3 14 159 2 6 53\n 58 9 79 323 84 6\n 2643 383 2 79 50 288", "output": "87"}] |
If Taro will win, print `First`; if Jiro will win, print `Second`.
* * * | s551543432 | Accepted | p03170 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | ###==================================================
### import
# import bisect
# from collections import Counter, deque, defaultdict
# from copy import deepcopy
# from functools import reduce, lru_cache
# from heapq import heappush, heappop
# import itertools
# import math
# import string
import sys
### stdin
def input():
return sys.stdin.readline()
def iIn():
return int(input())
def iInM():
return map(int, input().split())
def iInM1():
return map(int1, input().split())
def iInLH():
return list(map(int, input().split()))
def iInLH1():
return list(map(int1, input().split()))
def iInLV(n):
return [iIn() for _ in range(n)]
def iInLV1(n):
return [iIn() - 1 for _ in range(n)]
def iInLD(n):
return [iInLH() for _ in range(n)]
def iInLD1(n):
return [iInLH1() for _ in range(n)]
def sInLH():
return list(input().split())
def sInLV(n):
return [input().rstrip("\n") for _ in range(n)]
def sInLD(n):
return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=" "):
print(deli.join(map(str, lst)))
def OutV(lst):
print("\n".join(map(str, lst)))
### setting
sys.setrecursionlimit(10**6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------
N, K = iInM()
A = iInLH()
dp = [0] * (K + 1)
# 0: lose
# 1: win
for i in range(1, K + 1):
for j in range(N):
if i - A[j] < 0:
break
if dp[i - A[j]] == 0:
dp[i] = 1
break
ans = "First" if dp[K] else "Second"
print(ans)
# print(dp)
| Statement
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive
integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the
following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play
optimally, determine the winner. | [{"input": "2 4\n 2 3", "output": "First\n \n\nIf Taro removes three stones, Jiro cannot make a move. Thus, Taro wins.\n\n* * *"}, {"input": "2 5\n 2 3", "output": "Second\n \n\nWhatever Taro does in his operation, Jiro wins, as follows:\n\n * If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.\n * If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.\n\n* * *"}, {"input": "2 7\n 2 3", "output": "First\n \n\nTaro should remove two stones. Then, whatever Jiro does in his operation, Taro\nwins, as follows:\n\n * If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.\n * If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.\n\n* * *"}, {"input": "3 20\n 1 2 3", "output": "Second\n \n\n* * *"}, {"input": "3 21\n 1 2 3", "output": "First\n \n\n* * *"}, {"input": "1 100000\n 1", "output": "Second"}] |
If Taro will win, print `First`; if Jiro will win, print `Second`.
* * * | s653432282 | Runtime Error | p03170 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()
#####Shorten#####
def DD(arg): return defaultdict(arg)
#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n): return kaijo_memo[n]
if(len(kaijo_memo) == 0): kaijo_memo.append(1)
while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if n == r: return 1
if n < r or r < 0: return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1: arr.append([temp, 1])
if arr==[]: arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2,N+1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b: a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd (a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n-1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X//n: return base_10_to_n(X//n, n)+[X%n]
return [X%n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
return [X%n]
#####IntLog#####
def int_log(n, a):
count = 0
while n>=a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N,K = IL()
A = IL()
a = A[0]
dp = [0 for i in range(K+1)]
for i in range(a,K+1):
temp = [0]
for a in A:
if i >= a:
temp.append(dp[i-a])
if not max(temp):
dp[i] = 1
if dp[-1]:
print("First")
else:
print("Second") | Statement
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive
integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the
following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play
optimally, determine the winner. | [{"input": "2 4\n 2 3", "output": "First\n \n\nIf Taro removes three stones, Jiro cannot make a move. Thus, Taro wins.\n\n* * *"}, {"input": "2 5\n 2 3", "output": "Second\n \n\nWhatever Taro does in his operation, Jiro wins, as follows:\n\n * If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.\n * If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.\n\n* * *"}, {"input": "2 7\n 2 3", "output": "First\n \n\nTaro should remove two stones. Then, whatever Jiro does in his operation, Taro\nwins, as follows:\n\n * If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.\n * If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.\n\n* * *"}, {"input": "3 20\n 1 2 3", "output": "Second\n \n\n* * *"}, {"input": "3 21\n 1 2 3", "output": "First\n \n\n* * *"}, {"input": "1 100000\n 1", "output": "Second"}] |
If Taro will win, print `First`; if Jiro will win, print `Second`.
* * * | s381555790 | Runtime Error | p03170 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | def solve():
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp = ['Second']*(K*2)
for i in range(K):
if dp[i]!='Second':
continue
for j in range(N):
dp[i+A[j]]='First'
ans = dp[K]
return ans
print(solve())def solve():
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp = ['Second']*(K*2)
for i in range(K):
if dp[i]!='Second':
continue
for j in range(N):
dp[i+A[j]]='First'
ans = dp[K]
return ans
print(solve()) | Statement
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive
integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the
following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play
optimally, determine the winner. | [{"input": "2 4\n 2 3", "output": "First\n \n\nIf Taro removes three stones, Jiro cannot make a move. Thus, Taro wins.\n\n* * *"}, {"input": "2 5\n 2 3", "output": "Second\n \n\nWhatever Taro does in his operation, Jiro wins, as follows:\n\n * If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.\n * If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.\n\n* * *"}, {"input": "2 7\n 2 3", "output": "First\n \n\nTaro should remove two stones. Then, whatever Jiro does in his operation, Taro\nwins, as follows:\n\n * If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.\n * If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.\n\n* * *"}, {"input": "3 20\n 1 2 3", "output": "Second\n \n\n* * *"}, {"input": "3 21\n 1 2 3", "output": "First\n \n\n* * *"}, {"input": "1 100000\n 1", "output": "Second"}] |
If Taro will win, print `First`; if Jiro will win, print `Second`.
* * * | s595344457 | Runtime Error | p03170 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | n, k = map(int, input().split())
a = list(map, (int, input().split()))
dp = [False] * k+1;
for i in range (1, k+1):
for j in range(n):
if i-a[j]<0:
break;
if dp[i-a[j]]==False:
dp[i] = True;
break;
if dp[k] == True:
print("First");
else
print("Second");
| Statement
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive
integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the
following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play
optimally, determine the winner. | [{"input": "2 4\n 2 3", "output": "First\n \n\nIf Taro removes three stones, Jiro cannot make a move. Thus, Taro wins.\n\n* * *"}, {"input": "2 5\n 2 3", "output": "Second\n \n\nWhatever Taro does in his operation, Jiro wins, as follows:\n\n * If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.\n * If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.\n\n* * *"}, {"input": "2 7\n 2 3", "output": "First\n \n\nTaro should remove two stones. Then, whatever Jiro does in his operation, Taro\nwins, as follows:\n\n * If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.\n * If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.\n\n* * *"}, {"input": "3 20\n 1 2 3", "output": "Second\n \n\n* * *"}, {"input": "3 21\n 1 2 3", "output": "First\n \n\n* * *"}, {"input": "1 100000\n 1", "output": "Second"}] |
If Taro will win, print `First`; if Jiro will win, print `Second`.
* * * | s773545519 | Runtime Error | p03170 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | n, m = map(int, input().split())
a = [int(i) for i in input().split()))]
l = [0 for i in range(n+1)]
for i in range(1, m+1):
for j in range(n):
if a[j]<=i and l[i-a[j]] == 0:
l[i] = 1
if l[k] ==1:
print("First")
else:
print("Second") | Statement
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive
integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the
following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play
optimally, determine the winner. | [{"input": "2 4\n 2 3", "output": "First\n \n\nIf Taro removes three stones, Jiro cannot make a move. Thus, Taro wins.\n\n* * *"}, {"input": "2 5\n 2 3", "output": "Second\n \n\nWhatever Taro does in his operation, Jiro wins, as follows:\n\n * If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.\n * If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.\n\n* * *"}, {"input": "2 7\n 2 3", "output": "First\n \n\nTaro should remove two stones. Then, whatever Jiro does in his operation, Taro\nwins, as follows:\n\n * If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.\n * If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.\n\n* * *"}, {"input": "3 20\n 1 2 3", "output": "Second\n \n\n* * *"}, {"input": "3 21\n 1 2 3", "output": "First\n \n\n* * *"}, {"input": "1 100000\n 1", "output": "Second"}] |
If Taro will win, print `First`; if Jiro will win, print `Second`.
* * * | s254069716 | Runtime Error | p03170 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | N, K = map(int, input().split())
L = list(map(int, input().split()))
dp = [-1 for k in range(K+1)]
dp[0] = 1
def fn(n):
if dp[n] != -1:
return dp[n]
for i in L:
if n >= i:
if fn(n-i) == 1:
dp[n] = 0
return 0
dp[n] = 1
return 1
for l in range(1, K):
fn(l)
if fn(K) == 0:
print("First")
else:
print("Second") | Statement
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive
integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the
following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play
optimally, determine the winner. | [{"input": "2 4\n 2 3", "output": "First\n \n\nIf Taro removes three stones, Jiro cannot make a move. Thus, Taro wins.\n\n* * *"}, {"input": "2 5\n 2 3", "output": "Second\n \n\nWhatever Taro does in his operation, Jiro wins, as follows:\n\n * If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.\n * If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.\n\n* * *"}, {"input": "2 7\n 2 3", "output": "First\n \n\nTaro should remove two stones. Then, whatever Jiro does in his operation, Taro\nwins, as follows:\n\n * If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.\n * If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.\n\n* * *"}, {"input": "3 20\n 1 2 3", "output": "Second\n \n\n* * *"}, {"input": "3 21\n 1 2 3", "output": "First\n \n\n* * *"}, {"input": "1 100000\n 1", "output": "Second"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.