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 smallest cost of a route that takes not longer than time T.
If there is no route that takes not longer than time T, print `TLE` instead.
* * * | s487440599 | Runtime Error | p03239 | Input is given from Standard Input in the following format:
N T
c_1 t_1
c_2 t_2
:
c_N t_N | n,t = int(input().split())
m = 10000
for i in range(n):
c,d = int(input().split())
if d <= t:
if m > c:
m = c
if m = 10000:
print('TLE')
else:
print(m) | Statement
When Mr. X is away from home, he has decided to use his smartwatch to search
the best route to go back home, to participate in ABC.
You, the smartwatch, has found N routes to his home.
If Mr. X uses the i-th of these routes, he will get home in time t_i at cost
c_i.
Find the smallest cost of a route that takes not longer than time T. | [{"input": "3 70\n 7 60\n 1 80\n 4 50", "output": "4\n \n\n * The first route gets him home at cost 7.\n * The second route takes longer than time T = 70.\n * The third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\n* * *"}, {"input": "4 3\n 1 1000\n 2 4\n 3 1000\n 4 500", "output": "TLE\n \n\nThere is no route that takes not longer than time T = 3.\n\n* * *"}, {"input": "5 9\n 25 8\n 5 9\n 4 10\n 1000 1000\n 6 1", "output": "5"}] |
Print the smallest cost of a route that takes not longer than time T.
If there is no route that takes not longer than time T, print `TLE` instead.
* * * | s092119514 | Runtime Error | p03239 | Input is given from Standard Input in the following format:
N T
c_1 t_1
c_2 t_2
:
c_N t_N | n,a=map(int,input().split())
ans=100000000
for i in range(n):
c,t=map(int,input().split())
if t<=a:
ans=min(ans,c)
if ans=100000000
print('TLE')
else:
print(ans)
| Statement
When Mr. X is away from home, he has decided to use his smartwatch to search
the best route to go back home, to participate in ABC.
You, the smartwatch, has found N routes to his home.
If Mr. X uses the i-th of these routes, he will get home in time t_i at cost
c_i.
Find the smallest cost of a route that takes not longer than time T. | [{"input": "3 70\n 7 60\n 1 80\n 4 50", "output": "4\n \n\n * The first route gets him home at cost 7.\n * The second route takes longer than time T = 70.\n * The third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\n* * *"}, {"input": "4 3\n 1 1000\n 2 4\n 3 1000\n 4 500", "output": "TLE\n \n\nThere is no route that takes not longer than time T = 3.\n\n* * *"}, {"input": "5 9\n 25 8\n 5 9\n 4 10\n 1000 1000\n 6 1", "output": "5"}] |
Print the smallest cost of a route that takes not longer than time T.
If there is no route that takes not longer than time T, print `TLE` instead.
* * * | s331969931 | Runtime Error | p03239 | Input is given from Standard Input in the following format:
N T
c_1 t_1
c_2 t_2
:
c_N t_N | # 6727236
ソースコード
Copy
Copy
Tmp = []
Tmp = input().rstrip().split(" ")
nN = int(Tmp[0])
nT = int(Tmp[1])
nCost = 1001
nAns = 0
for i in range(nN):
Tmp = input().rstrip().split(" ")
nTmpCost = int(Tmp[0])
nTmpT = int(Tmp[1])
if nTmpT <= nT and nTmpCost < nCost:
nCost = nTmpCost
nAns = i + 1
if nAns == 0:
print("TLE")
else:
print(nCost)
| Statement
When Mr. X is away from home, he has decided to use his smartwatch to search
the best route to go back home, to participate in ABC.
You, the smartwatch, has found N routes to his home.
If Mr. X uses the i-th of these routes, he will get home in time t_i at cost
c_i.
Find the smallest cost of a route that takes not longer than time T. | [{"input": "3 70\n 7 60\n 1 80\n 4 50", "output": "4\n \n\n * The first route gets him home at cost 7.\n * The second route takes longer than time T = 70.\n * The third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\n* * *"}, {"input": "4 3\n 1 1000\n 2 4\n 3 1000\n 4 500", "output": "TLE\n \n\nThere is no route that takes not longer than time T = 3.\n\n* * *"}, {"input": "5 9\n 25 8\n 5 9\n 4 10\n 1000 1000\n 6 1", "output": "5"}] |
Print the smallest cost of a route that takes not longer than time T.
If there is no route that takes not longer than time T, print `TLE` instead.
* * * | s527385310 | Wrong Answer | p03239 | Input is given from Standard Input in the following format:
N T
c_1 t_1
c_2 t_2
:
c_N t_N | nt = input().split()
ct = [0]
for i in range(int(nt[0])):
inp = input().split()
if int(inp[1]) <= int(nt[1]):
ct.append(int(inp[0]))
print(ct)
ct.sort()
print(ct)
if len(ct) == 1:
print("TLE")
else:
print(ct[1])
| Statement
When Mr. X is away from home, he has decided to use his smartwatch to search
the best route to go back home, to participate in ABC.
You, the smartwatch, has found N routes to his home.
If Mr. X uses the i-th of these routes, he will get home in time t_i at cost
c_i.
Find the smallest cost of a route that takes not longer than time T. | [{"input": "3 70\n 7 60\n 1 80\n 4 50", "output": "4\n \n\n * The first route gets him home at cost 7.\n * The second route takes longer than time T = 70.\n * The third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\n* * *"}, {"input": "4 3\n 1 1000\n 2 4\n 3 1000\n 4 500", "output": "TLE\n \n\nThere is no route that takes not longer than time T = 3.\n\n* * *"}, {"input": "5 9\n 25 8\n 5 9\n 4 10\n 1000 1000\n 6 1", "output": "5"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s345735757 | Runtime Error | p03393 | Input is given from Standard Input in the following format:
S | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
S = list(input())
check = [0]*26
if len(S)==26:
else:
end = S[-1]
for i in range(24, -1, -1):
if ord(S[i])<ord(end):
S[i] = end
print(''.join(S[:i+1]))
break
else:
if S[0]=='z':
print(-1)
else:
print(chr(ord(S[0])+1))
else:
for s in S:
check[ord(s)-97] = 1
for i in range(26):
if not check[i]:
S.append(chr(i+97))
break
print(''.join(S))
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s756938837 | Accepted | p03393 | Input is given from Standard Input in the following format:
S | # -*- 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 collections import Counter
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
#####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))))
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
L = "abcdefghijklmnopqrstuvwxyz"
invL = L[::-1]
S = S()
if len(S) != 26:
for l in L:
if l not in S:
print(S + l)
exit()
else:
prev = chr(96)
for s in S[::-1]:
now = s
if ord(now) < ord(prev):
k = S.index(now)
for l in L[ord(now) - 97 + 1 :]:
if l not in S[:k]:
print(S[:k] + l)
exit()
prev = now
print(-1)
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s214879562 | Wrong Answer | p03393 | Input is given from Standard Input in the following format:
S | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [input() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [int(input()) for i in range(n)]
class Math:
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def roundUp(a, b):
return -(-a // b)
@staticmethod
def toUpperMultiple(a, x):
return Math.roundUp(a, x) * x
@staticmethod
def toLowerMultiple(a, x):
return (a // x) * x
@staticmethod
def nearPow2(n):
if n <= 0:
return 0
if n & (n - 1) == 0:
return n
ret = 1
while n > 0:
ret <<= 1
n >>= 1
return ret
@staticmethod
def sign(n):
if n == 0:
return 0
if n < 0:
return -1
return 1
@staticmethod
def isPrime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n**0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
class PriorityQueue:
def __init__(self, l=[]):
self.__q = l
heapq.heapify(self.__q)
return
def push(self, n):
heapq.heappush(self.__q, n)
return
def pop(self):
return heapq.heappop(self.__q)
MOD = int(1e09) + 7
INF = int(1e15)
def calc(N):
return sum(int(x) for x in str(N))
def main():
# sys.stdin = open("sample.txt")
S = Scanner.string()
if len(S) == 26:
if list(S) == list(reversed(list(string.ascii_lowercase))):
print(-1)
return
i = 0
for i in reversed(range(25)):
if S[i] < S[i + 1]:
break
ans = S[:i]
ans += sorted(S[i + 1 :])[0]
print(ans)
return
else:
T = Counter(S)
for c in string.ascii_lowercase:
if T[c] == 0:
print(S + c)
return
return
if __name__ == "__main__":
main()
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s943289951 | Runtime Error | p03393 | Input is given from Standard Input in the following format:
S | # encoding:utf-8
import fractions
def check(l):
l = list(map(int, l.split()))
print(len(l), len([x for x in l if x % 2 == 0]), len([x for x in l if x % 2 == 1]))
if max(l) >= 30001:
print("max >= 30001")
return False
if len(set(l)) != len(l):
print("not unique")
return False
tmp = l[0]
for i in range(len(l) - 1):
tmp = fractions.gcd(tmp, l[i + 1])
if tmp != 1:
print("gcd is 1")
return False
for i in range(len(l)):
if fractions.gcd(l[i], sum(l) - l[i]) == 1:
print("not special")
return False
return True
def main(n):
if n == 3:
return "2 5 63"
sub1 = [str(i * 3) for i in range(1, 10001) if i % 2 == 1]
sub2 = [str(i) for i in range(1, 30000) if i % 2 == 0 and i % 3 != 0]
sub3 = [str(i) for i in range(1, 30001) if i % 6 == 0]
if n <= 5003:
if n % 2 == 0:
s = "2 4 " + " ".join([str(x) for x in sub1[0 : (n - 2)]])
return s
else:
s = "2 4 6 " + " ".join([str(x) for x in sub1[0 : (n - 3)]])
return s
elif n <= 15000:
if n % 2 == 0:
s = " ".join(sub2[0 : (n - 5000)]) + " " + " ".join(sub1)
return s
else:
s = " ".join(sub2[0 : (n - 5001)]) + " 6 " + " ".join(sub1)
return s
else:
s = (
" ".join(sub2)
+ " "
+ " ".join(sub1)
+ " "
+ " ".join(sub3[0 : (n - 15000)])
)
return s
if __name__ == "__main__":
n = int(input())
# print(check(main(n)))
# print(main(20000))
print(main(n))
# print(check("2 4 3 20001"))
# for i in range(5001, 5006):
# ans = main(i)
# print(i, check(ans))
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s854067051 | Accepted | p03393 | Input is given from Standard Input in the following format:
S | import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a, b):
return math.gcd # 最大公約数
def lcm(a, b):
return (a * b) // math.gcd(a, b) # 最小公倍数
def iin():
return int(input()) # 整数読み込み
def isn():
return input().split() # 文字列読み込み
def imn():
return map(int, input().split()) # 整数map取得
def iln():
return list(map(int, input().split())) # 整数リスト取得
def iln_s():
return sorted(iln()) # 昇順の整数リスト取得
def iln_r():
return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=""):
return s.join(l) # リストを文字列に変換
def perm(l, n):
return itertools.permutations(l, n) # 順列取得
def comb(l, n):
return itertools.combinations(l, n) # 組み合わせ取得
def 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
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def primes(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
def sieve_of_e(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return is_prime
s = input()
S = list(s)
a = string.ascii_lowercase
od = collections.OrderedDict()
for i in range(len(a)):
od[a[i]] = 0
for st in S:
od[st] = 1
for k, v in od.items():
if v == 0:
print(join(S) + k)
exit()
prev = S.pop()
od[prev] = 0
done = False
for i in range(len(S)):
prev = S.pop()
od[prev] = 0
target = False
for k, v in od.items():
if prev == k:
target = True
continue
if target == True and v == 0:
print(join(S) + k)
done = True
break
if done == True:
break
if done == False:
print(-1)
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s249090145 | Wrong Answer | p03393 | Input is given from Standard Input in the following format:
S | s = list(input())
for i in range(len(s)):
if s[i] == "a":
s[i] = 0
if s[i] == "b":
s[i] = 1
if s[i] == "c":
s[i] = 2
if s[i] == "d":
s[i] = 3
if s[i] == "e":
s[i] = 4
if s[i] == "f":
s[i] = 5
if s[i] == "g":
s[i] = 6
if s[i] == "h":
s[i] = 7
if s[i] == "i":
s[i] = 8
if s[i] == "j":
s[i] = 9
if s[i] == "k":
s[i] = 10
if s[i] == "l":
s[i] = 11
if s[i] == "m":
s[i] = 12
if s[i] == "n":
s[i] = 13
if s[i] == "o":
s[i] = 14
if s[i] == "p":
s[i] = 15
if s[i] == "q":
s[i] = 16
if s[i] == "r":
s[i] = 17
if s[i] == "s":
s[i] = 18
if s[i] == "t":
s[i] = 19
if s[i] == "u":
s[i] = 20
if s[i] == "v":
s[i] = 21
if s[i] == "w":
s[i] = 22
if s[i] == "x":
s[i] = 23
if s[i] == "y":
s[i] = 24
if s[i] == "z":
s[i] = 25
if len(s) != 26:
for i in range(26):
if i not in s:
s.append(i)
break
for i in range(len(s)):
if s[i] == 0:
s[i] = "a"
if s[i] == 1:
s[i] = "b"
if s[i] == 2:
s[i] = "c"
if s[i] == 3:
s[i] = "d"
if s[i] == 4:
s[i] = "e"
if s[i] == 5:
s[i] = "f"
if s[i] == 6:
s[i] = "g"
if s[i] == 7:
s[i] = "h"
if s[i] == 8:
s[i] = "i"
if s[i] == 9:
s[i] = "j"
if s[i] == 10:
s[i] = "k"
if s[i] == 11:
s[i] = "l"
if s[i] == 12:
s[i] = "m"
if s[i] == 13:
s[i] = "n"
if s[i] == 14:
s[i] = "o"
if s[i] == 15:
s[i] = "p"
if s[i] == 16:
s[i] = "q"
if s[i] == 17:
s[i] = "r"
if s[i] == 18:
s[i] = "s"
if s[i] == 19:
s[i] = "t"
if s[i] == 20:
s[i] = "u"
if s[i] == 21:
s[i] = "v"
if s[i] == 22:
s[i] = "w"
if s[i] == 23:
s[i] = "x"
if s[i] == 24:
s[i] = "y"
if s[i] == 25:
s[i] = "z"
s_ = "".join(s)
print(s_)
else:
x = 1
while True:
if s[-x] > s[-x - 1]:
s1 = s[0 : -x - 1]
s2 = s[-x - 1] + 1
s1.append(s2)
break
else:
x = x + 1
if x == 26:
break
if s == [
25,
24,
23,
22,
21,
20,
19,
18,
17,
16,
15,
14,
13,
12,
11,
10,
9,
8,
7,
6,
5,
4,
3,
2,
1,
0,
]:
print("-1")
else:
for i in range(len(s1)):
if s1[i] == 0:
s1[i] = "a"
if s1[i] == 1:
s1[i] = "b"
if s1[i] == 2:
s1[i] = "c"
if s1[i] == 3:
s1[i] = "d"
if s1[i] == 4:
s1[i] = "e"
if s1[i] == 5:
s1[i] = "f"
if s1[i] == 6:
s1[i] = "g"
if s1[i] == 7:
s1[i] = "h"
if s1[i] == 8:
s1[i] = "i"
if s1[i] == 9:
s1[i] = "j"
if s1[i] == 10:
s1[i] = "k"
if s1[i] == 11:
s1[i] = "l"
if s1[i] == 12:
s1[i] = "m"
if s1[i] == 13:
s1[i] = "n"
if s1[i] == 14:
s1[i] = "o"
if s1[i] == 15:
s1[i] = "p"
if s1[i] == 16:
s1[i] = "q"
if s1[i] == 17:
s1[i] = "r"
if s1[i] == 18:
s1[i] = "s"
if s1[i] == 19:
s1[i] = "t"
if s1[i] == 20:
s1[i] = "u"
if s1[i] == 21:
s1[i] = "v"
if s1[i] == 22:
s1[i] = "w"
if s1[i] == 23:
s1[i] = "x"
if s1[i] == 24:
s1[i] = "y"
if s1[i] == 25:
s1[i] = "z"
s2_ = "".join(s1)
print(s2_)
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s852731119 | Wrong Answer | p03393 | Input is given from Standard Input in the following format:
S | def examA():
S = SI()
N = len(S)
if N < 26:
d = defaultdict(bool)
for s in S:
d[s] = True
for a in alphabet:
if not d[a]:
ans = S + a
print(ans)
return
keep = []
for i in range(N - 1)[::-1]:
keep.append(S[i + 1])
if S[i] < S[i + 1]:
break
# print(keep)
n = len(keep)
if n == 25:
print(-1)
return
c = "zz"
for s in keep:
if s > S[(N - n - 1)]:
c = min(c, s)
ans = S[: (N - n - 1)] + c
print(ans)
return
def examB():
N = I()
ans = [2 * (i + 1) for i in range(N)]
if N % 2 == 0:
for i in range(4998):
ans[-3 - i] = 3 + i * 6
print(" ".join(map(str, ans)))
return
def examC():
ans = 0
print(ans)
return
def examD():
ans = 0
print(ans)
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LFI():
return list(map(float, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord("a") + i) for i in range(26)]
if __name__ == "__main__":
examA()
"""
"""
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s928401442 | Runtime Error | p03393 | Input is given from Standard Input in the following format:
S | from string import*
from itertools import*
b = ascii_lowercase
s = input()
if len(s) < 26:
print(s + sorted(set(b) - set(s))[0])
else:
d = [p,len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], t[-2::-1])])][0] - 2
print(-(d < -26) or s[:d] + sorted(set(s[d+1:]) - set(b[:ord(s[d]) - 97]))[0]) | Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s683980768 | Wrong Answer | p03393 | Input is given from Standard Input in the following format:
S | S = input()
def next_tasai(S):
if S == "zyxwvutsrqponmlkjihgfedcba":
return -1
A = "abcdefghijklmnopqrstuvwxyz"
Aset = set([a for a in A])
Sset = set([s for s in S])
if Aset - Sset:
l = min(Aset - Sset)
answer = S + l
return answer
else:
i = -1
while True:
if S[i] < S[i - 1]:
i -= 1
else:
key = min([s for s in S[i - 1 :] if s > S[i - 1]])
return (
S[: i - 1]
+ key
+ "".join(sorted([s for s in S[i - 1 :].replace(key, "")]))
)
print(next_tasai(S))
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
Print the next word that appears after S in the dictionary, or `-1` if it
doesn't exist.
* * * | s572371312 | Wrong Answer | p03393 | Input is given from Standard Input in the following format:
S | ss = input()
ss = list(map(ord, ss))
dic = [i for i in range(97, 123)]
# print(dic)
for s in ss:
dic.remove(s)
# print(dic)
if len(ss) < 26:
ss.append(min(dic))
else:
for s in ss[::-1]:
if len(dic) > 0 and s < max(dic):
ss[ss.index(s)] = max(dic)
break
dic.append(ss.pop(ss.index(s)))
else:
ss = -1
print(ss if ss == -1 else "".join(list(map(chr, ss))))
| Statement
Gotou just received a dictionary. However, he doesn't recognize the language
used in the dictionary. He did some analysis on the dictionary and realizes
that the dictionary contains all possible **diverse** words in lexicographical
order.
A word is called **diverse** if and only if it is a nonempty string of English
lowercase letters and all letters in the word are distinct. For example,
`atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect`
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the
dictionary, i.e. the lexicographically smallest diverse word that is
lexicographically larger than S, or determine that it doesn't exist.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
X is lexicographically larger than Y if and only if Y is a prefix of X or
x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | [{"input": "atcoder", "output": "atcoderb\n \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}] |
If it is possible to arrange the pieces under the conditions, print `YES`; if
it is impossible, print `NO`.
* * * | s218507203 | Wrong Answer | p03669 | Input is given from Standard Input in the following format:
N H
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_N B_N C_N D_N | a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
a = 1
print("YES")
| Statement
We have N irregular jigsaw pieces. Each piece is composed of three rectangular
parts of width 1 and various heights joined together. More specifically:
* The i-th piece is a part of height H, with another part of height A_i joined to the left, and yet another part of height B_i joined to the right, as shown below. Here, the bottom sides of the left and right parts are respectively at C_i and D_i units length above the bottom side of the center part.

Snuke is arranging these pieces on a square table of side 10^{100}. Here, the
following conditions must be held:
* All pieces must be put on the table.
* The entire bottom side of the center part of each piece must touch the front side of the table.
* The entire bottom side of the non-center parts of each piece must either touch the front side of the table, or touch the top side of a part of some other piece.
* The pieces must not be rotated or flipped.
Determine whether such an arrangement is possible. | [{"input": "3 4\n 1 1 0 0\n 2 2 0 1\n 3 3 1 0", "output": "YES\n \n\nThe figure below shows a possible arrangement.\n\n\n\n* * *"}, {"input": "4 2\n 1 1 0 1\n 1 1 0 1\n 1 1 0 1\n 1 1 0 1", "output": "NO\n \n\n* * *"}, {"input": "10 4\n 1 1 0 3\n 2 3 2 0\n 1 2 3 0\n 2 1 0 0\n 3 2 0 2\n 1 1 3 0\n 3 2 0 0\n 1 3 2 0\n 1 1 1 3\n 2 3 0 0", "output": "YES"}] |
If it is possible to arrange the pieces under the conditions, print `YES`; if
it is impossible, print `NO`.
* * * | s131325479 | Runtime Error | p03669 | Input is given from Standard Input in the following format:
N H
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_N B_N C_N D_N | int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
print("YES") | Statement
We have N irregular jigsaw pieces. Each piece is composed of three rectangular
parts of width 1 and various heights joined together. More specifically:
* The i-th piece is a part of height H, with another part of height A_i joined to the left, and yet another part of height B_i joined to the right, as shown below. Here, the bottom sides of the left and right parts are respectively at C_i and D_i units length above the bottom side of the center part.

Snuke is arranging these pieces on a square table of side 10^{100}. Here, the
following conditions must be held:
* All pieces must be put on the table.
* The entire bottom side of the center part of each piece must touch the front side of the table.
* The entire bottom side of the non-center parts of each piece must either touch the front side of the table, or touch the top side of a part of some other piece.
* The pieces must not be rotated or flipped.
Determine whether such an arrangement is possible. | [{"input": "3 4\n 1 1 0 0\n 2 2 0 1\n 3 3 1 0", "output": "YES\n \n\nThe figure below shows a possible arrangement.\n\n\n\n* * *"}, {"input": "4 2\n 1 1 0 1\n 1 1 0 1\n 1 1 0 1\n 1 1 0 1", "output": "NO\n \n\n* * *"}, {"input": "10 4\n 1 1 0 3\n 2 3 2 0\n 1 2 3 0\n 2 1 0 0\n 3 2 0 2\n 1 1 3 0\n 3 2 0 0\n 1 3 2 0\n 1 1 1 3\n 2 3 0 0", "output": "YES"}] |
Print the subsets ordered by their decimal integers. Print a subset in the
following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset
in ascending order. Separate two adjacency elements by a space character. | s838698163 | Accepted | p02428 | The input is given in the following format.
$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$
$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$. | n = int(input())
d = list(map(int, input().split()))
for b in range(2**n):
a = bin(b)[2:]
a = a[::-1]
ans = []
for i in range(len(a)):
if a[i] == "1":
ans.append(i)
ans.sort()
flag = True
for i in d[1:]:
if i not in ans:
flag = False
break
if flag:
print(str(b) + ":", *ans)
| Enumeration of Subsets II
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0,
1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$
as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010,
00...0100, ..., 10...0000 in binary respectively and the integer
representation of a subset is calculated by bitwise OR of existing elements. | [{"input": "4\n 2 0 2", "output": "5: 0 2\n 7: 0 1 2\n 13: 0 2 3\n 15: 0 1 2 3"}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s373840376 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | X, K, D = list(map(int, input().split()))
def sgn(x):
if x > 0:
return 1
elif x < 0:
return -1
return 0
def solve():
if X > 0:
x_greedy = X - K * D
elif X < 0:
x_greedy = X + K * D
if sgn(X) == sgn(x_greedy):
return print(abs(x_greedy))
else:
x_r = X % D
x_l = x_r - D
r_parity = (abs(X - x_r) // D) % 2
if K % 2 == r_parity:
return print(abs(x_r))
else:
return print(abs(x_l))
if __name__ == "__main__":
solve()
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s876071135 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | import heapq
N, K = map(int, input().split(" "))
Ps = list(map(int, input().split(" ")))
Cs = list(map(int, input().split(" ")))
max_points = []
heapq.heapify(max_points)
for now_point in range(2, N + 1):
max_point = -float("inf")
C_point = 0
max_point = []
heapq.heapify(max_point)
for _ in range(K):
next_point = Ps[now_point - 1]
C_point += Cs[next_point - 1]
heapq.heappush(max_point, -C_point)
now_point = next_point
max_point_ = heapq.heappop(max_point)
heapq.heappush(max_points, max_point_)
print(-heapq.heappop(max_points))
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s912906236 | Wrong Answer | p02582 | Input is given from Standard Input in the following format:
S | rainy_days = input()
if rainy_days == "RRR":
print(3)
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s110752636 | Accepted | p02582 | Input is given from Standard Input in the following format:
S | S = input()
if S == 'SSS':print(0)
if S == 'SSR':print(1)
if S == 'SRS':print(1)
if S == 'SRR':print(2)
if S == 'RSS':print(1)
if S == 'RSR':print(1)
if S == 'RRS':print(2)
if S == 'RRR':print(3) | Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s218585868 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | X, K, D = [int(x) for x in input().strip().split(" ")]
k, x = divmod(X, D)
if K >= k:
X = x
K -= k
if k % 2 == 0:
print(abs(X))
elif X < 0:
print(abs(X + D))
else:
print(abs(X - D))
elif X < 0:
print(abs(X + D * K))
else:
print(abs(X - D * K))
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s732634953 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | input_line = input()
data = input_line.split(" ")
x = abs(int(data[0]))
k = int(data[1])
d = int(data[2])
a = x // d
b = x % d
res = abs(a)
if res >= k:
ans = x - k * d
else:
num = k - res
if num % 2 == 1:
ans = abs(b - d)
else:
ans = b
print(ans)
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s215062890 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | N, X, T = map(int, input().split())
y = N // X
c = N % X
print((y * T + T) if c else (y * T))
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s991755857 | Accepted | p02582 | Input is given from Standard Input in the following format:
S | C = input()
print(len(max(C.split("S"))))
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s757235745 | Wrong Answer | p02582 | Input is given from Standard Input in the following format:
S | S = list(input())
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s247538443 | Wrong Answer | p02582 | Input is given from Standard Input in the following format:
S | max([len(t) for t in input().split("S")])
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s982091123 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | R, C, K = map(int, input().split(" "))
board = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K):
i, j, v = map(int, input().split(" "))
board[i][j] = v
score = [[[0] * 4 for _ in range(C + 1)] for _ in range(R + 1)]
for i in range(1, R + 1):
for j in range(1, C + 1):
if board[i][j] == 0:
for k in range(4):
score[i][j][k] = score[i][j - 1][k]
else:
for k in range(3):
score[i][j][k + 1] = score[i][j - 1][k] + board[i][j]
descent = max(score[i - 1][j])
score[i][j][1] = max(
descent + board[i][j], score[i][j - 1][1], score[i][j - 1][0] + board[i][j]
)
score[i][j][0] = max(descent, score[i][j - 1][0])
print(max(score[-1][-1]))
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s205153073 | Wrong Answer | p02582 | Input is given from Standard Input in the following format:
S | a,b,c = map(str,input().rstrip(""))
if(a=="R" and b == "R" and c == "R"):
count = 3
elif(a=="R" and b == "R" and c == "S"):
count = 2
elif(a=="R" and b == "S" and c == "S"):
count = 1
elif(a=="S" and b == "R" and c == "R"):
count = 2
elif(a=="S" and b == "R" and c == "S"):
count = 1
elif(a=="S" and b == "S" and c == "R"):
count = 1
else:
count = 0
print(count)
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s152759907 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | whether=input(str())
if whether[1]==whether[2]==whether[3]=="R":
print ("3")
elif whether[1]==whether[2]==whether[3]=="S":
print ("0")
elif whether[1]==whether[2]=="R" or whether[2]==whether[3]=="R":
print ("2")
else:
print ("1")
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s684961054 | Accepted | p02582 | Input is given from Standard Input in the following format:
S | print(max(map(len, input().split("S"))))
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s106662299 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | def run():
# sys.stdin.readline()
import sys
input = sys.stdin.readline
r, c, k = map(int, input().split())
t = [[0 for i in range(c)] for i in range(r)]
for i in range(k):
a, b, z = map(int, input().split())
t[a - 1][b - 1] = z
t = tuple(t)
dp = [[[0 for i in range(c)] for i in range(r)] for i in range(4)]
dp[0][0][0] = 0
dp[1][0][0] = t[0][0]
dp[2][0][0] = t[0][0]
dp[3][0][0] = t[0][0]
for i in range(r - 1):
dp[0][i + 1][0] = dp[1][i][0]
for j in range(1, 4):
dp[j][i + 1][0] = dp[1][i][0] + t[i + 1][0]
for i in range(c - 1):
dp[0][0][i + 1] = 0
for j in range(1, 4):
dp[j][0][i + 1] = max(dp[1][0][i], t[0][i + 1])
for j in range(2, 4):
dp[j][0][i + 1] = max(dp[2][0][i], dp[1][0][i] + t[0][i + 1])
dp[3][0][i + 1] = max(dp[3][0][i], dp[2][0][i] + t[0][i + 1])
for i in range(r - 1):
for j in range(c - 1):
u = max(dp[0][i + 1][j], dp[3][i][j + 1])
for s in range(0, 4):
dp[s][i + 1][j + 1] = u
u = max(
dp[0][i + 1][j] + t[i + 1][j + 1],
dp[1][i + 1][j],
dp[3][i][j + 1] + t[i + 1][j + 1],
)
for s in range(1, 4):
dp[s][i + 1][j + 1] = u
u = max(
dp[1][i + 1][j] + t[i + 1][j + 1],
dp[2][i + 1][j],
dp[3][i][j + 1] + t[i + 1][j + 1],
)
for s in range(2, 4):
dp[s][i + 1][j + 1] = u
dp[3][i + 1][j + 1] = max(
dp[2][i + 1][j] + t[i + 1][j + 1],
dp[3][i + 1][j],
dp[3][i][j + 1] + t[i + 1][j + 1],
)
print(dp[3][r - 1][c - 1])
if __name__ == "__main__":
run()
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s876327766 | Runtime Error | p02582 | Input is given from Standard Input in the following format:
S | p = {"RRR": 3, "RRS": 2, "SRR": 2, "RSR": 1, "SSR": 1, "RSS": 1, "SSS": 0}
print(p[input()])
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s657289304 | Accepted | p02582 | Input is given from Standard Input in the following format:
S | a = max(input().split("S"))
print(len(a))
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
Print the maximum number of consecutive rainy days in the period.
* * * | s699593912 | Wrong Answer | p02582 | Input is given from Standard Input in the following format:
S | print(sum(s == "R" for s in input()))
| Statement
We have weather records at AtCoder Town for some consecutive three days. A
string of length 3, S, represents the records - if the i-th character is `S`,
it means it was sunny on the i-th day; if that character is `R`, it means it
was rainy on that day.
Find the maximum number of consecutive rainy days in this period. | [{"input": "RRS", "output": "2\n \n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number\nof consecutive rainy days is 2, so we should print 2.\n\n* * *"}, {"input": "SSS", "output": "0\n \n\nIt was sunny throughout the period. We had no rainy days, so we should print\n0.\n\n* * *"}, {"input": "RSR", "output": "1\n \n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we\nshould print 1."}] |
For each dataset, print a list of employee IDs or a text "NA" | s208643097 | Wrong Answer | p00100 | The input consists of several datasets. The input ends with a line including a
single 0. Each dataset consists of:
_n_ (the number of data in the list)
_i_ _p_ _q_
_i_ _p_ _q_
:
:
_i_ _p_ _q_ | #!/usr/bin/env python3
import sys
input_lines = sys.stdin.readlines()
cnt = 0
dataset = []
for i in input_lines:
print("s")
| Sale Result
There is data on sales of your company. Your task is to write a program which
identifies good workers.
The program should read a list of data where each item includes the employee
ID _i_ , the amount of sales _q_ and the corresponding unit price _p_. Then,
the program should print IDs of employees whose total sales proceeds (i.e. sum
of p × q) is greater than or equal to 1,000,000 in the order of inputting. If
there is no such employees, the program should print "NA". You can suppose
that _n_ < 4000, and each employee has an unique ID. The unit price _p_ is
less than or equal to 1,000,000 and the amount of sales _q_ is less than or
equal to 100,000. | [{"input": "1001 2000 520\n 1002 1800 450\n 1003 1600 625\n 1001 200 1220\n 2\n 1001 100 3\n 1005 1000 100\n 2\n 2013 5000 100\n 2013 5000 100\n 0", "output": "1003\n NA\n 2013"}] |
For each dataset, print a list of employee IDs or a text "NA" | s638625455 | Wrong Answer | p00100 | The input consists of several datasets. The input ends with a line including a
single 0. Each dataset consists of:
_n_ (the number of data in the list)
_i_ _p_ _q_
_i_ _p_ _q_
:
:
_i_ _p_ _q_ | num = int(input())
if not num:
exit()
data = [[int(el) for el in input().split(" ")] for _ in range(num)]
result = [print(i) for i, j, k in data if j * k >= 1e6]
if not result:
print("NA")
| Sale Result
There is data on sales of your company. Your task is to write a program which
identifies good workers.
The program should read a list of data where each item includes the employee
ID _i_ , the amount of sales _q_ and the corresponding unit price _p_. Then,
the program should print IDs of employees whose total sales proceeds (i.e. sum
of p × q) is greater than or equal to 1,000,000 in the order of inputting. If
there is no such employees, the program should print "NA". You can suppose
that _n_ < 4000, and each employee has an unique ID. The unit price _p_ is
less than or equal to 1,000,000 and the amount of sales _q_ is less than or
equal to 100,000. | [{"input": "1001 2000 520\n 1002 1800 450\n 1003 1600 625\n 1001 200 1220\n 2\n 1001 100 3\n 1005 1000 100\n 2\n 2013 5000 100\n 2013 5000 100\n 0", "output": "1003\n NA\n 2013"}] |
Output a line containing the minimum amount of the holy water required to save
all his cats. Your program may output an arbitrary number of digits after the
decimal point. However, the absolute error should be 0.001 or less. | s848646802 | Wrong Answer | p01341 | The input has the following format:
_N M_
_x_ 1 _y_ 1 .
.
.
_x_ _N_ _y_ _N_ _p_ 1 _q_ 1
.
.
.
_p_ _M_ _q_ _M_
The first line of the input contains two integers _N_ (2 ≤ _N_ ≤ 10000) and
_M_ (1 ≤ _M_). _N_ indicates the number of magical piles and _M_ indicates the
number of magical fences. The following _N_ lines describe the coordinates of
the piles. Each line contains two integers _x i_ and _y i_ (-10000 ≤ _x i_, _y
i_ ≤ 10000). The following _M_ lines describe the both ends of the fences.
Each line contains two integers _p j_ and _q j_ (1 ≤ _p j_, _q j_ ≤ _N_). It
indicates a fence runs between the _p j_-th pile and the _q j_-th pile.
You can assume the following:
* No Piles have the same coordinates.
* A pile doesn’t lie on the middle of fence.
* No Fences cross each other.
* There is at least one cat in each enclosed area.
* It is impossible to destroy a fence partially.
* A unit of holy water is required to destroy a unit length of magical fence. | N, M = map(int, input().rstrip().split())
pileDict = {}
for i in range(N):
prow, pcol = map(lambda x: int(x), input().rstrip().split())
pileDict[i] = [prow, pcol]
edgeDict = {}
for i in range(M):
fs, fe = map(lambda x: int(x), input().rstrip().split())
edgeDict[i] = [fs, fe]
print("test")
| C: Save your cats
Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many
cats in his garden. The cats were so cute that people in the village also
loved them.
One day, an evil witch visited the village. She envied the cats for being
loved by everyone. She drove magical piles in his garden and enclosed the cats
with magical fences running between the piles. She said “Your cats are shut
away in the fences until they become ugly old cats.” like a curse and went
away.
Nicholas tried to break the fences with a hummer, but the fences are
impregnable against his effort. He went to a church and asked a priest help.
The priest looked for how to destroy the magical fences in books and found
they could be destroyed by holy water. The Required amount of the holy water
to destroy a fence was proportional to the length of the fence. The holy water
was, however, fairly expensive. So he decided to buy exactly the minimum
amount of the holy water required to save all his cats. How much holy water
would be required? | [{"input": "3 3\n 0 0\n 3 0\n 0 4\n 1 2\n 2 3\n 3 1", "output": "3.000"}, {"input": "4 3\n 0 0\n -100 0\n 100 0\n 0 100\n 1 2\n 1 3\n 1 4", "output": "0.000"}, {"input": "6 7\n 2 0\n 6 0\n 8 2\n 6 3\n 0 5\n 1 7\n 1 2\n 2 3\n 3 4\n 4 1\n 5 1\n 5 4\n 5 6", "output": "7.236"}, {"input": "6 6\n 0 0\n 0 1\n 1 0\n 30 0\n 0 40\n 30 40\n 1 2\n 2 3\n 3 1\n 4 5\n 5 6\n 6 4", "output": "31.000"}] |
Print the minimum required number of additional chairs.
* * * | s806634478 | Wrong Answer | p03686 | Input is given from Standard Input in the following format:
N M
L_1 R_1
:
L_N R_N | N, M = map(int, input().split())
span = []
for _ in range(N):
l, r = map(int, input().split())
s = r
t = M + l
span.append((s, t))
span.sort()
cnt = 0
tmp = -1
for s, t in span:
if tmp < s:
tmp = s
elif tmp + 1 <= t:
tmp += 1
else:
cnt += 1
print(cnt)
| Statement
There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i
≤ M) is i.
N people of the Takahashi clan played too much games, and they are all
suffering from backaches. They need to sit in chairs and rest, but they are
particular about which chairs they sit in. Specifically, the i-th person
wishes to sit in a chair whose coordinate is not greater than L_i, or not less
than R_i. Naturally, only one person can sit in the same chair.
It may not be possible for all of them to sit in their favorite chairs, if
nothing is done. Aoki, who cares for the health of the people of the Takahashi
clan, decides to provide additional chairs so that all of them can sit in
chairs at their favorite positions.
Additional chairs can be placed at arbitrary real coordinates. Find the
minimum required number of additional chairs. | [{"input": "4 4\n 0 3\n 2 3\n 1 3\n 3 4", "output": "0\n \n\nThe four people can sit in chairs at the coordinates 3, 2, 1 and 4,\nrespectively, and no more chair is needed.\n\n* * *"}, {"input": "7 6\n 0 7\n 1 5\n 3 6\n 2 7\n 1 6\n 2 6\n 3 7", "output": "2\n \n\nIf we place additional chairs at the coordinates 0 and 2.5, the seven people\ncan sit at coordinates 0, 5, 3, 2, 6, 1 and 2.5, respectively.\n\n* * *"}, {"input": "3 1\n 1 2\n 1 2\n 1 2", "output": "2\n \n\n* * *"}, {"input": "6 6\n 1 6\n 1 6\n 1 5\n 1 5\n 2 6\n 2 6", "output": "2"}] |
Print the minimum required number of additional chairs.
* * * | s036392149 | Wrong Answer | p03686 | Input is given from Standard Input in the following format:
N M
L_1 R_1
:
L_N R_N | #!/usr/bin/env python3
import heapq
INF = 10**9
class SegTreeX:
def __init__(self, n):
k = 1
while k < n:
k *= 2
self.n = k
self.dat = [0] * (k * 2)
self.pos = [i - (k - 1) for i in range(k * 2)]
def update(self, i, x):
i += self.n - 1
self.dat[i] = x
while 0 < i:
i = (i - 1) // 2
d1 = self.dat[i * 2 + 1]
d2 = self.dat[i * 2 + 2]
if d1 <= d2:
self.dat[i] = d1
self.pos[i] = self.pos[i * 2 + 1]
else:
self.dat[i] = d2
self.pos[i] = self.pos[i * 2 + 2]
def query(self, a, b, k=0, l=0, r=-1):
if r < 0:
r = self.n
if r <= a or b <= l:
return INF, -1
if a <= l and r <= b:
return self.dat[k], self.pos[k]
else:
vl, pl = self.query(a, b, k * 2 + 1, l, (l + r) // 2)
vr, pr = self.query(a, b, k * 2 + 2, (l + r) // 2, r)
if vl <= vr:
return vl, pl
else:
return vr, pr
def solve(n, m, a):
a.sort()
ans = 0
q = []
ol = -1
seg = SegTreeX(m + 1)
for i in range(n):
li, ri = a[i]
if li != ol and 0 <= ol:
while ol < len(q):
rj = heapq.heappop(q)
if m < rj:
ans += 1
else:
v, p = seg.query(rj, m + 1)
if p < 0 or v == 1:
ans += 1
else:
seg.update(p, 1)
heapq.heappush(q, ri)
ol = li
while ol < len(q):
rj = heapq.heappop(q)
if m < rj:
ans += 1
else:
v, p = seg.query(rj, m + 1)
if p < 0 or v == 1:
ans += 1
else:
seg.update(p, 1)
if ans < n - m:
ans = n - m
return ans
def main():
n, m = input().split()
n = int(n)
m = int(m)
a = []
for _ in range(n):
li, ri = input().split()
li = int(li)
ri = int(ri)
a.append((li, ri))
print(solve(n, m, a))
if __name__ == "__main__":
main()
| Statement
There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i
≤ M) is i.
N people of the Takahashi clan played too much games, and they are all
suffering from backaches. They need to sit in chairs and rest, but they are
particular about which chairs they sit in. Specifically, the i-th person
wishes to sit in a chair whose coordinate is not greater than L_i, or not less
than R_i. Naturally, only one person can sit in the same chair.
It may not be possible for all of them to sit in their favorite chairs, if
nothing is done. Aoki, who cares for the health of the people of the Takahashi
clan, decides to provide additional chairs so that all of them can sit in
chairs at their favorite positions.
Additional chairs can be placed at arbitrary real coordinates. Find the
minimum required number of additional chairs. | [{"input": "4 4\n 0 3\n 2 3\n 1 3\n 3 4", "output": "0\n \n\nThe four people can sit in chairs at the coordinates 3, 2, 1 and 4,\nrespectively, and no more chair is needed.\n\n* * *"}, {"input": "7 6\n 0 7\n 1 5\n 3 6\n 2 7\n 1 6\n 2 6\n 3 7", "output": "2\n \n\nIf we place additional chairs at the coordinates 0 and 2.5, the seven people\ncan sit at coordinates 0, 5, 3, 2, 6, 1 and 2.5, respectively.\n\n* * *"}, {"input": "3 1\n 1 2\n 1 2\n 1 2", "output": "2\n \n\n* * *"}, {"input": "6 6\n 1 6\n 1 6\n 1 5\n 1 5\n 2 6\n 2 6", "output": "2"}] |
Print the minimum required number of additional chairs.
* * * | s688886827 | Runtime Error | p03686 | Input is given from Standard Input in the following format:
N M
L_1 R_1
:
L_N R_N | # https://tjkendev.github.io/procon-library/python/max_flow/dinic.html
# Dinic's algorithm
from collections import deque
class Dinic:
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap):
forward = [to, cap, None]
forward[2] = backward = [fr, 0, forward]
self.G[fr].append(forward)
self.G[to].append(backward)
def add_multi_edge(self, v1, v2, cap1, cap2):
edge1 = [v2, cap1, None]
edge1[2] = edge2 = [v1, cap2, edge1]
self.G[v1].append(edge1)
self.G[v2].append(edge2)
def bfs(self, s, t):
self.level = level = [None] * self.N
deq = deque([s])
level[s] = 0
G = self.G
while deq:
v = deq.popleft()
lv = level[v] + 1
for w, cap, _ in G[v]:
if cap and level[w] is None:
level[w] = lv
deq.append(w)
return level[t] is not None
def dfs(self, v, t, f):
if v == t:
return f
level = self.level
for e in self.it[v]:
w, cap, rev = e
if cap and level[v] < level[w]:
d = self.dfs(w, t, min(f, cap))
if d:
e[1] -= d
rev[1] += d
return d
return 0
def flow(self, s, t):
flow = 0
INF = 10**9 + 7
G = self.G
while self.bfs(s, t):
(*self.it,) = map(iter, self.G)
f = INF
while f:
f = self.dfs(s, t, INF)
flow += f
return flow
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, m, *lr = map(int, read().split())
mp = iter(lr)
D = Dinic(n + 3 * m + 8)
s = n + 3 * m + 8 - 2
g = n + 3 * m + 8 - 1
for i in range(n + m + 2, n + 2 * m + 3):
D.add_edge(i, i - m - 2, 1)
D.add_edge(i, i + 1, 1)
D.add_edge(n + 2 * m + 3, n + m + 1, 1)
for i in range(n + 2 * m + 4, n + 3 * m + 5):
D.add_edge(i, i - 2 * m - 4, 1)
D.add_edge(i + 1, i, 1)
D.add_edge(n + 3 * m + 5, n + m + 1, 1)
for i in range(n):
D.add_edge(s, i, 1)
for i in range(n + 1, n + m + 1):
D.add_edge(i, g, 1)
for i, (l, r) in enumerate(zip(mp, mp)):
D.add_edge(i, n + 2 * m + 4 + l, 1)
D.add_edge(i, n + m + 2 + r, 1)
ans = D.flow(s, g)
print(n - ans)
| Statement
There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i
≤ M) is i.
N people of the Takahashi clan played too much games, and they are all
suffering from backaches. They need to sit in chairs and rest, but they are
particular about which chairs they sit in. Specifically, the i-th person
wishes to sit in a chair whose coordinate is not greater than L_i, or not less
than R_i. Naturally, only one person can sit in the same chair.
It may not be possible for all of them to sit in their favorite chairs, if
nothing is done. Aoki, who cares for the health of the people of the Takahashi
clan, decides to provide additional chairs so that all of them can sit in
chairs at their favorite positions.
Additional chairs can be placed at arbitrary real coordinates. Find the
minimum required number of additional chairs. | [{"input": "4 4\n 0 3\n 2 3\n 1 3\n 3 4", "output": "0\n \n\nThe four people can sit in chairs at the coordinates 3, 2, 1 and 4,\nrespectively, and no more chair is needed.\n\n* * *"}, {"input": "7 6\n 0 7\n 1 5\n 3 6\n 2 7\n 1 6\n 2 6\n 3 7", "output": "2\n \n\nIf we place additional chairs at the coordinates 0 and 2.5, the seven people\ncan sit at coordinates 0, 5, 3, 2, 6, 1 and 2.5, respectively.\n\n* * *"}, {"input": "3 1\n 1 2\n 1 2\n 1 2", "output": "2\n \n\n* * *"}, {"input": "6 6\n 1 6\n 1 6\n 1 5\n 1 5\n 2 6\n 2 6", "output": "2"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s546752933 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | N, L = list(map(int, input().split()))
app_taste = list(range(L, L + N))
bite_apple = L
for i in app_taste:
if abs(bite_apple) > abs(i):
bite_apple = i
print(sum(app_taste) - bite_apple)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s236061738 | Runtime Error | p02994 | Input is given from Standard Input in the following format:
N L | (n, l) = map(int, input().split())
d = [l + i for i in range(n)]
c = [abs(i) for i in d.copy()]
nearest0 = c.index(min(c))
d.remove(d[nearest0])
ans = sum(d)
print(ans)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s171921654 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | n, l = map(int, input().split())
ans = list(i + l for i in range(n))
m = 10**10
for i in ans:
if abs(m) > abs(i):
m = i
print(sum(ans) - m)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s078448715 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | # !/usr/bin/env python3
# encoding: UTF-8
# Modified: <22/Jun/2019 05:38:20 PM>
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology (IIIT), Gwalior
import sys
import os
from io import IOBase, BytesIO
def main():
n, l = get_ints()
arr = [0] * n
for i in range(n):
arr[i] = l + i
arr.sort()
# print(arr)
tmp = [(abs(arr[i]), i) for i in range(n)]
tmp.sort()
# print(tmp)
ans = 0
for i in range(1, n):
ans += arr[tmp[i][1]]
print(ans)
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill():
pass
return super(FastIO, self).read()
def readline(self):
while self.newlines == 0:
s = self._fill()
self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
py2 = round(0.5)
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2 == 1:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline().strip()
if __name__ == "__main__":
main()
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s012224990 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | import sys
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
def YesNo(x):
return "Yes" if x else "No"
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return input()
def main():
N, L = LI()
li = list(range(L, N + L))
if 0 in li:
ans = sum(li)
elif li[-1] < 0:
ans = sum(li[:-1])
else:
ans = sum(li[1:])
return ans
print(main())
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s985259213 | Wrong Answer | p02994 | Input is given from Standard Input in the following format:
N L | N, L = [s for s in input().split()]
apples_taste = []
abs_apples_taste = []
for i in range(int(N)):
apples_taste.append(i + int(L))
abs_apples_taste.append(abs(i + int(L)))
abs_apples_taste.sort()
print(sum(apples_taste) - abs_apples_taste[0])
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s765936032 | Runtime Error | p02994 | Input is given from Standard Input in the following format:
N L | N, L = [int(x) for x in input().split()]
A = list(range(L, L + N))
Min = 100
for i in A:
if Min > abs(i):
youso = i
Min = abs(i)
A.remove(youso)
print(sum(A))
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s584749980 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | N, L = map(int, input().split())
c = 400
k = 400
wa = 0
for i in range(N):
a = L + i
wa += a
if abs(a) < c:
c = abs(a)
k = a
print(wa - k)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s684735235 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | N, L = input().split()
N, L = int(N), int(L)
print(sum(sorted([i for i in range(L, L + N)], key=abs)[1:]))
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s885559949 | Runtime Error | p02994 | Input is given from Standard Input in the following format:
N L | n, l = map(int, input())
print(n * (l - 1) + n * (n + 1) / 2 - l)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s706307909 | Wrong Answer | p02994 | Input is given from Standard Input in the following format:
N L | N, L = [int(s) for s in input().split(" ")]
tastes = [(L + i - 1) for i in range(1, N + 1)]
min = min(tastes)
tastes.remove(min)
print(sum(tastes))
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s108025239 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | n, l = map(int, input().split())
apples = list()
apple_total = 0
for i in range(1, n + 1):
apples.append(l + i - 1)
apple_total += l + i - 1
if 0 in apples:
print(apple_total)
else:
if apple_total > 0:
apple_total -= apples[0]
print(apple_total)
else:
apple_total -= apples[-1]
print(apple_total)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s132476895 | Wrong Answer | p02994 | Input is given from Standard Input in the following format:
N L | intCount, intBase = map(int, input().split())
intSum = 0
# everythins is minus
if intBase + intCount - 1 < 0:
intSum += -1 * (intBase + intCount - 1)
# everything is plus
elif intBase > 1:
intSum -= intBase
for intTmp in range(1, intCount + 1):
intSum += intBase + intTmp - 1
print(intSum)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s770056835 | Runtime Error | p02994 | Input is given from Standard Input in the following format:
N L | n = [int(i) for i in input().split()]
array = []
abs_array = []
for i in range(n[0]):
array.append(n[1] + i - 1)
abs_array.append(abs(n[1] + i - 1))
abs_array = abs_array.sort()
if abs_array[0] in array == True:
print(sum(array) - abs_array[0])
else:
print(sum(array) + abs_array[0])
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s511476304 | Wrong Answer | p02994 | Input is given from Standard Input in the following format:
N L | x, y = input().split()
z = int(x)
g = int(y)
taste = []
ataste = []
num = 0
while z - 1 >= num:
num += 1
num2 = g + num - 1
if num2 < 0:
num3 = num2 * -1
else:
num3 = num2
taste.append(num2)
ataste.append(num3)
n = sum(taste)
m = min(ataste)
print(n - m)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s594657871 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | N, L = [int(nl) for nl in input().split()]
T = []
for n in range(N):
T.append(L + n)
T_abs = [abs(t) for t in T]
mn_T_abs = min(T_abs)
idx_mn_T_abs = T_abs.index(mn_T_abs)
T.pop(idx_mn_T_abs)
ans = sum(T)
print(ans)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s330060737 | Wrong Answer | p02994 | Input is given from Standard Input in the following format:
N L | n, L = map(int, input().split())
N = 0
G = 0
for i in range(1, n):
N += i + L - 1
NN = N
for i in range(1, n):
DD = NN - (L + i - 1)
if DD > G:
G = DD
print(G)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s734717196 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | n, l = map(int, input().split())
key = 0
Min = 1000
for i in range(n):
key += l + i
if abs(l + i) < abs(Min):
Min = l + i
print(key - Min)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s737627897 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | n, l = map(int, input().split())
n_l = [0] * n
flag = "ng"
for i in range(n):
n_l[i] = l + (i + 1) - 1
if n_l[i] == 0:
flag = "ok"
if flag == "ok":
print(sum(n_l))
exit()
n_l_min = min(n_l)
if n_l_min < 0:
print(sum(n_l) - max(n_l))
exit()
print(sum(n_l) - n_l_min)
# print(n_l)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s490874137 | Accepted | p02994 | Input is given from Standard Input in the following format:
N L | p, q = input().split()
a, b = (int(p), int(q))
key_num = 0
azi_list = []
for i in range(a):
azi_list.append(b + i)
if key_num in azi_list:
print(sum(azi_list))
elif key_num not in azi_list and azi_list[0] > 0:
print(sum(azi_list[1:]))
else:
print(sum(azi_list[:-1]))
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s606962256 | Wrong Answer | p02994 | Input is given from Standard Input in the following format:
N L | import sys
B, A = map(int, input().split()) # list() を使っても構いません
abs_A = abs(A)
# print (abs_A)
if A > 1: ##Aは正か否か
flag = True
else:
flag = False
result = 0
temp = A
for i in range(B):
result = result + temp
temp = temp + 1
# print("first result---")
# print(result)
# print("flag---")
# print(flag)
if B == 2:
if A > 0:
result = A + 1
print(result)
sys.exit()
elif A == 0:
result = A + 1
print(result)
sys.exit()
else:
result = A
print(result)
sys.exit()
if abs_A > B:
if flag:
result = result - A
print("pattern A")
print(result)
else:
print("pattern B")
result = result - temp + 1
print(result)
elif abs_A == B:
if flag:
result = result - A
print("pattern C")
print(result)
else:
print("pattern D")
print(result)
else:
if flag:
print("pattern E")
result = result - A
print(result)
else:
print("pattern F")
print(result)
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s509662788 | Wrong Answer | p02994 | Input is given from Standard Input in the following format:
N L | n, l = map(int, input().split())
n_flavor = []
for i in range(1, n + 1):
flavor = l + i - 1
n_flavor.append(flavor)
rem_abs = abs(n_flavor[0])
rem = n_flavor[0]
for j in range(1, n):
if rem_abs > abs(n_flavor[j]):
rem = abs(n_flavor[j])
rem = n_flavor[j]
else:
continue
n_flavor.remove(rem)
print(sum(n_flavor))
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s475734166 | Wrong Answer | p02994 | Input is given from Standard Input in the following format:
N L | N, L = map(int, input().split())
S = []
for i in range(L, N + L):
S.append(i)
ans = []
p = []
mini = False
plu = False
for j in S:
ans.append(sum(S) - sum(S) - j)
p.append(sum(S) - j)
if sum(S) - j > 0:
plu = True
if sum(S) - j < 0:
mini = True
if plu and mini:
if 0 in ans:
print(p[ans.index(0)])
elif plu:
print(p[ans.index(max(ans))])
elif mini:
print(p[ans.index(min(ans))])
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
Find the flavor of the apple pie made of the remaining N-1 apples when you
optimally choose the apple to eat.
* * * | s806225738 | Runtime Error | p02994 | Input is given from Standard Input in the following format:
N L | N, L = (int(nl) for nl in input().split())
tastes = [L + i - 1 for i in range(1, N + 1)]
min_taste = 0
min_taste_abs = 100
for taste in tastes:
if min_taste_abs > abs(taste):
min_taste_abs = abs(taste)
min_taste = taste
min_taste_index = tastes.index(min_taste)
print(sum(tastes[:min_taste_index] + tastes[min_taste_index + 1 :]))
| Statement
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The
_flavor_ of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the
apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, but being hungry
tempts you to eat one of them, which can no longer be used to make the apple
pie.
You want to make an apple pie that is as similar as possible to the one that
you planned to make. Thus, you will choose the apple to eat so that the flavor
of the apple pie made of the remaining N-1 apples will have the smallest
possible absolute difference from the flavor of the apple pie made of all the
N apples.
Find the flavor of the apple pie made of the remaining N-1 apples when you
choose the apple to eat as above.
We can prove that this value is uniquely determined. | [{"input": "5 2", "output": "18\n \n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively.\nThe optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\n* * *"}, {"input": "3 -1", "output": "0\n \n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal\nchoice is to eat Apple 2, so the answer is (-1)+1=0.\n\n* * *"}, {"input": "30 -50", "output": "-1044"}] |
If Alice will win, print `Alice`; if Bob will win, print `Bob`.
* * * | s016930313 | Wrong Answer | p03491 | Input is given from Standard Input in the following format:
N L
s_1
s_2
:
s_N | N, L = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()
st = []
for s in S:
st.append(s)
while len(st) >= 2:
s1, s2 = st[-2:]
if s1[:-1] == s2[:-1]:
del st[-2:]
st.append(s1[:-1])
else:
break
if st[0] == "":
print("Bob")
exit()
# st = list(map(list, st))
def add1(s):
if s.count("0") == 0:
return ["0"] * len(s)
i = 1
while s[-i] == "1":
i += 1
return s[:-i] + ["1"] + ["0"] * (i - 1)
s_p = st[0]
from collections import defaultdict
dd_ans = defaultdict(bool)
for i, c in enumerate(s_p):
if c == "1":
level, m = divmod(L - i - 1, 3)
dd_ans[(level, m % 2)] ^= True
for i, c in enumerate(st[-1]):
if c == "0":
level, m = divmod(L - i - 1, 3)
dd_ans[(level, m % 2)] ^= True
for s in st[1:]:
# print(ans)
s_copy = s
if len(s_p) < len(s):
s_p += "1" * (len(s) - len(s_p))
else:
s += "0" * (len(s_p) - len(s))
a = 0
f = True
for i, (c1, c2) in enumerate(zip(s_p, s)):
if f:
if c1 != c2:
f = False
else:
if c1 == "0":
level, m = divmod(L - i - 1, 3)
dd_ans[(level, m % 2)] ^= True
if c2 == "1":
level, m = divmod(L - i - 1, 3)
dd_ans[(level, m % 2)] ^= True
# ans ^= a
s_p = s_copy
print("Alice" if sum(dd_ans.values()) else "Bob")
| Statement
For strings s and t, we will say that s and t are _prefix-free_ when neither
is a prefix of the other.
Let L be a positive integer. A set of strings S is a _good string set_ when
the following conditions hold true:
* Each string in S has a length between 1 and L (inclusive) and consists of the characters `0` and `1`.
* Any two distinct strings in S are prefix-free.
We have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will
play a game against each other. They will alternately perform the following
operation, starting from Alice:
* Add a new string to S. After addition, S must still be a good string set.
The first player who becomes unable to perform the operation loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "2 2\n 00\n 01", "output": "Alice\n \n\nIf Alice adds `1`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 2\n 00\n 11", "output": "Bob\n \n\nThere are two strings that Alice can add on the first turn: `01` and `10`. In\ncase she adds `01`, if Bob add `10`, she will be unable to add a new string.\nAlso, in case she adds `10`, if Bob add `01`, she will be unable to add a new\nstring.\n\n* * *"}, {"input": "3 3\n 0\n 10\n 110", "output": "Alice\n \n\nIf Alice adds `111`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 1\n 0\n 1", "output": "Bob\n \n\nAlice is unable to add a new string on the first turn.\n\n* * *"}, {"input": "1 2\n 11", "output": "Alice\n \n\n* * *"}, {"input": "2 3\n 101\n 11", "output": "Bob"}] |
If Alice will win, print `Alice`; if Bob will win, print `Bob`.
* * * | s900602390 | Runtime Error | p03491 | Input is given from Standard Input in the following format:
N L
s_1
s_2
:
s_N | import sys
readline = sys.stdin.readline
N, L = map(int, readline().split())
node = set([1])
for _ in range(N):
S = list(map(int, readline().strip()))
ls = len(S)
pre = 1
for s in S:
vn = 2*pre + s
if vn not in node:
node.add(vn)
pre = vn
cnt = 0
for d in node:
h = 0
if 2*d in node:
h += 1
if 2*d+1 in node:
h += 1
if h == 1:
depth = L-d.bit_length()+1
cnt ^= (-depth&depth)
print('Alice' if cnt else 'Bob')
| Statement
For strings s and t, we will say that s and t are _prefix-free_ when neither
is a prefix of the other.
Let L be a positive integer. A set of strings S is a _good string set_ when
the following conditions hold true:
* Each string in S has a length between 1 and L (inclusive) and consists of the characters `0` and `1`.
* Any two distinct strings in S are prefix-free.
We have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will
play a game against each other. They will alternately perform the following
operation, starting from Alice:
* Add a new string to S. After addition, S must still be a good string set.
The first player who becomes unable to perform the operation loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "2 2\n 00\n 01", "output": "Alice\n \n\nIf Alice adds `1`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 2\n 00\n 11", "output": "Bob\n \n\nThere are two strings that Alice can add on the first turn: `01` and `10`. In\ncase she adds `01`, if Bob add `10`, she will be unable to add a new string.\nAlso, in case she adds `10`, if Bob add `01`, she will be unable to add a new\nstring.\n\n* * *"}, {"input": "3 3\n 0\n 10\n 110", "output": "Alice\n \n\nIf Alice adds `111`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 1\n 0\n 1", "output": "Bob\n \n\nAlice is unable to add a new string on the first turn.\n\n* * *"}, {"input": "1 2\n 11", "output": "Alice\n \n\n* * *"}, {"input": "2 3\n 101\n 11", "output": "Bob"}] |
If Alice will win, print `Alice`; if Bob will win, print `Bob`.
* * * | s587256664 | Wrong Answer | p03491 | Input is given from Standard Input in the following format:
N L
s_1
s_2
:
s_N | class Node:
def __init__(self):
self.lt = None
self.rt = None
self.dep = None
class Trie:
def __init__(self):
self.root = Node()
self.root.dep = 0
def add(self, string):
node = self.root
for s in string:
if s == "0":
if node.lt is None:
node.lt = Node()
node.lt.dep = node.dep + 1
node = node.lt
else:
if node.rt is None:
node.rt = Node()
node.rt.dep = node.dep + 1
node = node.rt
N, L = map(int, input().split())
trie = Trie()
for _ in range(N):
s = input()
trie.add(s)
subgame = []
stack = [trie.root]
while stack:
node = stack.pop()
if node.lt is None and node.rt is None:
continue
elif node.rt is None:
stack.append(node.lt)
subgame.append(L - node.dep)
elif node.lt is None:
stack.append(node.rt)
subgame.append(L - node.dep)
else:
stack.append(node.lt)
stack.append(node.rt)
def grundy(n):
if n == 0:
return 0
if n % 2 == 1:
return 1
if n == 2 ** (n.bit_length() - 1):
return n
return grundy(n - 2 ** (n.bit_length() - 2))
res = 0
for l in subgame:
res ^= grundy(l)
print("Alice" if res != 0 else "Bob")
| Statement
For strings s and t, we will say that s and t are _prefix-free_ when neither
is a prefix of the other.
Let L be a positive integer. A set of strings S is a _good string set_ when
the following conditions hold true:
* Each string in S has a length between 1 and L (inclusive) and consists of the characters `0` and `1`.
* Any two distinct strings in S are prefix-free.
We have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will
play a game against each other. They will alternately perform the following
operation, starting from Alice:
* Add a new string to S. After addition, S must still be a good string set.
The first player who becomes unable to perform the operation loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "2 2\n 00\n 01", "output": "Alice\n \n\nIf Alice adds `1`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 2\n 00\n 11", "output": "Bob\n \n\nThere are two strings that Alice can add on the first turn: `01` and `10`. In\ncase she adds `01`, if Bob add `10`, she will be unable to add a new string.\nAlso, in case she adds `10`, if Bob add `01`, she will be unable to add a new\nstring.\n\n* * *"}, {"input": "3 3\n 0\n 10\n 110", "output": "Alice\n \n\nIf Alice adds `111`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 1\n 0\n 1", "output": "Bob\n \n\nAlice is unable to add a new string on the first turn.\n\n* * *"}, {"input": "1 2\n 11", "output": "Alice\n \n\n* * *"}, {"input": "2 3\n 101\n 11", "output": "Bob"}] |
If Alice will win, print `Alice`; if Bob will win, print `Bob`.
* * * | s067657731 | Wrong Answer | p03491 | Input is given from Standard Input in the following format:
N L
s_1
s_2
:
s_N | from collections import defaultdict
def solve(l, ss):
xor = 0
for d in range(min(ss), l + 1):
sl = ss[d]
sl.sort()
while sl:
s = sl.pop()
ps = s[:-1]
ss[d + 1].append(ps)
if s[-1] == "1":
if sl and sl[-1][:-1] == ps:
sl.pop()
else:
xor ^= d & -d
del ss[d]
return xor
n, l = map(int, input().split())
ss = defaultdict(list)
for s in (input() for _ in range(n)):
ss[l - len(s) + 1].append(s)
print("Alice" if solve(l, ss) else "Bob")
| Statement
For strings s and t, we will say that s and t are _prefix-free_ when neither
is a prefix of the other.
Let L be a positive integer. A set of strings S is a _good string set_ when
the following conditions hold true:
* Each string in S has a length between 1 and L (inclusive) and consists of the characters `0` and `1`.
* Any two distinct strings in S are prefix-free.
We have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will
play a game against each other. They will alternately perform the following
operation, starting from Alice:
* Add a new string to S. After addition, S must still be a good string set.
The first player who becomes unable to perform the operation loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "2 2\n 00\n 01", "output": "Alice\n \n\nIf Alice adds `1`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 2\n 00\n 11", "output": "Bob\n \n\nThere are two strings that Alice can add on the first turn: `01` and `10`. In\ncase she adds `01`, if Bob add `10`, she will be unable to add a new string.\nAlso, in case she adds `10`, if Bob add `01`, she will be unable to add a new\nstring.\n\n* * *"}, {"input": "3 3\n 0\n 10\n 110", "output": "Alice\n \n\nIf Alice adds `111`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 1\n 0\n 1", "output": "Bob\n \n\nAlice is unable to add a new string on the first turn.\n\n* * *"}, {"input": "1 2\n 11", "output": "Alice\n \n\n* * *"}, {"input": "2 3\n 101\n 11", "output": "Bob"}] |
If Alice will win, print `Alice`; if Bob will win, print `Bob`.
* * * | s846754209 | Runtime Error | p03491 | Input is given from Standard Input in the following format:
N L
s_1
s_2
:
s_N | N, L = map(int, input().split())
class Node:
def __init__(self, depth=0):
self.parent = None
self.children = {}
self.depth = depth
def add(self, n):
self.children[n] = Node(self.depth + 1)
def has(self, n):
return n in self.children
t = Node()
for i in range(N):
s = input()
nt = t
for c in s:
if not nt.has(c):
nt.add(c)
nt = nt.children[c]
def solve(node):
global N, L
ans = 0
f = lambda d: (L - d) & -(L - d)
if node.has("0"):
ans ^= solve(node.children["0"])
else:
ans ^= f(node.depth)
if node.has("1"):
ans ^= solve(node.children["1"])
else:
ans ^= f(node.depth)
return ans
ans = solve(t)
if ans == 0:
print("Bob")
else:
print("Alice")
| Statement
For strings s and t, we will say that s and t are _prefix-free_ when neither
is a prefix of the other.
Let L be a positive integer. A set of strings S is a _good string set_ when
the following conditions hold true:
* Each string in S has a length between 1 and L (inclusive) and consists of the characters `0` and `1`.
* Any two distinct strings in S are prefix-free.
We have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will
play a game against each other. They will alternately perform the following
operation, starting from Alice:
* Add a new string to S. After addition, S must still be a good string set.
The first player who becomes unable to perform the operation loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "2 2\n 00\n 01", "output": "Alice\n \n\nIf Alice adds `1`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 2\n 00\n 11", "output": "Bob\n \n\nThere are two strings that Alice can add on the first turn: `01` and `10`. In\ncase she adds `01`, if Bob add `10`, she will be unable to add a new string.\nAlso, in case she adds `10`, if Bob add `01`, she will be unable to add a new\nstring.\n\n* * *"}, {"input": "3 3\n 0\n 10\n 110", "output": "Alice\n \n\nIf Alice adds `111`, Bob will be unable to add a new string.\n\n* * *"}, {"input": "2 1\n 0\n 1", "output": "Bob\n \n\nAlice is unable to add a new string on the first turn.\n\n* * *"}, {"input": "1 2\n 11", "output": "Alice\n \n\n* * *"}, {"input": "2 3\n 101\n 11", "output": "Bob"}] |
Print the information of each node in the following format:
node _id_ : parent = _p_ , sibling = _s_ , degree = _deg_ , depth = _dep_ ,
height = _h_ , _type_
_p_ is ID of its parent. If the node does not have a parent, print -1.
_s_ is ID of its sibling. If the node does not have a sibling, print -1.
_deg_ , _dep_ and _h_ are the number of children, depth and height of the node
respectively.
_type_ is a type of nodes represented by a string (root, internal node or
leaf. If the root can be considered as a leaf or an internal node, print root.
Please follow the format presented in a sample output below. | s259407241 | Accepted | p02280 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node is given in the following
format:
_id left right_
_id_ is the node ID, _left_ is ID of the left child and _right_ is ID of the
right child. If the node does not have the left (right) child, the
_left_(_right_) is indicated by -1. | from enum import IntEnum
class Attrs(IntEnum):
LEFT = 0
RIGHT = 1
PARENT = 2
SIBLING = 3
DEPTH = 4
HEIGHT = 5
def parents(nodes):
for i, node in enumerate(nodes):
if node[Attrs.LEFT] != -1:
nodes[node[Attrs.LEFT]][Attrs.PARENT] = i
nodes[node[Attrs.LEFT]][Attrs.SIBLING] = node[Attrs.RIGHT]
if node[Attrs.RIGHT] != -1:
nodes[node[Attrs.RIGHT]][Attrs.PARENT] = i
nodes[node[Attrs.RIGHT]][Attrs.SIBLING] = node[Attrs.LEFT]
def depth_and_heights(nodes):
def depth(n):
if nodetype(n) != "root" and n[Attrs.DEPTH] == 0:
n[Attrs.DEPTH] = depth(nodes[n[Attrs.PARENT]]) + 1
return n[Attrs.DEPTH]
def height(n):
if nodetype(n) != "leaf" and n[Attrs.HEIGHT] == 0:
if n[Attrs.LEFT] != -1:
lh = height(nodes[n[Attrs.LEFT]])
else:
lh = -1
if n[Attrs.RIGHT] != -1:
rh = height(nodes[n[Attrs.RIGHT]])
else:
rh = -1
n[Attrs.HEIGHT] = max(lh, rh) + 1
return n[Attrs.HEIGHT]
for node in nodes:
node[Attrs.DEPTH] = depth(node)
node[Attrs.HEIGHT] = height(node)
def degree(node):
if node[Attrs.LEFT] != -1 and node[Attrs.RIGHT] != -1:
return 2
elif node[Attrs.LEFT] != -1:
return 1
elif node[Attrs.RIGHT] != -1:
return 1
else:
return 0
def nodetype(node):
if node[Attrs.PARENT] == -1:
return "root"
elif node[Attrs.LEFT] == -1 and node[Attrs.RIGHT] == -1:
return "leaf"
else:
return "internal node"
def print_tree(ns):
parents(ns)
depth_and_heights(ns)
for nid, n in enumerate(ns):
print(
(
"node {}: parent = {}, sibling = {}, degree = {}, "
+ "depth = {}, height = {}, {}"
).format(
nid,
n[Attrs.PARENT],
n[Attrs.SIBLING],
degree(n),
n[Attrs.DEPTH],
n[Attrs.HEIGHT],
nodetype(n),
)
)
def run():
n = int(input())
nodes = [None] * n
for i in range(n):
nodeid, *attrs = [int(i) for i in input().split()]
attrs.extend([-1, -1, 0, 0])
nodes[nodeid] = attrs
print_tree(nodes)
if __name__ == "__main__":
run()
| Binary Tree
A rooted binary tree is a tree with a root node in which every node has at
most two children.
Your task is to write a program which reads a rooted binary tree _T_ and
prints the following information for each node _u_ of _T_ :
* node ID of _u_
* parent of _u_
* sibling of _u_
* the number of children of _u_
* depth of _u_
* height of _u_
* node type (root, internal node or leaf)
If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_
have the same parent, we say _u_ is a sibling of _v_ (vice versa).
The height of a node in a tree is the number of edges on the longest simple
downward path from the node to a leaf.
Here, the given binary tree consists of _n_ nodes and evey node has a unique
ID from 0 to _n_ -1. | [{"input": "9\n 0 1 4\n 1 2 3\n 2 -1 -1\n 3 -1 -1\n 4 5 8\n 5 6 7\n 6 -1 -1\n 7 -1 -1\n 8 -1 -1", "output": "node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root\n node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node\n node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf\n node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf\n node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node\n node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node\n node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf\n node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf\n node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf\n \n\n"}] |
Print the information of each node in the following format:
node _id_ : parent = _p_ , sibling = _s_ , degree = _deg_ , depth = _dep_ ,
height = _h_ , _type_
_p_ is ID of its parent. If the node does not have a parent, print -1.
_s_ is ID of its sibling. If the node does not have a sibling, print -1.
_deg_ , _dep_ and _h_ are the number of children, depth and height of the node
respectively.
_type_ is a type of nodes represented by a string (root, internal node or
leaf. If the root can be considered as a leaf or an internal node, print root.
Please follow the format presented in a sample output below. | s306973570 | Accepted | p02280 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node is given in the following
format:
_id left right_
_id_ is the node ID, _left_ is ID of the left child and _right_ is ID of the
right child. If the node does not have the left (right) child, the
_left_(_right_) is indicated by -1. | # Tree - Rooted Trees
class Node:
def is_leaf(self):
return self.depth > 0 and len(self.degree) == 0
def __init__(self, id):
self.id = id
self.parent = None
self.sibling = None
self.degree = []
self.depth = 0
self.height = 0
def __str__(self):
p = self.parent.id if self.parent else -1
s = self.sibling.id if self.sibling else -1
d = len(self.degree)
typ = "root"
if self.depth > 0:
typ = "internal node"
if d == 0 and self.depth > 0:
typ = "leaf"
h = self.height
return "node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}".format(
self.id, p, s, d, self.depth, h, typ
)
def calc_cld_depth(nd):
cs = nd.degree
for c in cs:
c.depth = nd.depth + 1
calc_cld_depth(c)
n = int(input())
rbt = [Node(i) for i in range(n)]
for i in range(n):
id, left, right = map(int, input().split())
tgt = rbt[id]
l, r = None, None
if not left == -1:
l = rbt[left]
l.depth += tgt.depth + 1
l.parent = tgt
calc_cld_depth(l)
tgt.degree.append(l)
if not right == -1:
r = rbt[right]
r.depth += tgt.depth + 1
r.parent = tgt
calc_cld_depth(r)
tgt.degree.append(r)
if (not left == -1) and (not right == -1):
l.sibling, r.sibling = r, l
if left == -1 and right == -1:
if tgt.parent:
tgt.depth = tgt.parent.depth + 1
# calc height
for c in rbt:
h = 0
if c.is_leaf():
c.height = h
p = c.parent
while p:
h += 1
if p.height < h:
p.height = h
p = p.parent
for t in rbt:
print(t)
| Binary Tree
A rooted binary tree is a tree with a root node in which every node has at
most two children.
Your task is to write a program which reads a rooted binary tree _T_ and
prints the following information for each node _u_ of _T_ :
* node ID of _u_
* parent of _u_
* sibling of _u_
* the number of children of _u_
* depth of _u_
* height of _u_
* node type (root, internal node or leaf)
If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_
have the same parent, we say _u_ is a sibling of _v_ (vice versa).
The height of a node in a tree is the number of edges on the longest simple
downward path from the node to a leaf.
Here, the given binary tree consists of _n_ nodes and evey node has a unique
ID from 0 to _n_ -1. | [{"input": "9\n 0 1 4\n 1 2 3\n 2 -1 -1\n 3 -1 -1\n 4 5 8\n 5 6 7\n 6 -1 -1\n 7 -1 -1\n 8 -1 -1", "output": "node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root\n node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node\n node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf\n node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf\n node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node\n node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node\n node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf\n node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf\n node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf\n \n\n"}] |
Print the information of each node in the following format:
node _id_ : parent = _p_ , sibling = _s_ , degree = _deg_ , depth = _dep_ ,
height = _h_ , _type_
_p_ is ID of its parent. If the node does not have a parent, print -1.
_s_ is ID of its sibling. If the node does not have a sibling, print -1.
_deg_ , _dep_ and _h_ are the number of children, depth and height of the node
respectively.
_type_ is a type of nodes represented by a string (root, internal node or
leaf. If the root can be considered as a leaf or an internal node, print root.
Please follow the format presented in a sample output below. | s622819458 | Wrong Answer | p02280 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node is given in the following
format:
_id left right_
_id_ is the node ID, _left_ is ID of the left child and _right_ is ID of the
right child. If the node does not have the left (right) child, the
_left_(_right_) is indicated by -1. | Binary Tree
A rooted binary tree is a tree with a root node in which every node has at
most two children.
Your task is to write a program which reads a rooted binary tree _T_ and
prints the following information for each node _u_ of _T_ :
* node ID of _u_
* parent of _u_
* sibling of _u_
* the number of children of _u_
* depth of _u_
* height of _u_
* node type (root, internal node or leaf)
If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_
have the same parent, we say _u_ is a sibling of _v_ (vice versa).
The height of a node in a tree is the number of edges on the longest simple
downward path from the node to a leaf.
Here, the given binary tree consists of _n_ nodes and evey node has a unique
ID from 0 to _n_ -1. | [{"input": "9\n 0 1 4\n 1 2 3\n 2 -1 -1\n 3 -1 -1\n 4 5 8\n 5 6 7\n 6 -1 -1\n 7 -1 -1\n 8 -1 -1", "output": "node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root\n node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node\n node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf\n node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf\n node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node\n node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node\n node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf\n node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf\n node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf\n \n\n"}] | |
Print the information of each node in the following format:
node _id_ : parent = _p_ , sibling = _s_ , degree = _deg_ , depth = _dep_ ,
height = _h_ , _type_
_p_ is ID of its parent. If the node does not have a parent, print -1.
_s_ is ID of its sibling. If the node does not have a sibling, print -1.
_deg_ , _dep_ and _h_ are the number of children, depth and height of the node
respectively.
_type_ is a type of nodes represented by a string (root, internal node or
leaf. If the root can be considered as a leaf or an internal node, print root.
Please follow the format presented in a sample output below. | s076631751 | Accepted | p02280 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node is given in the following
format:
_id left right_
_id_ is the node ID, _left_ is ID of the left child and _right_ is ID of the
right child. If the node does not have the left (right) child, the
_left_(_right_) is indicated by -1. | if __name__ == "__main__":
parent, children, depths, sibling, heights = {}, {}, {}, {}, {}
n = int(input())
for _ in range(n):
i, left, right = input().split()
if left == "-1" and right == "-1":
children[i] = None
continue
if left == "-1" or right == "-1":
child = left if right == "-1" else right
children[i] = [child]
else:
children[i] = [left, right]
for child in children[i]:
parent[child] = i
root = (set(children) - set(parent)).pop()
parent[root] = "-1"
sibling[root] = "-1"
def get_degree(i):
if children[i] is None:
return 0
return len(children[i])
def get_type(i):
if parent[i] == "-1":
return "root"
if children[i] is None:
return "leaf"
return "internal node"
def set_depth(i, depth):
depths[i] = depth
if children[i] is not None:
for child in children[i]:
set_depth(child, depth + 1)
def set_sibling(i, s):
sibling[i] = s
childs = children[i]
if childs is not None:
if len(childs) == 1:
set_sibling(childs[0], "-1")
else:
set_sibling(childs[0], childs[1])
set_sibling(childs[1], childs[0])
def set_height(i):
if children[i] is None:
heights[i] = 0
return 0
childs = children[i]
if len(childs) == 1:
heights[i] = set_height(childs[0]) + 1
return heights[i]
heights[i] = max(set_height(childs[0]), set_height(childs[1])) + 1
return heights[i]
set_depth(root, 0)
set_sibling(root, "-1")
set_height(root)
for i in map(str, range(n)):
print(
"node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(
i,
parent[i],
sibling[i],
get_degree(i),
depths[i],
heights[i],
get_type(i),
)
)
| Binary Tree
A rooted binary tree is a tree with a root node in which every node has at
most two children.
Your task is to write a program which reads a rooted binary tree _T_ and
prints the following information for each node _u_ of _T_ :
* node ID of _u_
* parent of _u_
* sibling of _u_
* the number of children of _u_
* depth of _u_
* height of _u_
* node type (root, internal node or leaf)
If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_
have the same parent, we say _u_ is a sibling of _v_ (vice versa).
The height of a node in a tree is the number of edges on the longest simple
downward path from the node to a leaf.
Here, the given binary tree consists of _n_ nodes and evey node has a unique
ID from 0 to _n_ -1. | [{"input": "9\n 0 1 4\n 1 2 3\n 2 -1 -1\n 3 -1 -1\n 4 5 8\n 5 6 7\n 6 -1 -1\n 7 -1 -1\n 8 -1 -1", "output": "node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root\n node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node\n node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf\n node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf\n node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node\n node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node\n node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf\n node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf\n node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf\n \n\n"}] |
Print the information of each node in the following format:
node _id_ : parent = _p_ , sibling = _s_ , degree = _deg_ , depth = _dep_ ,
height = _h_ , _type_
_p_ is ID of its parent. If the node does not have a parent, print -1.
_s_ is ID of its sibling. If the node does not have a sibling, print -1.
_deg_ , _dep_ and _h_ are the number of children, depth and height of the node
respectively.
_type_ is a type of nodes represented by a string (root, internal node or
leaf. If the root can be considered as a leaf or an internal node, print root.
Please follow the format presented in a sample output below. | s382198793 | Accepted | p02280 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node is given in the following
format:
_id left right_
_id_ is the node ID, _left_ is ID of the left child and _right_ is ID of the
right child. If the node does not have the left (right) child, the
_left_(_right_) is indicated by -1. | n = int(input())
childs = [0] * n
for i in range(n):
node = list(map(int, input().split()))
childs[node[0]] = node[1:]
class BisectTree:
def __init__(self, childs):
self.n = len(childs)
self.left_child = [0] * self.n
self.right_child = [0] * self.n
self.parent = [-1] * self.n
for i in range(self.n):
self.left_child[i] = childs[i][0]
self.right_child[i] = childs[i][1]
if childs[i][0] != -1:
self.parent[childs[i][0]] = i
if childs[i][1] != -1:
self.parent[childs[i][1]] = i
self.root = self.parent.index(-1)
self.d = [0] * self.n
self.degree = [0] * self.n
self.sibling = [-1] * self.n
self.node_type = [0] * self.n
self.height = [-1] * self.n
def set_depth(self, id, d):
if id != -1:
self.d[id] = d
self.set_depth(self.left_child[id], d + 1)
self.set_depth(self.right_child[id], d + 1)
def set_degree(self):
for i in range(self.n):
deg = 0
if self.left_child[i] != -1:
deg += 1
if self.right_child[i] != -1:
deg += 1
self.degree[i] = deg
def set_sibling(self):
for i in range(self.n):
if self.right_child[i] != -1 and self.left_child[i] != -1:
self.sibling[self.right_child[i]] = self.left_child[i]
self.sibling[self.left_child[i]] = self.right_child[i]
def set_height(self, id):
if self.left_child[id] == -1 and self.right_child[id] == -1:
self.height[id] = 0
else:
h1 = self.set_height(self.left_child[id])
h2 = self.set_height(self.right_child[id])
self.height[id] = max(h1, h2) + 1
return self.height[id]
def set_node_type(self):
for i in range(self.n):
if self.parent[i] == -1:
self.node_type[i] = "root"
elif self.left_child[i] == -1 and self.right_child[i] == -1:
self.node_type[i] = "leaf"
else:
self.node_type[i] = "internal node"
tree = BisectTree(childs)
tree.set_sibling()
tree.set_degree()
tree.set_depth(tree.root, 0)
tree.set_height(tree.root)
tree.set_node_type()
for i in range(n):
print("node {}: ".format(i), end="")
print("parent = {}, ".format(tree.parent[i]), end="")
print("sibling = {}, ".format(tree.sibling[i]), end="")
print("degree = {}, ".format(tree.degree[i]), end="")
print("depth = {}, ".format(tree.d[i]), end="")
print("height = {}, ".format(tree.height[i]), end="")
print(tree.node_type[i])
| Binary Tree
A rooted binary tree is a tree with a root node in which every node has at
most two children.
Your task is to write a program which reads a rooted binary tree _T_ and
prints the following information for each node _u_ of _T_ :
* node ID of _u_
* parent of _u_
* sibling of _u_
* the number of children of _u_
* depth of _u_
* height of _u_
* node type (root, internal node or leaf)
If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_
have the same parent, we say _u_ is a sibling of _v_ (vice versa).
The height of a node in a tree is the number of edges on the longest simple
downward path from the node to a leaf.
Here, the given binary tree consists of _n_ nodes and evey node has a unique
ID from 0 to _n_ -1. | [{"input": "9\n 0 1 4\n 1 2 3\n 2 -1 -1\n 3 -1 -1\n 4 5 8\n 5 6 7\n 6 -1 -1\n 7 -1 -1\n 8 -1 -1", "output": "node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root\n node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node\n node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf\n node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf\n node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node\n node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node\n node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf\n node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf\n node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf\n \n\n"}] |
Print the information of each node in the following format:
node _id_ : parent = _p_ , sibling = _s_ , degree = _deg_ , depth = _dep_ ,
height = _h_ , _type_
_p_ is ID of its parent. If the node does not have a parent, print -1.
_s_ is ID of its sibling. If the node does not have a sibling, print -1.
_deg_ , _dep_ and _h_ are the number of children, depth and height of the node
respectively.
_type_ is a type of nodes represented by a string (root, internal node or
leaf. If the root can be considered as a leaf or an internal node, print root.
Please follow the format presented in a sample output below. | s239551648 | Accepted | p02280 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node is given in the following
format:
_id left right_
_id_ is the node ID, _left_ is ID of the left child and _right_ is ID of the
right child. If the node does not have the left (right) child, the
_left_(_right_) is indicated by -1. | from sys import stdin
N = int(input())
nodes = [None] * N
sibling = [None] * N
dep = [0] * N
parent_list = [None] * N
degree = [0] * N
class node_tree:
def __init__(self, node):
self.node = node
self.left = None
self.right = None
self.brother = None
self.up = None
for i in range(N):
node, left, right = list(map(int, (stdin.readline().strip().split())))
if nodes[node] is not None:
parent = nodes[node]
else:
parent = node_tree(node)
if left != -1:
if nodes[left] is not None:
left_node = nodes[left]
else:
left_node = node_tree(left)
parent.left = left_node
left_node.up = parent
if right != -1:
if nodes[right] is not None:
right_node = nodes[right]
else:
right_node = node_tree(right)
parent.right = right_node
right_node.up = parent
if left != -1 and right != -1:
left_node.brother = right_node
right_node.brother = left_node
if left != -1:
nodes[left] = left_node
if right != -1:
nodes[right] = right_node
nodes[node] = parent
def search_root(u):
if u.up != None:
return search_root(u.up)
else:
return u.node
oya = search_root(nodes[0])
def search_depth(u, p):
dep[u.node] = p
if u.right is not None and u.left is not None:
degree[u.node] = 2
elif u.left is not None:
degree[u.node] = 1
elif u.right is not None:
degree[u.node] = 1
else:
degree[u.node] = 0
if u.right is not None:
parent_list[u.right.node] = u.node
search_depth(u.right, p + 1)
if u.left is not None:
parent_list[u.left.node] = u.node
search_depth(u.left, p + 1)
def search_height(u):
h1, h2 = 0, 0
if u.right is not None:
h1 = search_height(u.right) + 1
if u.left is not None:
h2 = search_height(u.left) + 1
return max(h1, h2)
def search_sib(u):
if u.brother is not None:
sibling[u.node] = u.brother.node
sibling[u.brother.node] = u.node
if u.left is not None:
search_sib(u.left)
if u.right is not None:
search_sib(u.right)
search_sib(nodes[oya])
search_depth(nodes[oya], 0)
word_list = ["internal node", "leaf"]
for i in range(N):
height = search_height(nodes[i])
if height >= 1:
word = word_list[0]
else:
word = word_list[1]
if i == oya:
parent_list[oya] = -1
sibling[oya] = -1
word = "root"
if sibling[i] is None:
sibling[i] = -1
print(
(
"node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s"
% (
nodes[i].node,
parent_list[i],
sibling[i],
degree[i],
dep[i],
height,
word,
)
)
)
| Binary Tree
A rooted binary tree is a tree with a root node in which every node has at
most two children.
Your task is to write a program which reads a rooted binary tree _T_ and
prints the following information for each node _u_ of _T_ :
* node ID of _u_
* parent of _u_
* sibling of _u_
* the number of children of _u_
* depth of _u_
* height of _u_
* node type (root, internal node or leaf)
If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_
have the same parent, we say _u_ is a sibling of _v_ (vice versa).
The height of a node in a tree is the number of edges on the longest simple
downward path from the node to a leaf.
Here, the given binary tree consists of _n_ nodes and evey node has a unique
ID from 0 to _n_ -1. | [{"input": "9\n 0 1 4\n 1 2 3\n 2 -1 -1\n 3 -1 -1\n 4 5 8\n 5 6 7\n 6 -1 -1\n 7 -1 -1\n 8 -1 -1", "output": "node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root\n node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node\n node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf\n node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf\n node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node\n node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node\n node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf\n node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf\n node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf\n \n\n"}] |
Print the information of each node in the following format:
node _id_ : parent = _p_ , sibling = _s_ , degree = _deg_ , depth = _dep_ ,
height = _h_ , _type_
_p_ is ID of its parent. If the node does not have a parent, print -1.
_s_ is ID of its sibling. If the node does not have a sibling, print -1.
_deg_ , _dep_ and _h_ are the number of children, depth and height of the node
respectively.
_type_ is a type of nodes represented by a string (root, internal node or
leaf. If the root can be considered as a leaf or an internal node, print root.
Please follow the format presented in a sample output below. | s988954353 | Accepted | p02280 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node is given in the following
format:
_id left right_
_id_ is the node ID, _left_ is ID of the left child and _right_ is ID of the
right child. If the node does not have the left (right) child, the
_left_(_right_) is indicated by -1. | from sys import stdin
class Node:
NIL = -1
def __init__(self, p=NIL, l=NIL, r=NIL, d=-1, h=-1):
self.p = p
self.l = l
self.r = r
self.d = d
self.h = h
def __repr__(self):
return "Node({}, {}, {}, {})".format(self.p, self.l, self.r, self.d)
def root_of(T):
return [u.p for u in T].index(Node.NIL)
def sibling_of(T, id):
p = T[T[id].p]
return p.r if p.l == id else p.l
def degree_of(T, id):
l = 0 if T[id].l == Node.NIL else 1
r = 0 if T[id].r == Node.NIL else 1
return l + r
def calc_depth(T):
def rec(id, depth):
nonlocal T
T[id].d = depth
if T[id].l != Node.NIL:
rec(T[id].l, depth + 1)
if T[id].r != Node.NIL:
rec(T[id].r, depth + 1)
rec(root_of(T), 0)
def calc_height(T):
def rec(id):
nonlocal T
l = 0 if T[id].l == Node.NIL else rec(T[id].l) + 1
r = 0 if T[id].r == Node.NIL else rec(T[id].r) + 1
T[id].h = max(l, r)
return T[id].h
rec(root_of(T))
def type_of(T, id):
if T[id].p == Node.NIL:
return "root"
elif T[id].l == Node.NIL and T[id].r == Node.NIL:
return "leaf"
else:
return "internal node"
def read_nodes(T):
for line in stdin:
id, l, r = [int(x) for x in line.split()]
T[id].l = l
if l != Node.NIL:
T[l].p = id
T[id].r = r
if r != Node.NIL:
T[r].p = id
def print_nodes(T):
for id in range(len(T)):
print("node {}: ".format(id), end="")
print("parent = {}, ".format(T[id].p), end="")
print("sibling = {}, ".format(sibling_of(T, id)), end="")
print("degree = {}, ".format(degree_of(T, id)), end="")
print("depth = {}, ".format(T[id].d), end="")
print("height = {}, ".format(T[id].h), end="")
print(type_of(T, id))
def main():
n = int(stdin.readline())
T = [Node() for _ in range(n)]
read_nodes(T)
calc_depth(T)
calc_height(T)
print_nodes(T)
main()
| Binary Tree
A rooted binary tree is a tree with a root node in which every node has at
most two children.
Your task is to write a program which reads a rooted binary tree _T_ and
prints the following information for each node _u_ of _T_ :
* node ID of _u_
* parent of _u_
* sibling of _u_
* the number of children of _u_
* depth of _u_
* height of _u_
* node type (root, internal node or leaf)
If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_
have the same parent, we say _u_ is a sibling of _v_ (vice versa).
The height of a node in a tree is the number of edges on the longest simple
downward path from the node to a leaf.
Here, the given binary tree consists of _n_ nodes and evey node has a unique
ID from 0 to _n_ -1. | [{"input": "9\n 0 1 4\n 1 2 3\n 2 -1 -1\n 3 -1 -1\n 4 5 8\n 5 6 7\n 6 -1 -1\n 7 -1 -1\n 8 -1 -1", "output": "node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root\n node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node\n node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf\n node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf\n node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node\n node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node\n node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf\n node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf\n node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf\n \n\n"}] |
Print the information of each node in the following format:
node _id_ : parent = _p_ , sibling = _s_ , degree = _deg_ , depth = _dep_ ,
height = _h_ , _type_
_p_ is ID of its parent. If the node does not have a parent, print -1.
_s_ is ID of its sibling. If the node does not have a sibling, print -1.
_deg_ , _dep_ and _h_ are the number of children, depth and height of the node
respectively.
_type_ is a type of nodes represented by a string (root, internal node or
leaf. If the root can be considered as a leaf or an internal node, print root.
Please follow the format presented in a sample output below. | s195548614 | Accepted | p02280 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node is given in the following
format:
_id left right_
_id_ is the node ID, _left_ is ID of the left child and _right_ is ID of the
right child. If the node does not have the left (right) child, the
_left_(_right_) is indicated by -1. | import sys
sys.setrecursionlimit(10**7)
def resolve():
class Node:
def __init__(self, parent, left, right):
self.parent = parent
self.left = left
self.right = right
self.height = None
def get_type(self):
if self.parent == -1:
return "root"
elif self.left == -1 and self.right == -1:
return "leaf"
else:
return "internal node"
def get_depth(self):
if self.parent == -1:
return 0
else:
depth = 1
t = Nodes[self.parent]
while t.parent != -1:
t = Nodes[t.parent]
depth += 1
return depth
def get_height(self):
h_left = 0
h_right = 0
if self.left != -1:
h_left = Nodes[self.left].get_height() + 1
if self.right != -1:
h_right = Nodes[self.right].get_height() + 1
self.height = max(h_left, h_right)
return self.height
def get_degree(self):
degree = 0
if self.left != -1:
degree += 1
if self.right != -1:
degree += 1
return degree
def get_sigling(self):
if self.parent == -1:
return -1
p = Nodes[self.parent]
if Nodes[p.left] != self and Nodes[p.left] != -1:
return p.left
if Nodes[p.right] != self and Nodes[p.right] != -1:
return p.right
N = int(input())
Nodes = [Node(-1, None, None) for _ in range(25)]
for _ in range(N):
id, left, right = map(int, input().split())
Nodes[id].left = left
Nodes[id].right = right
if left != -1:
Nodes[left].parent = id
if right != -1:
Nodes[right].parent = id
for i in range(N):
node = Nodes[i]
print("node %d: " % i, end="")
print("parent = %d, " % node.parent, end="")
print("sibling = %d, " % node.get_sigling(), end="")
print("degree = %d, " % node.get_degree(), end="")
print("depth = %d, " % node.get_depth(), end="")
print("height = %d, " % node.get_height(), end="")
print(node.get_type())
if __name__ == "__main__":
resolve()
| Binary Tree
A rooted binary tree is a tree with a root node in which every node has at
most two children.
Your task is to write a program which reads a rooted binary tree _T_ and
prints the following information for each node _u_ of _T_ :
* node ID of _u_
* parent of _u_
* sibling of _u_
* the number of children of _u_
* depth of _u_
* height of _u_
* node type (root, internal node or leaf)
If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_
have the same parent, we say _u_ is a sibling of _v_ (vice versa).
The height of a node in a tree is the number of edges on the longest simple
downward path from the node to a leaf.
Here, the given binary tree consists of _n_ nodes and evey node has a unique
ID from 0 to _n_ -1. | [{"input": "9\n 0 1 4\n 1 2 3\n 2 -1 -1\n 3 -1 -1\n 4 5 8\n 5 6 7\n 6 -1 -1\n 7 -1 -1\n 8 -1 -1", "output": "node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root\n node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node\n node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf\n node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf\n node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node\n node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node\n node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf\n node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf\n node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf\n \n\n"}] |
For each dataset, output a line having an integer indicating the length of the
shortest path from the entry to the exit. The length of a path is given by the
number of visited squares. If there exists no path to go through the maze,
output a line containing a single zero. The line should not contain any
character other than this number. | s542439476 | Wrong Answer | p00747 | The input consists of one or more datasets, each of which represents a maze.
The first line of a dataset contains two integer numbers, the width _w_ and
the height _h_ of the rectangular area, in this order.
The following 2 × _h_ − 1 lines of a dataset describe whether there are walls
between squares or not. The first line starts with a space and the rest of the
line contains _w_ − 1 integers, 1 or 0, separated by a space. These indicate
whether walls separate horizontally adjoining squares in the first row. An
integer 1 indicates a wall is placed, and 0 indicates no wall is there. The
second line starts without a space and contains _w_ integers, 1 or 0,
separated by a space. These indicate whether walls separate vertically
adjoining squares in the first and the second rows. An integer 1/0 indicates a
wall is placed or not. The following lines indicate placing of walls between
horizontally and vertically adjoining squares, alternately, in the same
manner.
The end of the input is indicated by a line containing two zeros.
The number of datasets is no more than 100. Both the widths and the heights of
rectangular areas are no less than 2 and no more than 30. | from copy import deepcopy
while True:
w, h = map(int, input().split())
if w == 0:
break
wwal = [] # |
hwal = [] # ー
a = [0] * w
b = []
for i in range(2 * h - 1):
if i % 2 == 0:
wwal.append(list(map(int, input().split())))
c = deepcopy(a)
b.append(c)
else:
hwal.append(list(map(int, input().split())))
b[0][0] = 1
start = [[0, 0]]
flag = 0
while flag == 0:
flag = 1
stamemo = []
for i in range(len(start)):
t = start.pop()
# Left
if t[1] != 0:
if wwal[t[0]][t[1] - 1] == 0 and b[t[0]][t[1] - 1] == 0:
b[t[0]][t[1] - 1] = b[t[0]][t[1]] + 1
stamemo.append([t[0], t[1] - 1])
flag = 0
# righT
if t[1] != w - 1:
if wwal[t[0]][t[1]] == 0 and b[t[0]][t[1] + 1] == 0:
b[t[0]][t[1] + 1] = b[t[0]][t[1]] + 1
if t[0] == h - 1 and t[1] + 1 == w - 1:
print(b[t[0]][t[1] + 1])
flag = 2
break
stamemo.append([t[0], t[1] + 1])
flag = 0
# Up
if t[0] != 0:
if hwal[t[0] - 1][t[1]] == 0 and b[t[0] - 1][t[1]] == 0:
b[t[0] - 1][t[1]] = b[t[0]][t[1]] + 1
stamemo.append([t[0] - 1, t[1]])
flag = 0
# dowN
if t[0] != h - 1:
if hwal[t[0]][t[1]] == 0 and b[t[0] + 1][t[1]] == 0:
b[t[0] + 1][t[1]] = b[t[0]][t[1]] + 1
if t[0] + 1 == h - 1 and t[1] == w - 1:
print(b[t[0] + 1][t[1]])
flag = 2
break
stamemo.append([t[0] + 1, t[1]])
flag = 0
start = stamemo
print(start)
if flag == 1:
print(0)
| B: Amazing Mazes
You are requested to solve maze problems. Without passing through these mazes,
you might not be able to pass through the domestic contest!
A maze here is a rectangular area of a number of squares, lined up both
lengthwise and widthwise, The area is surrounded by walls except for its entry
and exit. The entry to the maze is at the leftmost part of the upper side of
the rectangular area, that is, the upper side of the uppermost leftmost square
of the maze is open. The exit is located at the rightmost part of the lower
side, likewise.
In the maze, you can move from a square to one of the squares adjoining either
horizontally or vertically. Adjoining squares, however, may be separated by a
wall, and when they are, you cannot go through the wall.
Your task is to find the length of the shortest path from the entry to the
exit. Note that there may be more than one shortest paths, or there may be
none. | [{"input": "\n\n \n \n 2 3\n 1\n 0 1\n 0\n 1 0\n 1\n 9 4\n 1 0 1 0 0 0 0 0\n 0 1 1 0 1 1 0 0 0\n 1 0 1 1 0 0 0 0\n 0 0 0 0 0 0 0 1 1\n 0 0 0 1 0 0 1 1\n 0 0 0 0 1 1 0 0 0\n 0 0 0 0 0 0 1 0\n 12 5\n 1 0 0 0 0 0 0 0 0 0 0\n 0 0 0 1 1 0 0 0 0 0 0 0\n 1 0 1 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 1 1 0 0 0 0\n 0 0 1 0 0 1 0 1 0 0 0\n 0 0 0 1 1 0 1 1 0 1 1 0\n 0 0 0 0 0 1 0 0 1 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 1 0 0\n 0 0", "output": "0\n 20"}] |
For each dataset, output a line having an integer indicating the length of the
shortest path from the entry to the exit. The length of a path is given by the
number of visited squares. If there exists no path to go through the maze,
output a line containing a single zero. The line should not contain any
character other than this number. | s611834076 | Accepted | p00747 | The input consists of one or more datasets, each of which represents a maze.
The first line of a dataset contains two integer numbers, the width _w_ and
the height _h_ of the rectangular area, in this order.
The following 2 × _h_ − 1 lines of a dataset describe whether there are walls
between squares or not. The first line starts with a space and the rest of the
line contains _w_ − 1 integers, 1 or 0, separated by a space. These indicate
whether walls separate horizontally adjoining squares in the first row. An
integer 1 indicates a wall is placed, and 0 indicates no wall is there. The
second line starts without a space and contains _w_ integers, 1 or 0,
separated by a space. These indicate whether walls separate vertically
adjoining squares in the first and the second rows. An integer 1/0 indicates a
wall is placed or not. The following lines indicate placing of walls between
horizontally and vertically adjoining squares, alternately, in the same
manner.
The end of the input is indicated by a line containing two zeros.
The number of datasets is no more than 100. Both the widths and the heights of
rectangular areas are no less than 2 and no more than 30. | from collections import deque
while True:
W, H = map(int, input().split(" "))
if W == 0 and H == 0:
break
field = []
for _ in range(2 * H - 1):
row = list(input())
if len(row) == 2 * W - 2:
row.append(" ")
field.append(row)
gy = 2 * H - 2
gx = 2 * W - 2
queue = deque()
queue.append((0, 0, 1))
min_step = 0
while len(queue) > 0:
y, x, step = queue.popleft()
if field[y][x] != " ":
continue
else:
field[y][x] = "X"
if y == gy and x == gx:
min_step = step
break
for dy, dx in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
if 0 <= y + dy <= gy and 0 <= x + dx <= gx:
if field[y + dy][x + dx] == "0":
queue.append((y + 2 * dy, x + 2 * dx, step + 1))
print(min_step)
| B: Amazing Mazes
You are requested to solve maze problems. Without passing through these mazes,
you might not be able to pass through the domestic contest!
A maze here is a rectangular area of a number of squares, lined up both
lengthwise and widthwise, The area is surrounded by walls except for its entry
and exit. The entry to the maze is at the leftmost part of the upper side of
the rectangular area, that is, the upper side of the uppermost leftmost square
of the maze is open. The exit is located at the rightmost part of the lower
side, likewise.
In the maze, you can move from a square to one of the squares adjoining either
horizontally or vertically. Adjoining squares, however, may be separated by a
wall, and when they are, you cannot go through the wall.
Your task is to find the length of the shortest path from the entry to the
exit. Note that there may be more than one shortest paths, or there may be
none. | [{"input": "\n\n \n \n 2 3\n 1\n 0 1\n 0\n 1 0\n 1\n 9 4\n 1 0 1 0 0 0 0 0\n 0 1 1 0 1 1 0 0 0\n 1 0 1 1 0 0 0 0\n 0 0 0 0 0 0 0 1 1\n 0 0 0 1 0 0 1 1\n 0 0 0 0 1 1 0 0 0\n 0 0 0 0 0 0 1 0\n 12 5\n 1 0 0 0 0 0 0 0 0 0 0\n 0 0 0 1 1 0 0 0 0 0 0 0\n 1 0 1 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 1 1 0 0 0 0\n 0 0 1 0 0 1 0 1 0 0 0\n 0 0 0 1 1 0 1 1 0 1 1 0\n 0 0 0 0 0 1 0 0 1 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 1 0 0\n 0 0", "output": "0\n 20"}] |
For each dataset, output a line having an integer indicating the length of the
shortest path from the entry to the exit. The length of a path is given by the
number of visited squares. If there exists no path to go through the maze,
output a line containing a single zero. The line should not contain any
character other than this number. | s206396523 | Wrong Answer | p00747 | The input consists of one or more datasets, each of which represents a maze.
The first line of a dataset contains two integer numbers, the width _w_ and
the height _h_ of the rectangular area, in this order.
The following 2 × _h_ − 1 lines of a dataset describe whether there are walls
between squares or not. The first line starts with a space and the rest of the
line contains _w_ − 1 integers, 1 or 0, separated by a space. These indicate
whether walls separate horizontally adjoining squares in the first row. An
integer 1 indicates a wall is placed, and 0 indicates no wall is there. The
second line starts without a space and contains _w_ integers, 1 or 0,
separated by a space. These indicate whether walls separate vertically
adjoining squares in the first and the second rows. An integer 1/0 indicates a
wall is placed or not. The following lines indicate placing of walls between
horizontally and vertically adjoining squares, alternately, in the same
manner.
The end of the input is indicated by a line containing two zeros.
The number of datasets is no more than 100. Both the widths and the heights of
rectangular areas are no less than 2 and no more than 30. | def solve():
w, h = map(int, input().split())
if w == 0 and h == 0:
return False
walls = []
for i in range(h * 2 - 1):
walls.append(list(map(int, input().split())))
field = [[] for x in range(h * w)]
for i in range(h):
for j in range(w):
f = j + i * w
if j + 1 < len(walls[i]) and not walls[i * 2][j]:
field[f].append(f + 1)
field[f + 1].append(f)
if i + 1 < h and not walls[i * 2 + 1][j]:
field[f].append(f + w)
field[f + w].append(f)
# print(field)
end = [False for x in range(w * h)]
que = [(0, 0)]
goal = h * w - 1
results = []
while que:
tn, cost = que[0]
del que[0]
# print(tn)
for n in field[tn]:
if n == goal:
results.append(cost)
# print(end)
# return True
elif not end[n]:
end[n] = True
que.append((n, cost + 1))
print(min(results) + 2 if results else 0)
return True
while solve():
pass
| B: Amazing Mazes
You are requested to solve maze problems. Without passing through these mazes,
you might not be able to pass through the domestic contest!
A maze here is a rectangular area of a number of squares, lined up both
lengthwise and widthwise, The area is surrounded by walls except for its entry
and exit. The entry to the maze is at the leftmost part of the upper side of
the rectangular area, that is, the upper side of the uppermost leftmost square
of the maze is open. The exit is located at the rightmost part of the lower
side, likewise.
In the maze, you can move from a square to one of the squares adjoining either
horizontally or vertically. Adjoining squares, however, may be separated by a
wall, and when they are, you cannot go through the wall.
Your task is to find the length of the shortest path from the entry to the
exit. Note that there may be more than one shortest paths, or there may be
none. | [{"input": "\n\n \n \n 2 3\n 1\n 0 1\n 0\n 1 0\n 1\n 9 4\n 1 0 1 0 0 0 0 0\n 0 1 1 0 1 1 0 0 0\n 1 0 1 1 0 0 0 0\n 0 0 0 0 0 0 0 1 1\n 0 0 0 1 0 0 1 1\n 0 0 0 0 1 1 0 0 0\n 0 0 0 0 0 0 1 0\n 12 5\n 1 0 0 0 0 0 0 0 0 0 0\n 0 0 0 1 1 0 0 0 0 0 0 0\n 1 0 1 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 1 1 0 0 0 0\n 0 0 1 0 0 1 0 1 0 0 0\n 0 0 0 1 1 0 1 1 0 1 1 0\n 0 0 0 0 0 1 0 0 1 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 1 0 0\n 0 0", "output": "0\n 20"}] |
Print the answer.
* * * | s799396655 | Wrong Answer | p03887 | The input is given from Standard Input in the following format:
N A B C | def inverse(k):
return fast_pow(k, MOD - 2)
def comb(n, k):
return FACT[n] * INVERSE_FACT[n - k] * INVERSE_FACT[k] % MOD
def fast_pow(x, y):
if y == 0:
return 1
p = fast_pow(x, y // 2) % MOD
p = p * p % MOD
if y % 2:
p = p * x % MOD
return p
MOD = 1000000007
n, a, b, c = map(int, input().split())
FACT = [0] * (n + 1)
INVERSE_FACT = [0] * (n + 1)
FACT[0] = 1
INVERSE_FACT[0] = 1
for i in range(1, n + 1):
FACT[i] = FACT[i - 1] * i % MOD
INVERSE_FACT[i] = inverse(FACT[i])
ans = 0
if b % 2 != 0:
print(0)
exit()
for y in range(0, min(a + 1, c + 1)):
for z in range(0, (c - y) // 3 + 1):
x = a - y
rest3 = c - y - 3 * z
cur_ans = FACT[x + y + z] * INVERSE_FACT[x] % MOD
cur_ans = cur_ans * INVERSE_FACT[y] % MOD
cur_ans = cur_ans * INVERSE_FACT[z] % MOD
cur_ans = cur_ans * comb(x + y + z + 1 + b // 2 - 1, b // 2) % MOD
cur_ans = cur_ans * comb(b // 2 + rest3 - 1, rest3) % MOD
ans = (ans + cur_ans) % MOD
print(ans)
| Statement
Consider all integers between 1 and 2N, inclusive. Snuke wants to divide these
integers into N pairs such that:
* Each integer between 1 and 2N is contained in exactly one of the pairs.
* In exactly A pairs, the difference between the two integers is 1.
* In exactly B pairs, the difference between the two integers is 2.
* In exactly C pairs, the difference between the two integers is 3.
Note that the constraints guarantee that N = A + B + C, thus no pair can have
the difference of 4 or more.
Compute the number of ways to do this, modulo 10^9+7. | [{"input": "3 1 2 0", "output": "2\n \n\nThere are two possibilities: 1-2, 3-5, 4-6 or 1-3, 2-4, 5-6.\n\n* * *"}, {"input": "600 100 200 300", "output": "522158867"}] |
Print the answer.
* * * | s697213646 | Runtime Error | p03887 | The input is given from Standard Input in the following format:
N A B C | import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
"""
・2,3^n,2
・3(1)
・1
・333
"""
import numpy as np
MOD = 10**9 + 7
N, A, B, C = map(int, readline().split())
if B & 1:
print(0)
exit()
def cumprod(arr):
L = len(arr)
Lsq = int(L**0.5 + 1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n - 1]
arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n - 1, -1]
arr[n] %= MOD
return arr.ravel()[:L]
U = 10**5
x = np.arange(U, dtype=np.int64)
x[0] = 1
fact = cumprod(x)
x = np.arange(U, 0, -1, dtype=np.int64)
x[0] = pow(int(fact[-1]), MOD - 2, MOD)
fact_inv = cumprod(x)[::-1]
"""
・2,3^n,2:B2個
・3113:A-n個
・11:n個
・333333:m個
"""
B2 = B // 2
answer = 0
for m in range(C // 3 + 1):
n_min = max(0, A - C + 3 * m)
# (B2+A+m)! / (B2)!(A-n)!(n)!(m)!
x = fact[B2 + A + m] * fact_inv[m] % MOD * fact_inv[B2] % MOD
x *= fact_inv[A - n_min :: -1]
x %= MOD
x *= fact_inv[n_min : A + 1]
x %= MOD
# 2,3^n,2のところの3の振り分けを決める。B2個の非負整数の和がC-3m-(A-n)
# (B2+A+m)! / (B2)!(A-n)!(n)!(m)!
y = fact[B2 - 1 + C - 3 * m - A + n_min : B2 + C - 3 * m] * fact_inv[B2 - 1] % MOD
y *= fact_inv[C - 3 * m - A + n_min : C - 3 * m + 1]
y %= MOD
answer += (x * y % MOD).sum()
answer %= MOD
print(answer)
| Statement
Consider all integers between 1 and 2N, inclusive. Snuke wants to divide these
integers into N pairs such that:
* Each integer between 1 and 2N is contained in exactly one of the pairs.
* In exactly A pairs, the difference between the two integers is 1.
* In exactly B pairs, the difference between the two integers is 2.
* In exactly C pairs, the difference between the two integers is 3.
Note that the constraints guarantee that N = A + B + C, thus no pair can have
the difference of 4 or more.
Compute the number of ways to do this, modulo 10^9+7. | [{"input": "3 1 2 0", "output": "2\n \n\nThere are two possibilities: 1-2, 3-5, 4-6 or 1-3, 2-4, 5-6.\n\n* * *"}, {"input": "600 100 200 300", "output": "522158867"}] |
Print the minimum number of operations needed.
* * * | s495311540 | Runtime Error | p02795 | Input is given from Standard Input in the following format:
H
W
N | n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort()
t = 0
for i in range(0, n - 1):
if l[i + 1][0] - l[i][0] < l[i + 1][1] + l[i][1]:
del l[i + 1]
l = [[0, 0]] + l
t += 1
print(max(t, n - t))
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s593315811 | Accepted | p02795 | Input is given from Standard Input in the following format:
H
W
N | d = max(int(input()), int(input()))
print((int(input()) + (d - 1)) // d)
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s046994498 | Wrong Answer | p02795 | Input is given from Standard Input in the following format:
H
W
N | n, h, w = [int(input()) for i in range(3)]
k = max(h, w)
ans = (n + k - 1) // k
print(ans)
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s657060597 | Runtime Error | p02795 | Input is given from Standard Input in the following format:
H
W
N | H, W, N = map(int, input().split())
B = max(H, W)
ans = (N + B - 1) // B
print(ans)
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s245927089 | Runtime Error | p02795 | Input is given from Standard Input in the following format:
H
W
N | a, b, n = map(int, input().split())
print(n // a + 1 if a >= b else n // b + 1)
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s862705800 | Accepted | p02795 | Input is given from Standard Input in the following format:
H
W
N | a, b, c = [int(input()) for _ in range(3)]
x = max(a, b)
print((c + x - 1) // x)
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s319695475 | Wrong Answer | p02795 | Input is given from Standard Input in the following format:
H
W
N | N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(10000):
for i in range(N - 1):
if A == sorted(A):
print(ans)
quit()
a = A[i]
ai = A[i + 1]
b = B[i]
bi = B[i + 1]
if b > bi:
if ai - a >= b - bi:
A[i] = bi
A[i + 1] = b
B[i] = ai
B[i + 1] = a
ans += 1
elif a > ai:
if bi - b <= a - ai:
A[i] = bi
A[i + 1] = b
B[i] = ai
B[i + 1] = a
ans += 1
print(-1)
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s131581495 | Accepted | p02795 | Input is given from Standard Input in the following format:
H
W
N | row = int(input())
colmun = int(input())
top = int(input())
low, high = 0, 0
if row <= colmun:
low, high = row, colmun
else:
low, high = colmun, row
for n in range(low):
if (n + 1) * high >= top:
print(n + 1)
break
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s098268972 | Wrong Answer | p02795 | Input is given from Standard Input in the following format:
H
W
N | ans = "123"
print(ans.replace(input(), "").replace(input(), ""))
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s066402722 | Wrong Answer | p02795 | Input is given from Standard Input in the following format:
H
W
N | 14
12
112
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Print the minimum number of operations needed.
* * * | s341898247 | Wrong Answer | p02795 | Input is given from Standard Input in the following format:
H
W
N | a = [int(input()) for i in range(2)]
b = int(input())
c = b // max(a)
print(c)
| Statement
We have a grid with H rows and W columns, where all the squares are initially
white.
You will perform some number of painting operations on the grid. In one
operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black
squares in the grid? It is guaranteed that, under the conditions in
Constraints, having N or more black squares is always possible by performing
some number of operations. | [{"input": "3\n 7\n 10", "output": "2\n \n\nYou can have 14 black squares in the grid by performing the \"row\" operation\ntwice, on different rows.\n\n* * *"}, {"input": "14\n 12\n 112", "output": "8\n \n\n* * *"}, {"input": "2\n 100\n 200", "output": "2"}] |
Output line contains one integer - the number of connected subsets - for each
input line. | s199270374 | Wrong Answer | p00602 | Each data set is defined as one line with two integers as follows:
_Line 1_ : Number of nodes _V_ and the distance _d_.
Input includes several data sets (i.e., several lines). The number of dat sets
is less than or equal to 50. | while 1:
try:
v, d = map(int, input().split())
f = [0] * (v + 1)
f[0], f[1] = 1, 2
for i in range(2, v + 1):
f[i] = f[i - 1] + f[i - 2]
f.sort()
c = 1
for i in range(2, v + 1):
if f[i] - f[i - 1] >= d:
c += 1
print(c)
except:
break
| H: Fibonacci Sets
Fibonacci number _f_(_i_) appear in a variety of puzzles in nature and math,
including packing problems, family trees or Pythagorean triangles. They obey
the rule _f_(_i_) = _f_(_i_ \- 1) + _f_(_i_ \- 2), where we set _f_(0) = 1 =
_f_(-1).
Let _V_ and _d_ be two certain positive integers and be _N_ ≡ 1001 a constant.
Consider a set of _V_ nodes, each node _i_ having a Fibonacci label _F_[_i_] =
(_f_(_i_) mod N) assigned for _i_ = 1,..., _V_ ≤ N. If |_F_(_i_) - _F_(_j_)| <
_d_ , then the nodes _i_ and _j_ are connected.
Given _V_ and _d_ , how many connected subsets of nodes will you obtain?

Figure 1: There are 4 connected subsets for _V_ = 20 and _d_ = 100. | [{"input": "5\n 50 1\n 13 13", "output": "50\n 8"}] |
Print the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 +
7.
* * * | s673122473 | Wrong Answer | p03184 | Input is given from Standard Input in the following format:
H W N
r_1 c_1
r_2 c_2
:
r_N c_N | # -----conbination計算部分------
# https://qiita.com/derodero24/items/91b6468e66923a87f39f より
def cmb(n, r, mod=10**9 + 7):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 10**9 + 7 # 出力の制限
N = 10**5 * 2
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
# -------------------------------------------------------
# 入力
H, W, N = map(int, input().split())
# 迷路の初期化
# keystr = str(H).zfill(6)+str(W).zfill(6)
maplst = []
maplst.append([H, W, cmb(H + W - 2, W - 1)])
for i in range(N):
x, y = map(int, input().split())
keystr = str(x).zfill(6) + str(y).zfill(6)
maplst.append([x, y, cmb(x + y - 2, y - 1)])
maplst.sort()
| Statement
There is a grid with H horizontal rows and W vertical columns. Let (i, j)
denote the square at the i-th row from the top and the j-th column from the
left.
In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall
squares, and the others are all empty squares. It is guaranteed that Squares
(1, 1) and (H, W) are empty squares.
Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right
or down to an adjacent empty square.
Find the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7. | [{"input": "3 4 2\n 2 2\n 1 4", "output": "3\n \n\nThere are three paths as follows:\n\n\n\n* * *"}, {"input": "5 2 2\n 2 1\n 4 2", "output": "0\n \n\nThere may be no paths.\n\n* * *"}, {"input": "5 5 4\n 3 1\n 3 5\n 1 3\n 5 3", "output": "24\n \n\n* * *"}, {"input": "100000 100000 1\n 50000 50000", "output": "123445622\n \n\nBe sure to print the count modulo 10^9 + 7."}] |
Print the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 +
7.
* * * | s430820189 | Runtime Error | p03184 | Input is given from Standard Input in the following format:
H W N
r_1 c_1
r_2 c_2
:
r_N c_N | H, W = map(int, input().split())
a = [input() for _ in range(H)]
WARU = 10**9 + 7
dp = [[0] * (W + 1) for _ in range(H + 1)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if a[i][j] == "#":
continue
dp[i][j] %= WARU
dp[i + 1][j] += dp[i][j]
dp[i][j + 1] += dp[i][j]
print(dp[H - 1][W - 1])
| Statement
There is a grid with H horizontal rows and W vertical columns. Let (i, j)
denote the square at the i-th row from the top and the j-th column from the
left.
In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall
squares, and the others are all empty squares. It is guaranteed that Squares
(1, 1) and (H, W) are empty squares.
Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right
or down to an adjacent empty square.
Find the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7. | [{"input": "3 4 2\n 2 2\n 1 4", "output": "3\n \n\nThere are three paths as follows:\n\n\n\n* * *"}, {"input": "5 2 2\n 2 1\n 4 2", "output": "0\n \n\nThere may be no paths.\n\n* * *"}, {"input": "5 5 4\n 3 1\n 3 5\n 1 3\n 5 3", "output": "24\n \n\n* * *"}, {"input": "100000 100000 1\n 50000 50000", "output": "123445622\n \n\nBe sure to print the count modulo 10^9 + 7."}] |
Print the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 +
7.
* * * | s918949539 | Wrong Answer | p03184 | Input is given from Standard Input in the following format:
H W N
r_1 c_1
r_2 c_2
:
r_N c_N | import sys
input = sys.stdin.readline
def solve():
MOD = 10**9 + 7
H, W, N = map(int, input().split())
rcs = [tuple(map(int, input().split())) for _ in range(N)]
def getFacts(n, MOD):
facts = [1] * (n + 1)
for x in range(2, n + 1):
facts[x] = (facts[x - 1] * x) % MOD
return facts
facts = getFacts(H + W, MOD)
def getInvFacts(n, MOD):
invFacts = [0] * (n + 1)
invFacts[n] = pow(facts[n], MOD - 2, MOD)
for x in reversed(range(n)):
invFacts[x] = (invFacts[x + 1] * (x + 1)) % MOD
return invFacts
invFacts = getInvFacts(H + W, MOD)
def getNum(r, c, MOD):
return facts[r + c] * invFacts[r] * invFacts[c] % MOD
dp = [0] * N
for i, (r1, c1) in enumerate(rcs):
v = getNum(r1 - 1, c1 - 1, MOD)
for j, (r0, c0) in enumerate(rcs):
if i == j or r0 > r1 or c0 > c1:
continue
dr, dc = r1 - r0, c1 - c0
v -= getNum(dr, dc, MOD)
v %= MOD
dp[i] = v
ans = getNum(H - 1, W - 1, MOD)
for i, (r, c) in enumerate(rcs):
dr, dc = H - r, W - c
ans -= dp[i] * getNum(dr, dc, MOD)
ans %= MOD
print(ans)
solve()
| Statement
There is a grid with H horizontal rows and W vertical columns. Let (i, j)
denote the square at the i-th row from the top and the j-th column from the
left.
In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall
squares, and the others are all empty squares. It is guaranteed that Squares
(1, 1) and (H, W) are empty squares.
Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right
or down to an adjacent empty square.
Find the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7. | [{"input": "3 4 2\n 2 2\n 1 4", "output": "3\n \n\nThere are three paths as follows:\n\n\n\n* * *"}, {"input": "5 2 2\n 2 1\n 4 2", "output": "0\n \n\nThere may be no paths.\n\n* * *"}, {"input": "5 5 4\n 3 1\n 3 5\n 1 3\n 5 3", "output": "24\n \n\n* * *"}, {"input": "100000 100000 1\n 50000 50000", "output": "123445622\n \n\nBe sure to print the count modulo 10^9 + 7."}] |
Print the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 +
7.
* * * | s740212734 | Accepted | p03184 | Input is given from Standard Input in the following format:
H W N
r_1 c_1
r_2 c_2
:
r_N c_N | import sys
input = lambda: sys.stdin.readline().strip()
class PERM_COMB_MOD:
# http://drken1215.hatenablog.com/entry/2018/06/08/210000
def __init__(self, max_n=510000, mod=10**9 + 7):
self.fac = [0] * max_n
self.finv = [0] * max_n
self.inv = [0] * max_n
self.fac[0] = self.fac[1] = 1
self.finv[0] = self.finv[1] = 1
self.inv[1] = 1
self.max = max_n
self.mod = mod
self._maesyori()
def _maesyori(self):
for i in range(2, self.max):
self.fac[i] = self.fac[i - 1] * i % self.mod
self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod
def comb(self, n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.mod) % self.mod
mod = 10**9 + 7
PCM = PERM_COMB_MOD(3 * 10**5, mod=mod)
h, w, n = map(int, input().split())
rc = [list(map(int, input().split())) for i in range(n)]
rc.append([h, w])
n += 1
rc.sort()
DP = [0] * (n + 1)
# start地点
DP[0] = 1
for i in range(n):
r, c = rc[i]
DP[i + 1] = PCM.comb(r - 1 + c - 1, r - 1)
for j in range(i):
rj, cj = rc[j]
if rj <= r and cj <= c:
DP[i + 1] -= DP[j + 1] * PCM.comb(r - rj + c - cj, r - rj)
DP[i + 1] %= mod
print(DP[-1])
| Statement
There is a grid with H horizontal rows and W vertical columns. Let (i, j)
denote the square at the i-th row from the top and the j-th column from the
left.
In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall
squares, and the others are all empty squares. It is guaranteed that Squares
(1, 1) and (H, W) are empty squares.
Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right
or down to an adjacent empty square.
Find the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7. | [{"input": "3 4 2\n 2 2\n 1 4", "output": "3\n \n\nThere are three paths as follows:\n\n\n\n* * *"}, {"input": "5 2 2\n 2 1\n 4 2", "output": "0\n \n\nThere may be no paths.\n\n* * *"}, {"input": "5 5 4\n 3 1\n 3 5\n 1 3\n 5 3", "output": "24\n \n\n* * *"}, {"input": "100000 100000 1\n 50000 50000", "output": "123445622\n \n\nBe sure to print the count modulo 10^9 + 7."}] |
Print the minimum positive integer divisible by both 2 and N.
* * * | s853668374 | Runtime Error | p03307 | Input is given from Standard Input in the following format:
N | n=int(input())
if n% !=0:
print(2*n)
else:
print(n) | Statement
You are given a positive integer N. Find the minimum positive integer
divisible by both 2 and N. | [{"input": "3", "output": "6\n \n\n6 is divisible by both 2 and 3. Also, there is no positive integer less than 6\nthat is divisible by both 2 and 3. Thus, the answer is 6.\n\n* * *"}, {"input": "10", "output": "10\n \n\n* * *"}, {"input": "999999999", "output": "1999999998"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.