output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s298100491
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
dic = {i: list(input()) for i in "abc"} key = "a" while len(dic[key]) != 0: key = dic.pop(0) print(key.upper())
Statement Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s286561873
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
dict = {ch: list(input()) for ch in "abc"} ch = "a" While (dict[ch]): ch = dict[ch].pop(0) print(ch.upper())
Statement Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s693322518
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
Sa = str(input()) Sb = str(input()) Sc = str(input()) def battle(Sa, Sb, Sc): now = "a" while len(Sa) >= 0 and len(Sb) >= 0 and len(Sc) >= 0: if now == "a": if len(Sa) == 0: return "A" now = Sa[0] Sa = Sa[1:] elif now == "b": if len(Sb) == 0: return "B" now = Sb[0] Sb = Sb[1:] elif now == "c": if len(Sc) == 0: return "C" now = Sc[0] Sc = Sc[1:] print(battle(Sa, Sb, Sc))
Statement Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s320555006
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
A = list(str(input())) B = list(str(input())) C = list(str(input())) x = "A" while True: if x == "A": l = A pass elif x == "B": l = B pass elif x == "C": l = C pass if len(l) == 0: print(x) break else: x = str.upper(l[0]) l.remove(l[0])
Statement Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s173936190
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
s = [input() for i in range(3)] l = [len(s[i]) for i in range(3)] abc = [0, 0, 0] now = 0 while abc[now] != l[now]: s_sub = s[now][abc[now]] abc[now] += 1 now = 0 if s_sub == "a" else 1 if s_sub == "b" else 2 print("A" if now == 0 else "B" if now == 1 else "C")
Statement Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s542427159
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
S_A = input() S_B = input() S_C = input() i_A = 0 i_B = 0 i_C = 0 def AIf(): if i_A == len(S_A): return "A" if S_A[i_A] == "a": i_A += 1 IfA() if S_A[i_A] == "b": i_A += 1 IfB() if S_A[i_A] == "c": i_A += 1 IfC() def IfA(): if i_A == len(S_A): return "A" if S_A[i_A] == "a": i_A += 1 AIf() if S_A[i_A] == "b": i_A += 1 IfB() if S_A[i_A] == "c": i_A += 1 IfC() def BIf(): if i_B == len(S_B): return "B" if S_B[i_B] == "a": i_B += 1 IfA() if S_B[i_B] == "b": i_B += 1 IfB() if S_B[i_B] == "c": i_B += 1 IfC() def IfB(): if i_B == len(S_B): return "B" if S_B[i_B] == "a": i_B += 1 IfA() if S_B[i_B] == "b": i_B += 1 BIf() if S_B[i_B] == "c": i_B += 1 IfC() def CIf(): if i_C == len(S_C): return "C" if S_C[i_C] == "a": i_C += 1 IfA() if S_C[i_C] == "b": i_C += 1 IfB() if S_C[i_c] == "c": i_C += 1 IfC() def IfC(): if i_C == len(S_C): return "C" if S_C[i_C] == "a": i_C += 1 IfA() if S_C[i_C] == "b": i_C += 1 IfB() if S_C[i_c] == "c": i_C += 1 CIf() IfA()
Statement Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
Print the vertices numbers in order. Print a number in a line. If there are multiple possible solutions, print any one of them (the solution is judged by a special validator).
s102639518
Accepted
p02370
A directed graph $G$ is given in the following format: $|V|\;|E|$ $s_0 \; t_0$ $s_1 \; t_1$ : $s_{|E|-1} \; t_{|E|-1}$ $|V|$ is the number of vertices and $|E|$ is the number of edges in the graph. The graph vertices are named with the numbers $0, 1,..., |V|-1$ respectively. $s_i$ and $t_i$ represent source and target nodes of $i$-th edge (directed).
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 6 0 1 1 2 3 1 3 4 4 5 5 2 output: 0 3 1 4 5 2 """ from sys import stdin from collections import deque UNVISITED, VISITED_IN_QUEUE, POPPED_OUT = 0, 1, 2 def generate_adj_matrix(_v_info): for v_detail in _v_info: v_from, v_to = map(int, v_detail) init_adj_table[v_from].append(v_to) init_in_deg_list[v_to] += 1 return init_adj_table, init_in_deg_list def topological_sort(): for v in range(vertices): if not in_deg_list[v] and status[v] is UNVISITED: bfs(v) return ans def bfs(v): queue = deque() queue.append(v) status[v] = VISITED_IN_QUEUE while queue: current = queue.popleft() ans.append(current) for v_adj in adj_table[current]: in_deg_list[v_adj] -= 1 if not in_deg_list[v_adj] and status[v_adj] is UNVISITED: status[v_adj] = VISITED_IN_QUEUE queue.appendleft(v_adj) status[current] = POPPED_OUT return None if __name__ == "__main__": _input = stdin.readlines() vertices, edges = map(int, _input[0].split()) v_info = map(lambda x: x.split(), _input[1:]) status = [UNVISITED] * vertices init_adj_table = tuple([] for _ in range(vertices)) init_in_deg_list = [0] * vertices ans = [] adj_table, in_deg_list = generate_adj_matrix(v_info) print(*topological_sort(), sep="\n")
Topological Sort ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_GRL_tsort) A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You can obtain the proper sequence of all the tasks by a topological sort. Given a DAG $G$, print the order of vertices after the topological sort.
[{"input": "6\n 0 1\n 1 2\n 3 1\n 3 4\n 4 5\n 5 2", "output": "3\n 1\n 4\n 5\n 2"}]
Print the vertices numbers in order. Print a number in a line. If there are multiple possible solutions, print any one of them (the solution is judged by a special validator).
s922574335
Accepted
p02370
A directed graph $G$ is given in the following format: $|V|\;|E|$ $s_0 \; t_0$ $s_1 \; t_1$ : $s_{|E|-1} \; t_{|E|-1}$ $|V|$ is the number of vertices and $|E|$ is the number of edges in the graph. The graph vertices are named with the numbers $0, 1,..., |V|-1$ respectively. $s_i$ and $t_i$ represent source and target nodes of $i$-th edge (directed).
#!/usr/bin/python3 import os import sys def main(): sys.setrecursionlimit(100000) V, E = read_ints() G = [set() for _ in range(V)] for _ in range(E): s, t = read_ints() G[s].add(t) print(*solve(V, E, G), sep="\n") def solve(V, E, G): topo = [] done = [False] * V def dfs(i): if done[i]: return for j in G[i]: dfs(j) done[i] = True topo.append(i) for i in range(V): if not done[i]: dfs(i) topo.reverse() return topo ############################################################################### # AUXILIARY FUNCTIONS DEBUG = "DEBUG" in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return [int(e) for e in inp().split()] def dprint(*value, sep=" ", end="\n"): if DEBUG: print(*value, sep=sep, end=end) if __name__ == "__main__": main()
Topological Sort ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_GRL_tsort) A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You can obtain the proper sequence of all the tasks by a topological sort. Given a DAG $G$, print the order of vertices after the topological sort.
[{"input": "6\n 0 1\n 1 2\n 3 1\n 3 4\n 4 5\n 5 2", "output": "3\n 1\n 4\n 5\n 2"}]
Print the vertices numbers in order. Print a number in a line. If there are multiple possible solutions, print any one of them (the solution is judged by a special validator).
s216648535
Accepted
p02370
A directed graph $G$ is given in the following format: $|V|\;|E|$ $s_0 \; t_0$ $s_1 \; t_1$ : $s_{|E|-1} \; t_{|E|-1}$ $|V|$ is the number of vertices and $|E|$ is the number of edges in the graph. The graph vertices are named with the numbers $0, 1,..., |V|-1$ respectively. $s_i$ and $t_i$ represent source and target nodes of $i$-th edge (directed).
from sys import stdin from collections import deque n, e = map(int, stdin.readline().split()) G = [[] for _ in [0] * n] indeg = [0] * n out = [] V = [False] * n def bfs(s): dq = deque([s]) V[s] = True while dq: u = dq.popleft() out.append(u) for i in range(len(G[u])): v = G[u][i] indeg[v] -= 1 if indeg[v] == 0 and not V[v]: V[v] = True dq.append(v) def tsort(): for u in range(n): for i in range(len(G[u])): indeg[G[u][i]] += 1 for u in range(n): if indeg[u] == 0 and not V[u]: bfs(u) for i in range(len(out)): print(out[i]) for _ in [0] * e: s, t = map(int, stdin.readline().split()) G[s].append(t) tsort()
Topological Sort ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_GRL_tsort) A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You can obtain the proper sequence of all the tasks by a topological sort. Given a DAG $G$, print the order of vertices after the topological sort.
[{"input": "6\n 0 1\n 1 2\n 3 1\n 3 4\n 4 5\n 5 2", "output": "3\n 1\n 4\n 5\n 2"}]
Print the vertices numbers in order. Print a number in a line. If there are multiple possible solutions, print any one of them (the solution is judged by a special validator).
s918351099
Accepted
p02370
A directed graph $G$ is given in the following format: $|V|\;|E|$ $s_0 \; t_0$ $s_1 \; t_1$ : $s_{|E|-1} \; t_{|E|-1}$ $|V|$ is the number of vertices and $|E|$ is the number of edges in the graph. The graph vertices are named with the numbers $0, 1,..., |V|-1$ respectively. $s_i$ and $t_i$ represent source and target nodes of $i$-th edge (directed).
from collections import defaultdict def topological_sort(N, edges): def dfs(u): used[u] = True for v in edges[u]: if not used[v]: dfs(v) result.append(u) used = [False] * N result = [] for i in range(N): if not used[i]: dfs(i) return result[::-1] def main(): N, M = map(int, input().split()) edges = defaultdict(list) for _ in range(M): s, t = map(int, input().split()) edges[s].append(t) ans = topological_sort(N, edges) print(*ans) if __name__ == "__main__": main()
Topological Sort ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_GRL_tsort) A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You can obtain the proper sequence of all the tasks by a topological sort. Given a DAG $G$, print the order of vertices after the topological sort.
[{"input": "6\n 0 1\n 1 2\n 3 1\n 3 4\n 4 5\n 5 2", "output": "3\n 1\n 4\n 5\n 2"}]
Print the number of ways to divide the people into groups under the conditions, modulo 10^9+7. * * *
s602530152
Accepted
p03832
The input is given from Standard Input in the following format: N A B C D
n, a, b, c, d = map(int, input().split()) mod = 10**9 + 7 l = 2 * 10**6 fac = [1] * l facr = [1] * l for i in range(l - 1): fac[i + 1] = fac[i] * (i + 1) % mod facr[l - 1] = pow(fac[l - 1], mod - 2, mod) for i in range(1, l)[::-1]: facr[i - 1] = facr[i] * i % mod def combi(N, K): return fac[N] * facr[N - K] % mod * facr[K] % mod dp = [[0] * (n + 1) for i in range(n + 1)] dp[0][0] = 1 for i in range(n): for j in range(n + 1): dp[i + 1][j] += dp[i][j] dp[i + 1][j] %= mod if not a <= i + 1 <= b: continue for m in range(c, d + 1): if j + m * (i + 1) > n: break dp[i + 1][j + m * (i + 1)] += ( dp[i][j] * fac[(i + 1) * m] * pow(facr[(i + 1)], m, mod) * facr[m] * combi(n - j, (i + 1) * m) ) dp[i + 1][j + m * (i + 1)] %= mod print(dp[n][n] % mod) # print(dp)
Statement There are N people, conveniently numbered 1 through N. We want to divide them into some number of groups, under the following two conditions: * Every group contains between A and B people, inclusive. * Let F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds. Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count modulo 10^9+7.
[{"input": "3 1 3 1 2", "output": "4\n \n\nThere are four ways to divide the people:\n\n * (1,2),(3)\n * (1,3),(2)\n * (2,3),(1)\n * (1,2,3)\n\nThe following way to divide the people does not count: (1),(2),(3). This is\nbecause it only satisfies the first condition and not the second.\n\n* * *"}, {"input": "7 2 3 1 3", "output": "105\n \n\nThe only ways to divide the people under the conditions are the ones where\nthere are two groups of two people, and one group of three people. There are\n105 such ways.\n\n* * *"}, {"input": "1000 1 1000 1 1000", "output": "465231251\n \n\n* * *"}, {"input": "10 3 4 2 5", "output": "0\n \n\nThe answer can be 0."}]
Print the number of ways to divide the people into groups under the conditions, modulo 10^9+7. * * *
s456001872
Wrong Answer
p03832
The input is given from Standard Input in the following format: N A B C D
import os import sys # import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 def get_factorials(max, mod=None): """ 階乗 0!, 1!, 2!, ..., max! :param int max: :param int mod: :return: """ ret = [1] n = 1 if mod: for i in range(1, max + 1): n *= i n %= mod ret.append(n) else: for i in range(1, max + 1): n *= i ret.append(n) return ret def mod_invs(max, mod): """ 逆元のリスト 0 から max まで :param int max: :param int mod: """ invs = [1] * (max + 1) for x in range(2, max + 1): invs[x] = (-(mod // x) * invs[mod % x]) % mod return invs def factorial_invs(max, mod): """ 階乗 0!, 1!, 2!, ..., max! の逆元 :param int max: :param int mod: """ ret = [] r = 1 for inv in mod_invs(max, mod): r = r * inv % mod ret.append(r) return ret class Combination: def __init__(self, max, mod): """ :param int max: :param int mod: 3 以上の素数であること """ self._factorials = get_factorials(max, mod) self._finvs = factorial_invs(max, mod) self._mod = mod # @debug def ncr(self, n, r): """ :param int n: :param int r: :rtype: int """ if n < r: return 0 return ( self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod ) N, A, B, C, D = list(map(int, sys.stdin.buffer.readline().split())) comb = Combination(max=N + 1, mod=MOD) # dp[u][i]: u 人のグループまでみて、合計 i 人のグループ分けをする方法の数 dp = [[0] * (N + 1) for _ in range(N + 1)] for u in range(N + 1): dp[u][0] = 1 for unit in range(A, B + 1): for j in reversed(range(N + 1)): dp[unit][j] = dp[unit - 1][j] ncr = 1 for cnt in range(C, D + 1): if j + unit * cnt > N: break ncr = ncr * comb.ncr(N - j - unit * (cnt - 1), unit) % MOD dp[unit][j + unit * cnt] += dp[unit - 1][j] * ncr * comb._finvs[cnt] % MOD dp[unit][j + unit * cnt] %= MOD print(dp[B][N])
Statement There are N people, conveniently numbered 1 through N. We want to divide them into some number of groups, under the following two conditions: * Every group contains between A and B people, inclusive. * Let F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds. Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count modulo 10^9+7.
[{"input": "3 1 3 1 2", "output": "4\n \n\nThere are four ways to divide the people:\n\n * (1,2),(3)\n * (1,3),(2)\n * (2,3),(1)\n * (1,2,3)\n\nThe following way to divide the people does not count: (1),(2),(3). This is\nbecause it only satisfies the first condition and not the second.\n\n* * *"}, {"input": "7 2 3 1 3", "output": "105\n \n\nThe only ways to divide the people under the conditions are the ones where\nthere are two groups of two people, and one group of three people. There are\n105 such ways.\n\n* * *"}, {"input": "1000 1 1000 1 1000", "output": "465231251\n \n\n* * *"}, {"input": "10 3 4 2 5", "output": "0\n \n\nThe answer can be 0."}]
Print the number of ways to divide the people into groups under the conditions, modulo 10^9+7. * * *
s651874010
Wrong Answer
p03832
The input is given from Standard Input in the following format: N A B C D
#### import #### import sys import math from collections import defaultdict #### 設定 #### sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] #### 定数 #### mod = 10**9 + 7 #### 読み込み #### def I(): return int(input()) def II(): return map(int, input().split()) def III(): return list(map(int, input().split())) def Line(N): read_all = [tuple(map(int, input().split())) for _ in range(N)] return map(list, zip(*read_all)) ################# # 互いに素なa,bについて、a*x+b*y=1の一つの解[x,y]を出力 def extgcd(a, b): r = [1, 0, a] w = [0, 1, b] while w[2] != 1: q = r[2] // w[2] r2 = w w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]] r = r2 w = w2 return [w[0], w[1]] # aの逆元(mod M)を求める(aとMは互いに素であることが前提) def mod_inv(a, M=mod): x = extgcd(a, M)[0] return (M + x % M) % M # 0!からn!までをmodしつつ計算 def mod_fact(n, Mod=mod): d = [1] * (n + 1) for i in range(1, n + 1): d[i] = d[i - 1] * i % Mod return d N, A, B, C, D = II() value = [0] for i in range(C, D + 1): value.append(i) fact = mod_fact(N) inv = [0] * (N + 1) inv[N] = mod_inv(fact[N]) for i in range(1, N + 1)[::-1]: inv[i - 1] = inv[i] * i % mod dp = [[0] * (N + 1) for _ in range(B + 1)] for i in range(B): dp[i + 1][0] = 1 for i in range(A, B + 1): for j in range(A, N + 1): if i == A: if j % A != 0: continue else: num = j // A if C <= num <= D: dp[i][j] = ( fact[N] * inv[N - j] * inv[num] * pow(inv[A], num, mod) ) % mod else: for k in value: if k > j // i: break else: dp[i][j] += ( dp[i - 1][j - i * k] * fact[N - j + i * k] * inv[N - j] * pow(inv[i], k, mod) * inv[k] ) % mod print(dp[B][N])
Statement There are N people, conveniently numbered 1 through N. We want to divide them into some number of groups, under the following two conditions: * Every group contains between A and B people, inclusive. * Let F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds. Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count modulo 10^9+7.
[{"input": "3 1 3 1 2", "output": "4\n \n\nThere are four ways to divide the people:\n\n * (1,2),(3)\n * (1,3),(2)\n * (2,3),(1)\n * (1,2,3)\n\nThe following way to divide the people does not count: (1),(2),(3). This is\nbecause it only satisfies the first condition and not the second.\n\n* * *"}, {"input": "7 2 3 1 3", "output": "105\n \n\nThe only ways to divide the people under the conditions are the ones where\nthere are two groups of two people, and one group of three people. There are\n105 such ways.\n\n* * *"}, {"input": "1000 1 1000 1 1000", "output": "465231251\n \n\n* * *"}, {"input": "10 3 4 2 5", "output": "0\n \n\nThe answer can be 0."}]
Print the number of ways to divide the people into groups under the conditions, modulo 10^9+7. * * *
s459010169
Runtime Error
p03832
The input is given from Standard Input in the following format: N A B C D
N, A, B, C, D = map(int, input().split()) memo = {} def factorial(x): if x in memo: return memo[x] if x <= 1: ret = 1 else: ret = x * factorial(x - 1) memo[x] = ret return ret def process(N, groups, total, num, B, C, D): if num > B: if total != N: return 0 print(groups) rest = N ret = 1 for g, n in groups: for k in range(n): ret *= factorial(rest) / factorial(g) / factorial(rest - g) rest -= g ret //= factorial(n) return ret ret = 0 for n in [0] + list(range(C, D + 1)): nextTotal = total + num * n if nextTotal <= N: ret += process(N, groups + [(num, n)], nextTotal, num + 1, B, C, D) return ret print(process(N, [], 0, A, B, C, D))
Statement There are N people, conveniently numbered 1 through N. We want to divide them into some number of groups, under the following two conditions: * Every group contains between A and B people, inclusive. * Let F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds. Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count modulo 10^9+7.
[{"input": "3 1 3 1 2", "output": "4\n \n\nThere are four ways to divide the people:\n\n * (1,2),(3)\n * (1,3),(2)\n * (2,3),(1)\n * (1,2,3)\n\nThe following way to divide the people does not count: (1),(2),(3). This is\nbecause it only satisfies the first condition and not the second.\n\n* * *"}, {"input": "7 2 3 1 3", "output": "105\n \n\nThe only ways to divide the people under the conditions are the ones where\nthere are two groups of two people, and one group of three people. There are\n105 such ways.\n\n* * *"}, {"input": "1000 1 1000 1 1000", "output": "465231251\n \n\n* * *"}, {"input": "10 3 4 2 5", "output": "0\n \n\nThe answer can be 0."}]
Print the answer. * * *
s437664050
Runtime Error
p02720
Input is given from Standard Input in the following format: K
K = int(input()) list = [1,2,3,4,5,6,7,8,9] for i in range(K+1) v = list.pop(0) t = v%10 s = 10*v if t != 0: list.append(s + (t-1)) list.append(s + t) if t != 9: list.append(s + (t+1)) print(v)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s306029928
Accepted
p02720
Input is given from Standard Input in the following format: K
k = int(input()) lun = [str(i) for i in range(1, 10)] L = [str(i) for i in range(1, 10)] nL = [] while len(lun) < 10**5: for num in L: l = num[-1] lm = int(l) - 1 lp = int(l) + 1 nL.append(num + l) if lm >= 0: nL.append(num + str(lm)) if lp < 10: nL.append(num + str(lp)) lun.extend(nL) L = nL nL = [] lunlun = [int(x) for x in lun] lunlun.sort() print(lunlun[k - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s984261865
Accepted
p02720
Input is given from Standard Input in the following format: K
X = int(input()) a = [1, 2, 3, 4, 5, 6, 7, 8, 9] if 1 <= X <= 10**5: while len(a) < X: i = 0 for i in range(X - 10): if i < len(a): c = int(a[i]) d = 10 * c b = c % 10 b_1 = b - 1 b_2 = b b_3 = b + 1 if (b_1 >= 0) and (b_3 < 10): a_1 = d + b_1 a_2 = d + b_2 a_3 = d + b_3 a.append(a_1) a.append(a_2) a.append(a_3) elif b_1 < 0: a_2 = d + b_2 a_3 = d + b_3 a.append(a_2) a.append(a_3) else: a_1 = d + b_1 a_2 = d + b_2 a.append(a_1) a.append(a_2) i += 1 a = sorted(a) print(a[X - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s696511921
Accepted
p02720
Input is given from Standard Input in the following format: K
import sys sys.setrecursionlimit(10**5) k = int(input()) a = [str(i) for i in range(1, 10)] def lunlun(s): a = int(s[-1]) if a == 0: l = [0, 1] elif a == 9: l = [8, 9] else: l = [a - 1, a, a + 1] ret = [] for i in l: ret.append(s + str(i)) return ret n_2 = [] for i in a: temp = lunlun(i) for i in temp: n_2.append(i) n_3 = [] for i in n_2: temp = lunlun(i) for i in temp: n_3.append(i) n_4 = [] for i in n_3: temp = lunlun(i) for i in temp: n_4.append(i) n_5 = [] for i in n_4: temp = lunlun(i) for i in temp: n_5.append(i) n_6 = [] for i in n_5: temp = lunlun(i) for i in temp: n_6.append(i) n_7 = [] for i in n_6: temp = lunlun(i) for i in temp: n_7.append(i) n_8 = [] for i in n_7: temp = lunlun(i) for i in temp: n_8.append(i) n_9 = [] for i in n_8: temp = lunlun(i) for i in temp: n_9.append(i) n_10 = [] for i in n_9: temp = lunlun(i) for i in temp: n_10.append(i) a.extend(n_2) a.extend(n_3) a.extend(n_4) a.extend(n_5) a.extend(n_6) a.extend(n_7) a.extend(n_8) a.extend(n_9) a.extend(n_10) print(str(a[k - 1]))
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s097254610
Accepted
p02720
Input is given from Standard Input in the following format: K
import itertools k = int(input()) def a(b): list_ = [] for i in b: ii = str(i) z = int(ii[-1]) if z == 0: list_.append(int(ii + "0")) list_.append(int(ii + "1")) elif z == 9: list_.append(int(ii + "8")) list_.append(int(ii + "9")) else: list_.append(int(ii + str(z - 1))) list_.append(int(ii + str(z))) list_.append(int(ii + str(z + 1))) return list_ l1 = [[1]] for _ in range(9): l1.append(a(l1[-1])) c1 = list(itertools.chain.from_iterable(l1)) l2 = [[2]] for _ in range(9): l2.append(a(l2[-1])) c2 = list(itertools.chain.from_iterable(l2)) l3 = [[3]] for _ in range(9): l3.append(a(l3[-1])) c3 = list(itertools.chain.from_iterable(l3)) l4 = [[4]] for _ in range(9): l4.append(a(l4[-1])) c4 = list(itertools.chain.from_iterable(l4)) l5 = [[5]] for _ in range(9): l5.append(a(l5[-1])) c5 = list(itertools.chain.from_iterable(l5)) l6 = [[6]] for _ in range(9): l6.append(a(l6[-1])) c6 = list(itertools.chain.from_iterable(l6)) l7 = [[7]] for _ in range(9): l7.append(a(l7[-1])) c7 = list(itertools.chain.from_iterable(l7)) l8 = [[8]] for _ in range(9): l8.append(a(l8[-1])) c8 = list(itertools.chain.from_iterable(l8)) l9 = [[9]] for _ in range(9): l9.append(a(l9[-1])) c9 = list(itertools.chain.from_iterable(l9)) cc = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 cc.sort() print(cc[k - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s537873266
Runtime Error
p02720
Input is given from Standard Input in the following format: K
k = int(input()) a = [9, 8, 7, 6, 5, 4, 3, 2, 1] current_str = "" for i in range(k): current_str = str(a.pop()) current = list(current_str) candidates = [] if current[-1] == "0": cp = current.copy() cp1 = current.copy() cp.append("0") cp1.append("1") candidates.append(int("".join(cp))) candidates.append(int("".join(cp1))) elif current[-1] == "9": cp = current.copy() cp1 = current.copy() cp.append("8") cp1.append("9") candidates.append(int("".join(cp))) candidates.append(int("".join(cp1))) else: cp = current.copy() cp1 = current.copy() cp2 = current.copy() cp.append(str(int(current[-1]) - 1)) cp1.append(str(int(current[-1]))) cp2.append(str(int(current[-1]) + 1)) candidates.append("".join(cp)) candidates.append("".join(cp1)) candidates.append("".join(cp2)) for c in candidates: a.insert(0, int(c)) print(current_str)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s537295108
Runtime Error
p02720
Input is given from Standard Input in the following format: K
k = int(input()) num_digit = [0] * 10 # num_digit[i]は10^i以下のルンルン数の個数 num_digit[0] = 9 tmp = [[0] * 10 for i in range(10)] # tmp[i][j]はi+1桁で最高位jの個数 tmp[0] = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in range(1, 9): num_digit[i] = num_digit[i - 1] tmp[i][0] = tmp[i - 1][0] + tmp[i - 1][1] num_digit[i] += tmp[i][0] for j in range(1, 9): tmp[i][j] = tmp[i - 1][j - 1] + tmp[i - 1][j] + tmp[i - 1][j + 1] num_digit[i] += tmp[i][j] tmp[i][9] = tmp[i - 1][8] + tmp[i - 1][9] num_digit[i] += tmp[i][9] def lnln(n): ans = 0 d = 0 tmp_n = n while num_digit[d] < n: d += 1 tmp_n -= num_digit[d - 1] while tmp[d][ans] < tmp_n: tmp_n -= tmp[d][ans] ans += 1 ans *= 10**d if n > 9: ans += lnln(tmp_n) return ans print(lnln(k))
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s570739511
Accepted
p02720
Input is given from Standard Input in the following format: K
k = int(input()) lst = [i for i in range(1, 10)] left = 0 right = 9 while len(lst) < k: for i in range(left, right + 1): if lst[i] % 10 > 0: lst.append(lst[i] * 10 + lst[i] % 10 - 1) lst.append(lst[i] * 10 + lst[i] % 10) if lst[i] % 10 < 9: lst.append(lst[i] * 10 + lst[i] % 10 + 1) left = right + 1 right = len(lst) - 1 print(lst[k - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s201714294
Accepted
p02720
Input is given from Standard Input in the following format: K
from collections import deque K = int(input()) queue = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) lunlun = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] while len(queue) < 10**5: n_str = queue.popleft() last_c = n_str[len(n_str) - 1] if last_c == "0": queue.append(n_str + "0") queue.append(n_str + "1") lunlun.append(n_str + "0") lunlun.append(n_str + "1") elif last_c == "1": queue.append(n_str + "0") queue.append(n_str + "1") queue.append(n_str + "2") lunlun.append(n_str + "0") lunlun.append(n_str + "1") lunlun.append(n_str + "2") elif last_c == "2": queue.append(n_str + "1") queue.append(n_str + "2") queue.append(n_str + "3") lunlun.append(n_str + "1") lunlun.append(n_str + "2") lunlun.append(n_str + "3") elif last_c == "3": queue.append(n_str + "2") queue.append(n_str + "3") queue.append(n_str + "4") lunlun.append(n_str + "2") lunlun.append(n_str + "3") lunlun.append(n_str + "4") elif last_c == "4": queue.append(n_str + "3") queue.append(n_str + "4") queue.append(n_str + "5") lunlun.append(n_str + "3") lunlun.append(n_str + "4") lunlun.append(n_str + "5") elif last_c == "5": queue.append(n_str + "4") queue.append(n_str + "5") queue.append(n_str + "6") lunlun.append(n_str + "4") lunlun.append(n_str + "5") lunlun.append(n_str + "6") elif last_c == "6": queue.append(n_str + "5") queue.append(n_str + "6") queue.append(n_str + "7") lunlun.append(n_str + "5") lunlun.append(n_str + "6") lunlun.append(n_str + "7") elif last_c == "7": queue.append(n_str + "6") queue.append(n_str + "7") queue.append(n_str + "8") lunlun.append(n_str + "6") lunlun.append(n_str + "7") lunlun.append(n_str + "8") elif last_c == "8": queue.append(n_str + "7") queue.append(n_str + "8") queue.append(n_str + "9") lunlun.append(n_str + "7") lunlun.append(n_str + "8") lunlun.append(n_str + "9") elif last_c == "9": queue.append(n_str + "8") queue.append(n_str + "9") lunlun.append(n_str + "8") lunlun.append(n_str + "9") print(lunlun[K - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s473101077
Accepted
p02720
Input is given from Standard Input in the following format: K
K = int(input()) arr = list(range(1, 10)) i = 0 while len(arr) < K: num = arr[i] last = list(filter(lambda x: 0 <= x <= 9, [num % 10 - 1, num % 10, num % 10 + 1])) arr.extend(num * 10 + t for t in last) i += 1 # print(arr) print(arr[K - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s825013432
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
N = int(input()) def check(a): s = str(a) if len(s) == 1: return True for i in range(1, len(s)): if abs(int(s[i - 1]) - int(s[i])) > 1: return False return True def solve(N): m = 10**5 ct = 0 for i in range(1, m + 1): if check(i): ct += 1 if ct == N: return i print(solve(N))
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s215230396
Runtime Error
p02720
Input is given from Standard Input in the following format: K
k = int(input()) array = [] for i in range(1, 100000 + 1): s = str(i) try: a = abs(int(s[0]) - int(s[1])) if a < 2: try: b = abs(int(s[1]) - int(s[2])) if b < 2: try: c = abs(int(s[2]) - int(s[3])) if c < 2: try: d = abs(int(s[3]) - int(s[4])) if d < 2: try: e = abs(int(s[4]) - int(s[5])) if e < 2: array.append(int(i)) except IndexError: array.append(int(i)) except IndexError: array.append(int(i)) except IndexError: array.append(int(i)) except IndexError: array.append(int(i)) except IndexError: array.append(int(i)) print(array[k - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s197946639
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
K = int(input()) from itertools import product d = {} num_list = [] for i in range(10): nums = set([min((i - 1) % 10, i), i, max((i + 1) % 10, i)]) # nums = set([i, min(10-(i-1)%10, i),max((i+1)%10, i)]) nums = [str(el) for el in nums] d[i] = list(product([str(i)], list(nums))) d[i] = [int("".join(el)) for el in d[i]] d[i] = ["{:02}".format(el) for el in d[i]] num_list.extend(d[i]) num_list = sorted(num_list) dd = [ None, None, d, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(1, 10)}, {i: [] for i in range(10)}, ] def gen_2ll(): count = 0 ret = 0 while int(ret) != 99: if int(ret) < 9: ret += 1 count += 1 yield ret else: for i in range(1, 10): for ret in d[i]: count += 1 yield ret ll2_list = list(gen_2ll()) def get_digit_top_list(num_digit, top_num): # print(333, num_digit, top_num) if top_num == 0 and num_digit > 2: lls = [] for top_num in range(1, 10): lls.extend(get_digit_top_list(num_digit - 1, top_num)) # print(44444,lls) return ["0" + el for el in lls] ret = dd[num_digit][top_num] if ret: return ret second_nums = sorted( set( [ min((top_num - 1) % 10, top_num), top_num, max((top_num + 1) % 10, top_num), ] ) ) for second_num in second_nums: # print(111,dd[num_digit][top_num]) rem_nums = get_digit_top_list(num_digit - 1, int(second_num)) for rem_num in rem_nums: ll = str(top_num) + rem_num ret.append(ll) dd[num_digit][top_num] = ret return ret def get_kth_ll(K): if K <= len(ll2_list): print(ll2_list[K - 1]) else: K -= len(ll2_list) for num_digit in range(3, 100): for top_num in range(1, 10): _ll_list = get_digit_top_list(num_digit, top_num) # print(222, K, len(_ll_list)) if K - len(_ll_list) < 0: print(sorted([int(el) for el in _ll_list])[K - 1]) return None else: K -= len(_ll_list) get_kth_ll(K)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s204263195
Runtime Error
p02720
Input is given from Standard Input in the following format: K
K = int(input()) list0 = ["0"] list1 = ["1"] list2 = ["2"] list3 = ["3"] list4 = ["4"] list5 = ["5"] list6 = ["6"] list7 = ["7"] list8 = ["8"] list9 = ["9"] an = 0 def AAA(list0, list1, list2, list3, list4, list5, list6, list7, list8, list9): nlist0 = [0] * (len(list0) + len(list1)) nlist1 = [0] * (len(list0) + len(list1) + len(list2)) nlist2 = [0] * (len(list1) + len(list2) + len(list3)) nlist3 = [0] * (len(list2) + len(list3) + len(list4)) nlist4 = [0] * (len(list3) + len(list4) + len(list5)) nlist5 = [0] * (len(list4) + len(list5) + len(list6)) nlist6 = [0] * (len(list5) + len(list6) + len(list7)) nlist7 = [0] * (len(list6) + len(list7) + len(list8)) nlist8 = [0] * (len(list7) + len(list8) + len(list9)) nlist9 = [0] * (len(list8) + len(list9)) for i in range(len(list0)): nlist0[i] = "0" + list0[i] for j in range(len(list1)): nlist0[len(list0) + j] = "0" + list1[j] for i in range(len(list0)): nlist1[i] = "1" + list0[i] for j in range(len(list1)): nlist1[len(list0) + j] = "1" + list1[j] for k in range(len(list2)): nlist1[len(list0) + len(list1) + k] = "1" + list2[k] for i in range(len(list1)): nlist2[i] = "2" + list1[i] for j in range(len(list2)): nlist2[len(list1) + j] = "2" + list2[j] for k in range(len(list3)): nlist2[len(list1) + len(list2) + k] = "2" + list3[k] for i in range(len(list2)): nlist3[i] = "3" + list2[i] for j in range(len(list3)): nlist3[len(list2) + j] = "3" + list3[j] for k in range(len(list4)): nlist3[len(list2) + len(list3) + k] = "3" + list4[k] for i in range(len(list3)): nlist4[i] = "4" + list3[i] for j in range(len(list4)): nlist4[len(list3) + j] = "4" + list4[j] for k in range(len(list5)): nlist4[len(list3) + len(list4) + k] = "4" + list5[k] for i in range(len(list4)): nlist5[i] = "5" + list4[i] for j in range(len(list5)): nlist5[len(list4) + j] = "5" + list5[j] for k in range(len(list6)): nlist5[len(list4) + len(list5) + k] = "5" + list6[k] for i in range(len(list5)): nlist6[i] = "6" + list5[i] for j in range(len(list6)): nlist6[len(list5) + j] = "6" + list6[j] for k in range(len(list7)): nlist6[len(list5) + len(list6) + k] = "6" + list7[k] for i in range(len(list6)): nlist7[i] = "7" + list6[i] for j in range(len(list7)): nlist7[len(list6) + j] = "7" + list7[j] for k in range(len(list8)): nlist7[len(list6) + len(list7) + k] = "7" + list8[k] for i in range(len(list7)): nlist8[i] = "8" + list7[i] for j in range(len(list8)): nlist8[len(list7) + j] = "8" + list8[j] for k in range(len(list9)): nlist8[len(list7) + len(list8) + k] = "8" + list9[k] for i in range(len(list8)): nlist9[i] = "9" + list8[i] for j in range(len(list9)): nlist9[len(list8) + j] = "9" + list9[j] return ( nlist0, nlist1, nlist2, nlist3, nlist4, nlist5, nlist6, nlist7, nlist8, nlist9, ) while ( len(list1) + len(list2) + len(list3) + len(list4) + len(list5) + len(list6) + len(list7) + len(list8) + len(list9) < K ): an = ( an + len(list1) + len(list2) + len(list3) + len(list4) + len(list5) + len(list6) + len(list7) + len(list8) + len(list9) ) list0, list1, list2, list3, list4, list5, list6, list7, list8, list9 = AAA( list0, list1, list2, list3, list4, list5, list6, list7, list8, list9 ) nK = K - an if len(list1) >= nK: ans = list1[nK - 1] nK = 10**8 else: nK = nK - len(list1) if len(list2) >= nK: ans = list2[nK - 1] nK = 10**8 else: nK = nK - len(list2) if len(list3) >= nK: ans = list3[nK - 1] nK = 10**8 else: nK = nK - len(list3) if len(list4) >= nK: ans = list4[nK - 1] nK = 10**8 else: nK = nK - len(list4) if len(list5) >= nK: ans = list5[nK - 1] nK = 10**8 else: nK = nK - len(list5) if len(list6) >= nK: ans = list6[nK - 1] nK = 10**8 else: nK = nK - len(list6) if len(list7) >= nK: ans = list7[nK - 1] nK = 10**8 else: nK = nK - len(list7) if len(list8) >= nK: ans = list8[nK - 1] nK = 10**8 else: nK = nK - len(list8) if len(list9) >= nK: ans = list9[nK - 1] nK = 10**8 else: nK = nK - len(list9) print(int(ans))
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s963071302
Accepted
p02720
Input is given from Standard Input in the following format: K
def LunLun(k, count, base): nx = [] n = len(base) if count + n >= k: ans = base[k - count - 1] return ans for x in base: count += 1 p = x % 10 x *= 10 a = x + p - 1 b = a + 1 c = b + 1 n = 3 if p == 0: n -= 1 nx.extend([b, c]) elif p == 9: n -= 1 nx.extend([a, b]) else: nx.extend([a, b, c]) return LunLun(k, count, nx) def main(): k = int(input()) base = range(1, 10) ans = LunLun(k, 0, base) print(ans) if __name__ == "__main__": main()
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s387024926
Runtime Error
p02720
Input is given from Standard Input in the following format: K
from collections import deque K = int(input()) queue = deque([1,2,3,4,5,6,7,8,9]) count = 1 while count <= K: num = queue.popleft() if num%10!=0: queue.append(num*10+num%10-1) queue.append(num*10+num%10) if num%!=9: queue.append(num*10+num%10+1) print(num)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s570372919
Runtime Error
p02720
Input is given from Standard Input in the following format: K
K = int(input()) x = [[0] for _ in range(11)] y = [0 for _ in range(11)] x[1] = [1, 2, 3, 4, 5, 6, 7, 8, 9] y[1] = 9 for i in range(2, 11): x[i].pop() for num in x[i - 1]: last = num % 10 if last == 0: x[i].append(10 * num) x[i].append(10 * num + 1) y[i] += 2 elif last == 9: x[i].append(10 * num + 8) x[i].append(10 * num + 9) y[i] += 2 else: x[i].append(10 * num + (last - 1)) x[i].append(10 * num + last) x[i].append(10 * num + (last + 1)) y[i] += 3 # print(y) # print(sum(y)) z = [0, y[1]] for i in range(2, 11): z.append(z[-1] + y[i]) # print(z) maxi = 0 for r in range(11): if z[r] <= K: maxi = max(maxi, r) keta = maxi + 1 # print(K-y[maxi]) print(x[keta][K - y[maxi - 1]])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s257335269
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
# coding: utf-8 DATA = """ 100000 """.split( "\n" ) def get_debug_line(): for i in DATA: yield i if 1: get_line = input else: get_line = get_debug_line().__next__ get_line() def Calc(): K = [int(i) for i in get_line().strip().split(" ")][0] ret = [str(_) for _ in range(1, 10)] size = len(ret) start = 0 print(ret) count = len(ret) while size < K: for i in range(start, size): v = int(ret[i][-1]) ll = ret[i] if not v == 0: count += 1 ret.append(ll + str(v - 1)) ret.append(ll + str(v)) count += 1 if not v == 9: count += 1 ret.append(ll + str(v + 1)) if count >= K: break if count >= K: break start = size size = len(ret) print(ret[K - 1]) Calc()
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s348872968
Runtime Error
p02720
Input is given from Standard Input in the following format: K
k = int(input()) i = 10 lunlun = [i for i in range(1,10)] def check(n): place1 = n % 10 place10 = n // 10 if abs place10 - place1 == 1: return True else: return False while True: if check(i): lunlun.append(i,i+1,i+2) i += 3 if len(lunlun) > k: ans = i break else: i += 8 print(lunlun[k-1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s016765991
Accepted
p02720
Input is given from Standard Input in the following format: K
K = int(input()) F = {} for i in range(10): F[(1, i)] = 1 def f(n, d): if (n, d) in F: return F[(n, d)] nf = 0 for i in [d - 1, d, d + 1]: if 0 <= i <= 9: nf += f(n - 1, i) F[(n, d)] = nf return nf k = 0 p = (1, 0) for i in range(1, 11): for j in range(1, 10): fij = f(i, j) if k + fij >= K: p = (i, j) break k += fij p = (i, j) else: continue break def g(n, d, index): if n == 1: return str(d) total = 0 for i in [d - 1, d, d + 1]: if not 0 <= i <= 9: continue if total + f(n - 1, i) >= index: break total += f(n - 1, i) return str(d) + g(n - 1, i, index - total) print(g(p[0], p[1], K - k))
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s437107263
Accepted
p02720
Input is given from Standard Input in the following format: K
k = int(input()) if k < 10: print(k) else: k -= 9 run = {} run[1] = {i: 1 for i in range(0, 10)} now_dig = 1 flag = 0 flag2 = 0 ans = 0 while flag == 0: now_dig += 1 run[now_dig] = {} for num in range(0, 10): if num == 0: run[now_dig][num] = run[now_dig - 1][num] + run[now_dig - 1][num + 1] elif num == 9: run[now_dig][num] = run[now_dig - 1][num - 1] + run[now_dig - 1][num] else: run[now_dig][num] = ( run[now_dig - 1][num - 1] + run[now_dig - 1][num] + run[now_dig - 1][num + 1] ) if num != 0 and k - run[now_dig][num] > 0: k -= run[now_dig][num] elif num != 0: flag = 1 # print(k, now_dig, num) ans += num * pow(10, now_dig - 1) while now_dig > 1: now_dig -= 1 if num == 0: now_num = 0 end = 1 elif num == 9: now_num = 8 end = 9 else: now_num = num - 1 end = num + 1 while k - run[now_dig][now_num] > 0 and now_num <= end: k -= run[now_dig][now_num] now_num += 1 ans += now_num * pow(10, now_dig - 1) num = now_num break # print(now_dig, run[now_dig]) print(ans)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s374091712
Accepted
p02720
Input is given from Standard Input in the following format: K
# 最後に桁によって次の値の候補が定まる # 2kから末尾が出ることに注意 # k(桁) 1k=9 2k=26 3k=75 K = int(input()) count = 9 runrunnumber = [[] for _ in range(10)] runrunnumber[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9] # print(runrunnumber) if K > 10: for i in range(9): for j in runrunnumber[i]: if j % 10 == 0: for p in range(2): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 1: for p in range(3): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 2: for p in range(1, 4): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 3: for p in range(2, 5): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 4: for p in range(3, 6): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 5: for p in range(4, 7): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 6: for p in range(5, 8): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 7: for p in range(6, 9): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 8: for p in range(7, 10): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if j % 10 == 9: for p in range(8, 10): count += 1 tmp = j * 10 + p runrunnumber[i + 1].append(tmp) if count == K: print(tmp) break if count >= K: break if count >= K: break else: print(runrunnumber[0][K - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s606146170
Runtime Error
p02720
Input is given from Standard Input in the following format: K
import sys import resource sys.setrecursionlimit(10**9) resource.setrlimit(resource.RLIMIT_STACK, (-1, -1)) k = int(input()) ary = [1, 2, 3, 4, 5, 6, 7, 8, 9] def ans(j, nums): nums[j] += 1 pre = nums[j] for i in range(j + 1, len(nums)): if pre > 0: nums[i] = pre - 1 pre = nums[i] else: nums[i] = pre return int("".join(map(str, nums))) def lunlun(n): if n <= 9: return ary[n - 1] l = lunlun(n - 1) nums = list(map(int, list(str(l)))) first = len(nums) - 1 last = 0 for i in range(len(nums)): j = len(nums) - i - 1 c = nums[j] + 1 # 桁数が変わらないとき if j == first: # 1桁目 if nums[j] < 9 and abs(nums[j - 1] - c) <= 1: nums[j] += 1 return int("".join(map(str, nums))) elif j == last: # 最終桁 if nums[j] < 9 and abs(nums[j + 1] - c) <= 1: return ans(j, nums) elif j != first and j != last: # 間の桁 if nums[j] < 9 and abs(nums[j - 1] - c) <= 1 and abs(nums[j + 1] - c) <= 1: return ans(j, nums) # 桁が繰り上がるとき return int("1" + "".join(["0"] * len(nums))) print(lunlun(k))
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s134036380
Runtime Error
p02720
Input is given from Standard Input in the following format: K
from typing import List def lunlun_maker(l: List[int]) -> List[int]: next_lunluns = [] for e in l: nxt = e * 10 mod = e % 10 if 0 < mod < 9: next_lunluns.extend([nxt + mod - 1, nxt + mod, nxt + mod + 1]) elif mod == 0: next_lunluns.extend([nxt, nxt + 1]) elif mod == 9: next_lunluns.extend([nxt + 8, nxt + 9]) return next_lunluns def get_lunlun(num: int) -> int: lunluns = [1, 2, 3, 4, 5, 6, 7, 8, 9] counter = len(lunluns) counter_tmp = counter while counter < num: lunluns = lunlun_maker(lunluns) counter_tmp = counter counter += len(lunluns) return lunluns[num - counter_tmp - 1] K = int(input()) print(get_lunlun(K))
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s577586366
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
# ABC161D def f(k): if 1 <= k <= 9: return k nxt = [ [0, 1], [0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9], ] cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368] for length, begin in enumerate(cum_npi): if k < begin: found = cum_npi[length - 1] break begin = 10 ** (length - 1) length, begin, found k -= found x = [[]] * (length + 1) x[1] = list(range(1, 10)) x terminate = False i = 1 while True: # print(f"a) i = {i} x = {x}") if len(x[i]): # len(x[i]) digit = x[i][0] if i < length: # i, length i += 1 x[i] = nxt[digit].copy() # print(f"x) digit = {digit} nxt[digit] = {nxt[digit]} i = {i} x[i] = {x[i]}") # print(f"b) i = {i} x = {x}") if i == length: # i, length while len(x[i]): # i, x[i] k -= 1 # print(f"c) i = {i} x = {x}, k = {k}") if k == 0: x.pop(0) # print("answer =", x) ans = "".join([str(j.pop(0)) for j in x]) print(ans) terminate = True break else: x[i].pop(0) # print(f"d) i = {i} x = {x}") else: # print(f"e) i = {i} x = {x}") while len(x[i]) == 0: i -= 1 x[i].pop(0) if terminate: break f(int(input()))
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s369317457
Accepted
p02720
Input is given from Standard Input in the following format: K
# -*- coding: utf-8 -*- def f(n): C = [[1 for i in range(10)]] while sum(d for c in C for d in c[1:]) < n: C.append([sum(C[-1][max(0, i - 1) : min(i + 2, 10)]) for i in range(10)]) return C def solve(): n = int(input()) C = f(n) X = [] m = sum(d for c in C[:-1] for d in c[1:]) x = 1 for x in range(1, 10): if m + C[-1][x] < n: m += C[-1][x] else: break X.append(x) C = C[:-1] for c in C[::-1]: for x in range(max(0, X[-1] - 1), min(10, X[-1] + 2)): if m + c[x] < n: m += c[x] else: break X.append(x) return "".join(map(str, X)) if __name__ == "__main__": print(solve())
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s374351850
Runtime Error
p02720
Input is given from Standard Input in the following format: K
K = int(input()) def get_next_lun(before_number,keta): if keta == 1: #終了条件を忘れない if before_number == 9: return [8,9] if before_number == 0: return [1,2] else: return [before_number-1,before_number,before_number+1] else: if before_number == 9: for i in get_next_lun(before_number,keta-1): return [] if before_number == 0: return [] else: return [before_number-1,before_number,before_number+1] return
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s946564401
Accepted
p02720
Input is given from Standard Input in the following format: K
k = int(input()) l = [i for i in range(1, 10)] for i in range(k): r = l.pop(0) rr = r % 10 if rr != 0: l.append(10 * r + rr - 1) l.append(10 * r + rr) if rr != 9: l.append(10 * r + rr + 1) print(r)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s206094925
Runtime Error
p02720
Input is given from Standard Input in the following format: K
K = input() data = [int(i) for i in range(100000)] data_lun = [] for j in data: word = [int(k) for k in data] sa = [] for l in range(len(K) - 1): sa.append(word[l + 1] - word[l]) if max(sa) == 1: data_lun.append(j) print(j[int(K) - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s054941464
Accepted
p02720
Input is given from Standard Input in the following format: K
from itertools import product k = int(input()) ls = [] ls = [i for i in range(1, 10)] digit = 1 while len(ls) < k: for i in range(1, 10): for j in product([-1, 0, 1], repeat=digit): num = str(i) skip = 0 for y in j: x = int(num[-1]) + y if x < 0 or 9 < x: skip = 1 break num += str(x) if skip: continue ls.append(int(num)) digit += 1 print(ls[k - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s176938804
Accepted
p02720
Input is given from Standard Input in the following format: K
k = int(input()) ans = 0 a = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] old = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] b = [] l = 0 while l <= 9: b = [] for i in range(10): x = str(i) for j in old: if abs(i - int(j[0])) <= 1: y = x + j b.append(y) a.extend(b) old = b.copy() l += 1 c = set() for i in a: c.add(int(i)) d = list(c) d.sort() print(d[k])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s058124636
Accepted
p02720
Input is given from Standard Input in the following format: K
n = int(input()) listnum = [ [0, 1], [0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9], ] listans = [] for i in range(1, 10): numb = str(i) listans.append(int(numb)) for i in range(1, 10): for j in listnum[i]: numb = str(i) + str(j) listans.append(int(numb)) for i in range(1, 10): for j in listnum[i]: for m in listnum[j]: numb = str(i) + str(j) + str(m) listans.append(int(numb)) for i in range(1, 10): for j in listnum[i]: for m in listnum[j]: for x in listnum[m]: numb = str(i) + str(j) + str(m) + str(x) listans.append(int(numb)) for i in range(1, 10): for j in listnum[i]: for m in listnum[j]: for x in listnum[m]: for x2 in listnum[x]: numb = str(i) + str(j) + str(m) + str(x) + str(x2) listans.append(int(numb)) for i in range(1, 10): for j in listnum[i]: for m in listnum[j]: for x in listnum[m]: for x2 in listnum[x]: for x3 in listnum[x2]: numb = str(i) + str(j) + str(m) + str(x) + str(x2) + str(x3) listans.append(int(numb)) for i in range(1, 10): for j in listnum[i]: for m in listnum[j]: for x in listnum[m]: for x2 in listnum[x]: for x3 in listnum[x2]: for x4 in listnum[x3]: numb = ( str(i) + str(j) + str(m) + str(x) + str(x2) + str(x3) + str(x4) ) listans.append(int(numb)) for i in range(1, 10): for j in listnum[i]: for m in listnum[j]: for x in listnum[m]: for x2 in listnum[x]: for x3 in listnum[x2]: for x4 in listnum[x3]: for x5 in listnum[x4]: numb = ( str(i) + str(j) + str(m) + str(x) + str(x2) + str(x3) + str(x4) + str(x5) ) listans.append(int(numb)) for i in range(1, 10): for j in listnum[i]: for m in listnum[j]: for x in listnum[m]: for x2 in listnum[x]: for x3 in listnum[x2]: for x4 in listnum[x3]: for x5 in listnum[x4]: for x6 in listnum[x5]: numb = ( str(i) + str(j) + str(m) + str(x) + str(x2) + str(x3) + str(x4) + str(x5) + str(x6) ) listans.append(int(numb)) for i in range(1, 5): for j in listnum[i]: for m in listnum[j]: for x in listnum[m]: for x2 in listnum[x]: for x3 in listnum[x2]: for x4 in listnum[x3]: for x5 in listnum[x4]: for x6 in listnum[x5]: for x7 in listnum[x6]: numb = ( str(i) + str(j) + str(m) + str(x) + str(x2) + str(x3) + str(x4) + str(x5) + str(x6) + str(x7) ) listans.append(int(numb)) print(listans[n - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s613586067
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
K = int(input()) # ルンルン数を前計算したい。 M = [i for i in range(1, 11)] cnt = 0 U = list(M) while True: nex = set() tmp = set(M) for m in U: if str(m)[0] == "1": a = int("10" + str(m)) b = int("1" + str(m)) c = int("2" + str(m)) if a not in tmp: nex.add(a) if b not in tmp: nex.add(b) if c not in tmp: nex.add(c) elif str(m)[0] == "0": a = "1" + str(m) if a not in tmp: nex.add(a) else: for i in range(int(str(m)[0]) - 1, int(str(m)[0]) + 2): a = int(str(i) + str(m)) if a not in tmp: nex.add(a) M = list(tmp | nex) U = list(nex) if len(M) >= 10**5 + 1: break M = set(M) M = list(sorted(list(M))) print(M[K - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s511816283
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
a = int(input()) list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9] i = 1 while i <= a: # print (list1) if i != a: k = list1.pop(0) k = str(k) if int(k[-1]) == 0: list1.append(int(str(k) + "0")) list1.append(int(str(k) + "1")) elif int(k[-1]) == 9: list1.append(int(str(k) + "8")) list1.append(int(str(k) + "9")) else: list1.append(int(str(k) + str(int(k[-1]) - 1))) list1.append(int(str(k) + str(int(k[-1])))) list1.append(int(str(k) + str(int(k[-1]) + 1))) i += 1 else: print(list1[0]) break
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s528721703
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
K = int(input()) table = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] c = 9 result = [] for i in table: runrun = i if runrun[-1] == "0": table.extend([runrun + str(int(runrun)), runrun + str(int(runrun) + 1)]) c += 2 elif runrun[-1] == "9": table.extend([runrun + str(int(runrun) - 1), runrun + str(int(runrun))]) c += 2 else: table.extend( [ runrun + str(int(runrun) - 1), runrun + str(int(runrun)), runrun + str(int(runrun) + 1), ] ) c += 3 if c >= K: print(table[K - 1]) exit()
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s306826827
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
K = int(input()) List = [1, 2, 3, 4, 5, 6, 7, 8, 9] N = 0 M = 9 while len(List) < K: for i in range(N, M): last_number = int(str(List[i])[-1]) times10 = 10 * List[i] if last_number != 0 or last_number != 9: List.append(times10 + last_number - 1) List.append(times10 + last_number) List.append(times10 + last_number + 1) elif last_number == 0: List.append(times10) List.append(times10 + 1) else: List.append(times10 + 8) List.append(times10 + 9) N = M M = len(List) print(List[K - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s708671702
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
k = int(input()) count = 9 x = 10 while count < k: l = list(str(x)) flag = True for i in range(len(l) - 1): if abs(int(l[i]) - int(l[i + 1])) > 1: flag = False if flag: count += 1 x += 1 print(x - 1)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s063062679
Accepted
p02720
Input is given from Standard Input in the following format: K
def Lun(ume, gen, start): global keta if ume == keta: global ans temp = 0 for i in range(ume): temp += gen[i] * (10 ** (keta - i - 1)) ans.append(temp) # print(gen) return ima = gen[ume - 1] send = gen[:] if start: if ima > 0: send[ume] = ima - 1 Lun(ume + 1, send, start) send[ume] = ima Lun(ume + 1, send, start) if ima < 9: send[ume] = ima + 1 Lun(ume + 1, send, start) else: Lun(ume + 1, send, False) for i in range(1, 10): send[ume] = i Lun(ume + 1, send, True) ans = [] keta = 10 hajime = [0] * keta Lun(1, hajime, False) for i in range(1, 4): hajime[0] = i Lun(1, hajime, True) print(ans[int(input())])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s020589163
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
# # Written by NoKnowledgeGG @YlePhan # ('ω') # # import math # mod = 10**9+7 # import itertools # import fractions # import numpy as np # mod = 10**4 + 7 """def kiri(n,m): r_ = n / m if (r_ - (n // m)) > 0: return (n//m) + 1 else: return (n//m)""" # x o def Lun(now): STR = str(now) nowlen = len(STR) i = 0 if i + 1 < nowlen: if abs(int(STR[i]) - int(STR[i + 1])) > 1: return False if i + 2 < nowlen: if abs(int(STR[i + 1]) - int(STR[i + 2])) > 1: return False if i + 3 < nowlen: if abs(int(STR[i + 2]) - int(STR[i + 3])) > 1: return False if i + 4 < nowlen: if abs(int(STR[i + 3]) - int(STR[i + 4])) > 1: return False if i + 5 < nowlen: if abs(int(STR[i + 4]) - int(STR[i + 5])) > 1: return False if i + 6 < nowlen: if abs(int(STR[i + 5]) - int(STR[i + 6])) > 1: return False if i + 7 < nowlen: if abs(int(STR[i + 6]) - int(STR[i + 7])) > 1: return False if i + 8 < nowlen: if abs(int(STR[i + 7]) - int(STR[i + 8])) > 1: return False if i + 9 < nowlen: if abs(int(STR[i + 8]) - int(STR[i + 9])) > 1: return False if i + 10 < nowlen: if abs(int(STR[i + 9]) - int(STR[i + 10])) > 1: return False return True def main(): k = int(input()) if 1 <= k <= 9: print(k) exit() else: idx = 12 now = k while True: if Lun(now): idx += 1 if idx == k: print(now) exit() now += 1 else: now += 1 """PO = (k-9)//3 - 1 idx = 9 + 3*PO now = 10 * (PO+1) while True: if idx == k: print(now) exit() #---- if Lun(now): #print(now) idx += 1 if idx == k: print(now) exit() now += 1 else: now += 1""" if __name__ == "__main__": main()
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s057817867
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
# import numpy as np # import math # import copy # from collections import deque import sys input = sys.stdin.readline # sys.setrecursionlimit(10000) def main(): K = int(input()) dp = [[[] for j in range(10)] for i in range(11)] dp[1] = [[i] for i in range(10)] if K <= 10: print(K) sys.exit() count = 9 pre = [i for i in range(1, 10)] for disit in range(2, 11): dp[disit][0] = pre pre = [] for top in range(1, 10): if top == 9: test = [top - 1, top] else: test = [top - 1, top, top + 1] for k in test: temp = dp[disit - 1][k] for l in temp: res = l + top * 10 ** (disit - 1) if res not in pre: count += 1 pre.append(res) dp[disit][top].append(res) # print(count,temp) if count == K: print(res) sys.exit() main()
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s283320558
Accepted
p02720
Input is given from Standard Input in the following format: K
K = int(input()) s = "0" cnt = 0 while cnt < K: cnt += 1 ns = "" j = -1 for i in range(len(s) - 1, 0, -1): if int(s[i]) + 1 <= int(s[i - 1]) + 1 and int(s[i]) + 1 < 10: j = i break else: if s[0] < "9": j = 0 if j != -1: m = int(s[j]) for i in range(len(s)): if i == j: x = str(int(s[i]) + 1) elif i < j: x = s[i] elif i == j + 1: x = str(m) else: x = str(max(m - 1, 0)) m = max(m - 1, 0) ns += x else: ns = "1" + "0" * len(s) s = ns # print(s,) print(s)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s174435279
Accepted
p02720
Input is given from Standard Input in the following format: K
K = int(input()) l_lun = [i for i in range(1, 10)] nowp = 0 while nowp < K: newp = len(l_lun) for i in range(nowp, newp): left = l_lun[i] % 10 for j in range(left - 1, left + 2): if j < 0 or j >= 10: continue l_lun.append(l_lun[i] * 10 + j) nowp = newp print(l_lun[K - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s944309160
Accepted
p02720
Input is given from Standard Input in the following format: K
b = [[] for i in range(10)] b[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9] for j in range(9): for k in b[j]: b[j + 1].append(int(str(k) + str(k)[-1])) if str(k)[-1] != "9": b[j + 1].append(int(str(k) + str(int(str(k)[-1]) + 1))) if str(k)[-1] != "0": b[j + 1].append(int(str(k) + str(int(str(k)[-1]) - 1))) b[j + 1] = list(set(b[j + 1])) c = [] for j in range(10): c = c + b[j] c = sorted(c) print(c[int(input()) - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s102883339
Accepted
p02720
Input is given from Standard Input in the following format: K
import sys MAX = 1000000 Q = [0] * MAX head = 0 tail = 0 def isEmpty(): return head == tail def isFull(): return head == (tail + 1) % MAX def enqueue(x): global tail if isFull(): print("オーバーフロー") sys.exit() Q[tail] = x if tail + 1 == MAX: tail = 0 else: tail += 1 def dequeue(): global head if isEmpty(): print("アンダーフロー") sys.exit() x = Q[head] if head + 1 == MAX: head = 0 else: head += 1 return x k = int(input()) for i in range(1, 10): enqueue(i) for i in range(k): x = dequeue() b = x % 10 if b != 0: enqueue(10 * x + b - 1) enqueue(10 * x + b) if b != 9: enqueue(10 * x + b + 1) print(x)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s806948664
Accepted
p02720
Input is given from Standard Input in the following format: K
# ------------------------------------------------------------------- import sys def p(*_a): _s = " ".join(map(str, _a)) # print(_s) sys.stderr.write(_s + "\n") # ------------------------------------------------------------------- K = int(input()) # 5 A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] S = [] for a in A: S.append(str(a)) from collections import deque Q = deque() B = list(S) while True: for a in B: Q.append(str(a)) B = [] while Q: s = Q.popleft() a = int(s[0]) x = (str(a - 1) + s) if a > 0 else "" y = str(a) + s z = (str(a + 1) + s) if a < 9 else "" if x != "": B.append(x) if y != "": B.append(y) if z != "": B.append(z) B.sort() for b in B: if b[0] == "0": continue A.append(int(b)) if len(A) > K: ans = A[K] print(ans) # p(A) # p(B) exit(0)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s099391033
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
k = int(input()) numset = {i for i in range(1, 10)} flag = False count = len(numset) if count >= k: flag = True arr = [numset] index = 0 while not flag: beforeset = arr[index] tmpset = set() for i in beforeset: tail = str(i)[-1] if tail == "0": tmpset.add(int(str(i) + str(0))) tmpset.add(int(str(i) + str(1))) elif tail == "9": tmpset.add(int(str(i) + str(8))) tmpset.add(int(str(i) + str(9))) else: tmpset.add(int(str(i) + str(int(tail)))) tmpset.add(int(str(i) + str(int(tail) + 1))) tmpset.add(int(str(i) + str(int(tail) - 1))) count += len(tmpset) if count >= k: flag = True arr.append(tmpset) index += 1 totalarr = [] for tmpset in arr: totalarr += list(tmpset) totalarr.sort() print(totalarr[k])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s910559056
Accepted
p02720
Input is given from Standard Input in the following format: K
K = int(input()) A = [1, 2, 3, 4, 5, 6, 7, 8, 9] for i in range(len(A)): if A[i] != 9: for j in range(-1, 2): a = int(str(A[i]) + str(A[i] + j)) A.append(a) else: A.append(98) A.append(99) A.append(100) A.append(101) L1 = 10 L2 = len(A.copy()) for i in range(8): for i in range(L1, L2): B = A[i] if B % 10 == 0: A.append(int(str(B) + "0")) A.append(int(str(B) + "1")) elif B % 10 == 9: A.append(int(str(B) + "8")) A.append(int(str(B) + "9")) else: for j in range(-1, 2): a = int(str(B) + str((B % 10) + j)) A.append(a) L1 = L2 L2 = len(A.copy()) print(A[K - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s873355639
Accepted
p02720
Input is given from Standard Input in the following format: K
def dfs(cnt, num, top): if cnt == 10: return v.add(int(num)) if top == 0: dfs(cnt + 1, "0" + num, top) dfs(cnt + 1, "1" + num, top + 1) elif top == 9: dfs(cnt + 1, "8" + num, top - 1) dfs(cnt + 1, "9" + num, top) else: dfs(cnt + 1, str(top - 1) + num, top - 1) dfs(cnt + 1, str(top) + num, top) dfs(cnt + 1, str(top + 1) + num, top + 1) k = int(input()) v = set() for i in range(10): dfs(0, str(i), i) v = list(v) v.sort() v.pop(0) print(v[k - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s173628438
Wrong Answer
p02720
Input is given from Standard Input in the following format: K
def Add_(N): M = N C = 1 while M > 10: M = M // 10 C += 1 if M == 1: return [M * 10**C + N, (M + 1) * 10**C + N] elif M == 9: return [(M - 1) * 10**C + N, M * 10**C + N] else: return [(M - 1) * 10**C + N, M * 10**C + N, (M + 1) * 10**C + N] X = int(input()) R = [1, 2, 3, 4, 5, 6, 7, 8, 9] R_list = list() R_list.append(R) n = 9 d = 1 while n < X: list_ = [10**d] for i in R_list[-1]: temp = Add_(i) list_.extend(temp) n += len(temp) d += 1 R_list.append(list_) R = list() for list_ in R_list: R.extend(list_) R.sort() print(R[X - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s114098789
Accepted
p02720
Input is given from Standard Input in the following format: K
a = {0} _, *s = range(10) while s: v = s.pop() a |= {v} for w in range(max(0, v % 10 - 1), min(10, v % 10 + 2)): w += v * 10 if w < 4e9: s += (w,) print(sorted(a)[int(input())])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s749275595
Accepted
p02720
Input is given from Standard Input in the following format: K
list = [] for a in range(1, 10): list.append(a) for b in range(a - (a > 0), a + (a < 9) + 1): list.append(a * 10 + b) for c in range(b - (b > 0), b + (b < 9) + 1): list.append(a * 100 + b * 10 + c) for d in range(c - (c > 0), c + (c < 9) + 1): list.append(a * 1000 + b * 100 + c * 10 + d) for e in range(d - (d > 0), d + (d < 9) + 1): list.append(a * 10000 + b * 1000 + c * 100 + d * 10 + e) for f in range(e - (e > 0), e + (e < 9) + 1): list.append( a * 100000 + b * 10000 + c * 1000 + d * 100 + e * 10 + f ) for g in range(f - (f > 0), f + (f < 9) + 1): list.append( a * 1000000 + b * 100000 + c * 10000 + d * 1000 + e * 100 + f * 10 + g ) for h in range(g - (g > 0), g + (g < 9) + 1): list.append( a * 10000000 + b * 1000000 + c * 100000 + d * 10000 + e * 1000 + f * 100 + g * 10 + h ) for i in range(h - (h > 0), h + (h < 9) + 1): list.append( a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000 + f * 1000 + g * 100 + h * 10 + i ) for j in range(i - (i > 0), i + (i < 9) + 1): list.append( a * 1000000000 + b * 100000000 + c * 10000000 + d * 1000000 + e * 100000 + f * 10000 + g * 1000 + h * 100 + i * 10 + j ) list.sort() x = int(input()) print(list[x - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s417800837
Runtime Error
p02720
Input is given from Standard Input in the following format: K
K = int(input()) Q = queue.Queue() for a in range(1, 10): Q.put(a) for a in range(K - 1): now = Q.get() for b in range(-1, 2): add = (now % 10) + b if add >= 0 and add <= 9: Q.put(now * 10 + add) print(Q.get())
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s168795939
Accepted
p02720
Input is given from Standard Input in the following format: K
_, *s = range(10) for v in s: (*t,) = range(v * 10 + max(0, v % 10 - 1), v * 10 + min(10, v % 10 + 2)) s += t * (v < 4e8) print(s[int(input()) - 1])
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
Print the answer. * * *
s365605830
Accepted
p02720
Input is given from Standard Input in the following format: K
import sys input = lambda: sys.stdin.readline().rstrip() k = int(input()) cur = 0 for i in range(k): s = str(cur) n = len(s) if n <= 1 or cur == 10**n - 1: cur += 1 elif int(s[n - 2]) >= int(s[n - 1]) and int(s[n - 1]) != 9: cur += 1 elif int(s[n - 2]) >= int(s[n - 1]) and int(s[n - 1]) == 9: for j in range(n - 1): if int(s[n - j - 1]) == 9 or int(s[n - j - 1]) == int(s[n - j - 2]) + 1: continue else: nn = j ret = s[: n - 1 - nn] ret += str(int(s[n - 1 - nn]) + 1) break else: ret = str(int(s[0]) + 1) nn = n - 1 for j in range(nn): ret += str(max(int(ret[-1]) - 1, 0)) cur = int(ret) else: for j in range(1, n - 1): if int(s[n - 1 - j - 1]) >= int(s[n - 1 - j]): nn = n - 1 - j ret = s[:nn] ret += str(int(s[nn]) + 1) break else: nn = 0 ret = str(int(s[0]) + 1) for j in range(n - nn - 1): ret += str(max(int(ret[-1]) - 1, 0)) cur = int(ret) print(cur)
Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
[{"input": "15", "output": "23\n \n\nWe will list the 15 smallest lunlun numbers in ascending order: \n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23. \nThus, the answer is 23.\n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "13", "output": "21\n \n\n* * *"}, {"input": "100000", "output": "3234566667\n \n\nNote that the answer may not fit into the 32-bit signed integer type."}]
For each dataset, print the length of LCS of $X$ and $Y$ in a line.
s121100986
Runtime Error
p02235
The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given.
def lcs(list1,list2): f=[[0 for x in range(len(list1)+1)]for y in range(len(list2)+1)]#表の確保 for j in range(len(list1)): if list1[j]==list2[0]: f[j][0]=1 for j in range(len(list2)): if list1[0]==list2[j]: f[0][j]=1 for j in range(1,len(list1)): for k in range(1,len(list2)): if list1[j]==list2[k]: f[j][k]=f[j-1][k-1]+1 else: f[j][k]=max(f[j-1][k],f[j][k-1]) print(f[len(list1)-1][len(list2)-1]) n=int(input()) l=[] for i in range(n*2): str=input() l+=[list(str)] l[0].pop() i=0 while True:#(文字列の数/2)回繰り返す if i>2*n-2: break lcs(l[i],l[i+1]) i+=2
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
[{"input": "3\n abcbdab\n bdcaba\n abc\n abc\n abc\n bc", "output": "4\n 3\n 2"}]
For each dataset, print the length of LCS of $X$ and $Y$ in a line.
s854053471
Wrong Answer
p02235
The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given.
print(1)
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
[{"input": "3\n abcbdab\n bdcaba\n abc\n abc\n abc\n bc", "output": "4\n 3\n 2"}]
For each dataset, print the length of LCS of $X$ and $Y$ in a line.
s660479531
Wrong Answer
p02235
The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given.
for _ in [0] * int(input()): X, Y = " " + input(), " " + input() m, n = len(X), len(Y) c = [[0] * n for _ in [0] * m] print(c) for i in range(1, m): for j in range(1, n): c[i][j] = (max(c[i - 1][j], c[i][j - 1]), 1 + c[i - 1][j - 1])[X[i] == Y[j]] print(c[m - 1][n - 1])
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
[{"input": "3\n abcbdab\n bdcaba\n abc\n abc\n abc\n bc", "output": "4\n 3\n 2"}]
For each dataset, print the length of LCS of $X$ and $Y$ in a line.
s513853764
Accepted
p02235
The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given.
ascii_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" def llcs(x, y): pm = dict((zip(ascii_letters, [0] * 52))) for c in pm: for i, xc in enumerate(x): if c == xc: pm[c] |= 1 << i V = (1 << len(x)) - 1 for yc in y: V = (V + (V & pm[yc])) | (V & ~pm[yc]) ans = bin(V)[-len(x) :].count("0") return ans from sys import stdin def solve(): file_input = stdin q = int(file_input.readline()) for i in range(q): s1 = file_input.readline().rstrip() s2 = file_input.readline().rstrip() print(llcs(s1, s2)) solve()
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
[{"input": "3\n abcbdab\n bdcaba\n abc\n abc\n abc\n bc", "output": "4\n 3\n 2"}]
For each dataset, print the length of LCS of $X$ and $Y$ in a line.
s399859711
Wrong Answer
p02235
The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given.
from bisect import bisect_left q = int(input()) for _ in [0] * q: s1, s2 = input(), input() l1, l2 = len(s1), len(s2) p = [] for i, c in enumerate(s1): s = 0 while True: j = s2[s:].find(c) if j == -1: break p.append((i, s + j)) s += j + 1 lis = [] for _, y in sorted(p): i = bisect_left(lis, y) if len(lis) <= i: lis.append(y) else: lis[i] = y print(len(lis))
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
[{"input": "3\n abcbdab\n bdcaba\n abc\n abc\n abc\n bc", "output": "4\n 3\n 2"}]
For each dataset, print the length of LCS of $X$ and $Y$ in a line.
s156713521
Wrong Answer
p02235
The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given.
num = int(input()) for i in range(num): X = " " + input() Y = " " + input() lx = len(X) ly = len(Y) T = [0] * ly for j in range(1, lx): C = T[:] for k in range(1, ly): k1 = k - 1 if X[j] == Y[k]: T[k] = C[k1] + 1 elif C[k] > T[k1]: T[k] = C[k] else: T[k] = T[k1] print(T[k])
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
[{"input": "3\n abcbdab\n bdcaba\n abc\n abc\n abc\n bc", "output": "4\n 3\n 2"}]
For each test case, print the maximum value of the sum of the taste of the N cookies generated through the operations on one line. * * *
s779777420
Wrong Answer
p03977
The input is given from Standard Input in the following format: T N_1 D_1 : N_T D_T The input consists of multiple test cases. An Integer T that represents the number of test cases is given on line 1. Each test case is given on the next T lines. In the t-th test case ( 1 \leq t \leq T ), N_t that represents the number of cookies generated through the operations and D_t that represents the taste of the initial cookie are given separated by space.
N, T = 0, 0 for i in range(int(input())): N, T = map(int, input().split()) if N & 1: T ^= 127 print(T + (N - 1) * 127)
Statement A professor invented Cookie Breeding Machine for his students who like cookies very much. When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine, it consumes the cookie and generates two cookies with the taste of y and (x XOR y). Here, XOR represents Bitwise Exclusive OR. At first, there is only one cookie and the taste of it is D . Find the maximum value of the sum of the taste of the exactly N cookies generated after the following operation is conducted N-1 times. 1. Put one of the cookies into the machine. 2. Input a non-negative integer less than or equal to 127 on the machine.
[{"input": "3\n 3 1\n 4 108\n 1 10", "output": "255\n 400\n 10\n \n\nOn the 1st test case, if the machine is used as follows, three cookies with\nthe taste of 61, 95 and 99 are generated. Since the sum of these values is\nmaximum among all possible ways, the answer is 255.\n\n 1. Put the cookie with the taste of 1 and input an integer 60 on the machine, lose the cookie and get two cookies with the taste of 60 and 61. \n 2. Put the cookie with the taste of 60 and input an integer 99 on the machine, lose the cookie and get two cookies with the taste of 99 and 95. \n\nOn the 3rd test case, the machine may not be used."}]
For each test case, print the maximum value of the sum of the taste of the N cookies generated through the operations on one line. * * *
s382106692
Wrong Answer
p03977
The input is given from Standard Input in the following format: T N_1 D_1 : N_T D_T The input consists of multiple test cases. An Integer T that represents the number of test cases is given on line 1. Each test case is given on the next T lines. In the t-th test case ( 1 \leq t \leq T ), N_t that represents the number of cookies generated through the operations and D_t that represents the taste of the initial cookie are given separated by space.
q = int(input()) for _ in range(q): n, d = map(int, input().split()) print(127 * (n - 1) + d ^ (127 * ((n - 1) & 1)))
Statement A professor invented Cookie Breeding Machine for his students who like cookies very much. When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine, it consumes the cookie and generates two cookies with the taste of y and (x XOR y). Here, XOR represents Bitwise Exclusive OR. At first, there is only one cookie and the taste of it is D . Find the maximum value of the sum of the taste of the exactly N cookies generated after the following operation is conducted N-1 times. 1. Put one of the cookies into the machine. 2. Input a non-negative integer less than or equal to 127 on the machine.
[{"input": "3\n 3 1\n 4 108\n 1 10", "output": "255\n 400\n 10\n \n\nOn the 1st test case, if the machine is used as follows, three cookies with\nthe taste of 61, 95 and 99 are generated. Since the sum of these values is\nmaximum among all possible ways, the answer is 255.\n\n 1. Put the cookie with the taste of 1 and input an integer 60 on the machine, lose the cookie and get two cookies with the taste of 60 and 61. \n 2. Put the cookie with the taste of 60 and input an integer 99 on the machine, lose the cookie and get two cookies with the taste of 99 and 95. \n\nOn the 3rd test case, the machine may not be used."}]
Print the answer as an integer. * * *
s894680537
Accepted
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
c = sum(a := [*map(int, [*open(s := 0)][1].split())]) b = 1 for a in a: s = -(b < a) or s + b b = min(c := c - a, (b - a) * 2) print(s)
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
Print the answer as an integer. * * *
s622409061
Wrong Answer
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
N = int(input()) A = list(map(int, input().split())) AA = [0] for a in A[1:]: AA.append(AA[-1] + a) print(AA) f = 1 if A[0] == 0 else 0 r = 1 b = 1 for i, a in enumerate(A[1:]): x = min(b * 2, AA[-1] - AA[i]) if i < N - 1 and x > a or i == N - 1 and x == a: b = x - a r += x else: f = 0 print(r if f else -1)
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
Print the answer as an integer. * * *
s505344943
Accepted
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
import sys max_int = 1000000001 # 10^9+1 min_int = -max_int n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) a_ = a[::-1] sum = 0 prev_min = 0 prev_max = 0 prev = [] for num, one in enumerate(a_): prev_min = (prev_min + 1) // 2 + one prev_max += one level_maximum = 2 ** (len(a) - 1 - num) if prev_min > level_maximum: print(-1) exit() prev_max = min(level_maximum, prev_max) prev.append([prev_min, prev_max]) prev = prev[::-1] sum = 0 available = 1 for one in zip(prev, a): available = min(available, one[0][1]) sum += one[1] available -= one[1] sum += available available *= 2 print(sum)
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
Print the answer as an integer. * * *
s681205591
Wrong Answer
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
def check(d, nums): if d > 0 and not (nums[0] == 0): return "-1" if d == 0 and nums[0] == 0: return "-1" for i in range(len(nums)): if nums[i] > 2**i: return "-1" fullnode = 2 ** (d + 1) - 1 lostnode = 0 for i, n in enumerate(nums): lostnode += n * (2 ** (d + 1 - i) - 2) print(lostnode) return str(fullnode - lostnode) """ def recTree(d,nums,children): if d==0 and len(nums) == 1 and nums[0]==0: return 1 if d > 0 and len(nums) == d+1: print(d,":",((children+1)//2) ,"+", nums[-1]) return ((children+1)//2) + nums[-1] + recTree(d-1, nums[:-1], nums[-1]) """ d = int(input()) nums = list(map(int, input().split(" "))) print(check(d, nums))
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
Print the answer as an integer. * * *
s385582473
Wrong Answer
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
# coding: utf-8 # Your code here! n = int(input()) L = list(map(int, input().split())) a = sum(L) b = 0 n = 0 j = 1 # print(a,L) for i in range(len(L)): # print(a,b,j,n) if i > 0: a = a - L[i] # print(a,b,j,n) if b + L[i] <= j: n += b n += L[i] if b == 0: break elif b * 2 <= a and b * 2 <= j - L[i]: # print('a') b = b * 2 - L[i] elif b * 2 <= a and b * 2 > j - L[i]: # print('b') b = j - L[i] else: # print('c') b = a else: n = -1 break elif i == 0: if L[i] == 1: n = -1 break b = 1 n = L[i] j = j * 2 print(n)
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
Print the answer as an integer. * * *
s855541899
Wrong Answer
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
N = int(input()) A = list(map(int, input().split())) nodes = [0] * (N + 1) s_d = 0 # 飽和してないノードが残ってる深さ cap_d = 1 - A[0] failed = False for i, a in enumerate(A): # a個の葉をなるべく浅いノードから取る for _ in range(a): # これ以上分岐することろがなければ失敗 if i < s_d or cap_d <= 0: failed = True break # s_dから枝をとる for j in range(s_d, i + 1): nodes[j] += 1 # s_dがいっぱいになったら深さを一つ進める if nodes[s_d] >= cap_d: cap_d -= A[s_d] cap_d *= 2 s_d += 1 if failed: break print(-1 if failed else sum(nodes))
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
Print the answer as an integer. * * *
s403843182
Wrong Answer
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
from collections import deque n = int(input()) A = list(map(int, input().split())) sum = 0 maxNode = [2**i for i in range(n + 1)] que = deque() node = A[n] maxS = 0 maxim = -1 deep = n for i in range(node): que.appendleft(2 * node - i) maxS += A[n] while 0 < len(que) and 1 < deep: node = que.popleft() deep -= 1 print(deep) allnode = A[deep] + node if 2 ** A[deep] > allnode: deep += 1 continue maxS += allnode for i in range(A[deep]): que.appendleft(2 ** A[deep] - i) if deep == 1: maxim = max(maxS + A[0], maxim) maxS -= allnode print(maxim)
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
Print the answer as an integer. * * *
s827895514
Runtime Error
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
if A[0] >= 1: print(-1) else: print(1)
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
Print the answer as an integer. * * *
s433584250
Wrong Answer
p02665
Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N
N = int(input()) A = list(map(int, input().split())) result = 0 ver = [] for n in reversed(range(0, N + 1)): if n == len(A) - 1: ver.append(A[n]) elif A[n] == 0: if n**2 < ver[len(A) - n - 2]: ver.append(int(ver[len(A) - n - 2] / 2)) else: ver.append(ver[len(A) - n - 2]) elif A[n] != 0: if n**2 < ver[len(A) - n - 2]: ver.append(int(ver[len(A) - n - 2] / 2) + A[n]) else: ver.append(ver[len(A) - n - 2] + A[n]) print(sum(ver))
Statement Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
[{"input": "3\n 0 1 1 2", "output": "7\n \n\nBelow is the tree with the maximum possible number of vertices. It has seven\nvertices, so we should print 7.\n\n![0d8d99d13df036f23b0c9fcec52b842b.png](https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png)\n\n* * *"}, {"input": "4\n 0 0 1 0 2", "output": "10\n \n\n* * *"}, {"input": "2\n 0 3 1", "output": "-1\n \n\n* * *"}, {"input": "1\n 1 1", "output": "-1\n \n\n* * *"}, {"input": "10\n 0 0 1 1 2 3 5 8 13 21 34", "output": "264"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s670354565
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
N=int(input()) A=list(map(str, input().split())) counter=0 if 'P', 'W', 'G', 'Y' in A: print('Four') else: print('Three')
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s838035055
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) INF = 10**9 mod = 10**9+7 s = [0]*4 N = i() S = l() for i in range(N): if S[i] == 'P': s[0] = 1 if S[i] == 'W': s[1] = 1 if S[i] == 'G': s[2] = 1 if S[i] == 'Y' s[3] = 1 print(sum(s))
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s785147001
Accepted
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
a, b = open(0) print(("Three", "Four")["Y" in b])
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s453198956
Accepted
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
n, l = open(0) print("Four" if len(set(l.split())) == 4 else "Three")
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s130853751
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
n=int(input()) s=[map(str,input().split())] print("Four" if "Y" in s: else: "Three")
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s846423496
Wrong Answer
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
open(0) print("TFhoruere"[len(set(open(0))) == 4 :: 2])
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s201423821
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
n, *s = map(int, open(0).read().split()) print("TFhoruere"[len(set(s)) == 4 :: 2])
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s433456358
Accepted
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
N = int(input()) x = list(map(str, input().split())) res = [0, 0, 0, 0] def check(a): if a == [1, 1, 1, 1]: print("Four") quit() for i in range(0, N): if x[i] == "G": res[0] = 1 if x[i] == "Y": res[1] = 1 if x[i] == "W": res[2] = 1 if x[i] == "P": res[3] = 1 check(res) print("Three") quit()
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s391921524
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
num = int(input()) data = input().rstrip().split(' ') count = 0 if data.count('P') > 0 or data.count('W') > 0 or data.count('G') > 0 or data.count('Y') > 0: count++ print(count)
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s666800714
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
N = int(input()) n = "Three" for i in (N): S = input().split() If S == "Y": n = "Four" break if S != "Y": continue print(n)
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s005612157
Accepted
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
_ = int(input()) print(["Three", "Four"]["Y" in input().split()])
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s234633536
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
input() print(len(set([input().split()]))
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s661233886
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
n=input() if "Y" in input(): print("Four") else: print("Three)
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s389740374
Accepted
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
int(input()) b = ["One", "Two", "Three", "Four"] a = list(map(str, input().split(" "))) print(b[len(set(a)) - 1])
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]
If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`. * * *
s015462822
Runtime Error
p03424
Input is given from Standard Input in the following format: N S_1 S_2 ... S_N
N = int(input()) n = "Three" S = input().split() for i in range(N): If S[i+1] == "Y": n = "Four" break print(n)
Statement In Japan, people make offerings called _hina arare_ , colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`. If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.
[{"input": "6\n G W Y P Y W", "output": "Four\n \n\nThe bag contained arare in four colors, so you should print `Four`.\n\n* * *"}, {"input": "9\n G W W G P W P G G", "output": "Three\n \n\nThe bag contained arare in three colors, so you should print `Three`.\n\n* * *"}, {"input": "8\n P Y W G Y W Y Y", "output": "Four"}]