output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s817856935 | Accepted | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | import sys
sys.setrecursionlimit(10**6)
from math import floor, ceil, sqrt, factorial, log
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10**9 + 7
inf = float("inf")
ninf = -float("inf")
# 整数input
def ii():
return int(sys.stdin.readline().rstrip()) # int(input())
def mii():
return map(int, sys.stdin.readline().rstrip().split())
def limii():
return list(mii()) # list(map(int,input().split()))
def lin(n: int):
return [ii() for _ in range(n)]
def llint(n: int):
return [limii() for _ in range(n)]
# 文字列input
def ss():
return sys.stdin.readline().rstrip() # input()
def mss():
return sys.stdin.readline().rstrip().split()
def limss():
return list(mss()) # list(input().split())
def lst(n: int):
return [ss() for _ in range(n)]
def llstr(n: int):
return [limss() for _ in range(n)]
# 本当に貪欲法か? DP法では??
# 本当に貪欲法か? DP法では??
# 本当に貪欲法か? DP法では??
n = ii()
arr = limii()
mat = Counter(arr)
ans = 0
for i, j in mat.items():
if i <= j:
ans += j - i
else:
ans += j
print(ans)
| Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s186561932 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
cnt = 1
prev = a[0]
#print(a)
for i in range(1, n):
# print('\n# i: ' + str(i))
# print('# a[i]: ' + str(a[i]))
if a[i] == prev:
# print('same!')
cnt += 1
else:
if cnt == prev:
# print('good, skip!')
elif cnt > prev:
# print('cnt is larger!')
ans += cnt - prev
else:
# print('cnt is smaller!')
ans += cnt
# print('ans: ' + str(ans))
prev = a[i]
cnt = 1
if cnt > prev:
ans += cnt - prev
elif cnt < prev:
ans += cnt
print(ans) | Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s710936406 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | import copy
n = int(input())
x = [int(i) for i in input().split()]
y = copy.deepcopy(x)
z = []
for j in x:
if j not in z and x.count(j) < j:
while y.count(j) != 0:
y.remove(j)
elif j not in z and x.count(j) > j:
while y.count != j:
y.remove(j)
z.append(j)
print(len(x) - len(y))
| Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s893532686 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | import collections
N = int(input())
a = [int(i) for i in input().split(" ")]
c = collections.Counter(a)
ans = 0
for key,val in c.items():
del = max(val-key,val)
if key == val:
del = 0
ans += del
print(ans)
| Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s828275711 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | N = int(input())
A = list(map(int, input().split()))
B = [0] * 200000
ans = 0
for i in range(N):
if A[i] < 200000:
B[A[i]] += 1
else:
ans += 1
for i in range(200000):
if B[i] >= i:
ans += B[i] - i
else:
ans += B[i]
print(ans)
| Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s579400755 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | n = int(input())
alist = list(map(int,input().split()))
from collections import Counter
adic = Counter(alist)
count = 0
for key,value in adic:
if int(key) =< value:
count+=(value-int(key))
else:
count+=value
print(count) | Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s026827080 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | N = int(input())
a = [int(i) for i in input().split()]
a.sort()
for i in range(N):
if | Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s141334662 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | 8
2 7 1 8 2 8 1 8 | Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s191521858 | Wrong Answer | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | n = int(input())
arr = list(map(int, input().split()))
t = 0
for i in set(arr):
t += i
print(abs(n - t))
| Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s391454192 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | N = input()
d = dict()
for x in map(int, input().split())
if d.get(x) is None:
d[x] = 0
d[x] += 1
print(sum((min(d[x], abs(d[x]-x) for x in d))))
| Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s034026292 | Wrong Answer | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | n = int(input())
if n:
arr = list(map(int, input().split()))
t = 0
for i in set(arr):
t += i
print(abs(n - t))
else:
print(n)
| Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s646373057 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
map<int,int> m;
int n;
cin >> n;
rep(i,n){
int x;
cin >> x;
m[x]++;
}
int res = 0;
for(auto i:m){
if(i.first>i.second){
res+=i.second;
}
else{
res+=i.second-i.first;
}
}
cout << res << endl;
return 0;
} | Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s927878822 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向
const int MAX_N = 100010;
int n;
int a[MAX_N];
vector<int> aa;
int cnt[MAX_N];
void input(){
cin >> n;
for(int i=0;i<n;i++) cin >> a[i];
for(int i=0;i<n;i++) aa.push_back(a[i]);
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
input();
int ccnt = 0;
for(int i=0;i<n;++i){
if(aa[i] > 100000){
aa.erase(aa.begin()+i);
++ccnt;
}
} // 100000を超える数は良い数列の邪魔なので削除
int sz = aa.size();
for(int i=0;i<sz;++i) cnt[aa[i]]++;
for(int i=0;i<MAX_N;++i){
if (i != cnt[i]){
if(i < cnt[i]) ccnt += (cnt[i] - i);
else ccnt += cnt[i];
}
}
cout << ccnt << endl;
return 0;
} | Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s850371243 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b); a > b ? a : b end
def min(a,b); a < b ? a : b end
def swap(a,b); a, b = b, a end
def gif; gets.to_i end
def gff; gets.to_f end
def gsf; gets.chomp end
def gi; gets.split.map(&:to_i) end
def gf; gets.split.map(&:to_f) end
def gs; gets.chomp.split.map(&:to_s) end
def gc; gets.chomp.split('') end
def pr(num); num.prime_division end
def pr?(num); Prime.prime?(num) end
def digit(num); num.to_s.length end
def array(s,ini=nil); Array.new(s){ini} end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}} end
def rep(num); num.times{|i|yield(i)} end
def repl(st,en,n=1); st.step(en,n){|i|yield(i)} end
n = gif
a = gi
b = Hash.new
a.each do |aa|
b[aa] ||= 0
b[aa] += 1
end
ans = 0
b.each do |key,value|
if value >= key
ans += value - key
else
ans += value
end
end
puts ans
| Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s744033588 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | n = int(input())
a_list = list(map(int, input().split()))
dic = {}
i_list = []
for a in a_list:
dic[a] = 0
for a in a_list:
dic[a] += 1
if dic[a] = 1:
i_list.append(a)
ans = 0
for i in i_list:
p = dic[i] - i
if p >= 0:
ans += p
else:
ans += dic[i]
print(ans) | Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the minimum number of elements that needs to be removed so that a will
be a good sequence.
* * * | s591780094 | Runtime Error | p03487 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | N = int(input())
dict = {}
nums = list(map(int, input().split()))
for num in nums:
if num in dict.keys():
dict[num] += 1
else:
dict[num] = 1
ans = 0
for key, value in dict.items():
if int(key) == value
continue
elif int(key) > value:
ans += value
else:
ans += value - int(key)
print(ans) | Statement
You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
a_N). Your objective is to remove some of the elements in a so that a will be
a **good sequence**.
Here, an sequence b is a **good sequence** when the following condition holds
true:
* For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be
a good sequence. | [{"input": "4\n 3 3 3 3", "output": "1\n \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n 2 4 1 4 2", "output": "2\n \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n 1 2 2 3 3 3", "output": "0\n \n\n* * *"}, {"input": "1\n 1000000000", "output": "1\n \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n 2 7 1 8 2 8 1 8", "output": "5"}] |
Print the maximum possible sum of the integers written on the N cards after
the M operations.
* * * | s635096268 | Accepted | p03038 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N
B_1 C_1
B_2 C_2
\vdots
B_M C_M | # -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
def io_generator():
return input()
def iil(a_io):
return map(int, a_io().split())
# +++++++++++++++++++
def main(io):
n, m = iil(io)
aas = list(iil(io))
bbs = []
for _ in range(m):
b, c = iil(io)
bbs.append((b, c))
aas.sort()
# print(aas)
bbs = sorted(bbs, key=lambda t: -t[1])
# print(bbs)
bbii = 0
bbij = 0
ret = 0
ddd = 0
for i in aas:
if ddd == 1:
ret += i
continue
if i > bbs[bbii][1]:
ret += i
ddd = 1
continue
ret += bbs[bbii][1]
bbij += 1
if bbij >= bbs[bbii][0]:
bbij = 0
bbii += 1
if bbii >= len(bbs):
ddd = 1
return ret
return
# ++++++++++++++++++++
if __name__ == "__main__":
io = lambda: io_generator()
ret = main(io)
if ret is not None:
print(ret)
| Statement
You have N cards. On the i-th card, an integer A_i is written.
For each j = 1, 2, ..., M in this order, you will perform the following
operation once:
Operation: Choose at most B_j cards (possibly zero). Replace the integer
written on each chosen card with C_j.
Find the maximum possible sum of the integers written on the N cards after the
M operations. | [{"input": "3 2\n 5 1 4\n 2 3\n 1 5", "output": "14\n \n\nBy replacing the integer on the second card with 5, the sum of the integers\nwritten on the three cards becomes 5 + 5 + 4 = 14, which is the maximum\nresult.\n\n* * *"}, {"input": "10 3\n 1 8 5 7 100 4 52 33 13 5\n 3 10\n 4 30\n 1 4", "output": "338\n \n\n* * *"}, {"input": "3 2\n 100 100 100\n 3 99\n 3 99", "output": "300\n \n\n* * *"}, {"input": "11 3\n 1 1 1 1 1 1 1 1 1 1 1\n 3 1000000000\n 4 1000000000\n 3 1000000000", "output": "10000000001\n \n\nThe output may not fit into a 32-bit integer type."}] |
Print the maximum possible sum of the integers written on the N cards after
the M operations.
* * * | s393671878 | Runtime Error | p03038 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N
B_1 C_1
B_2 C_2
\vdots
B_M C_M | def comb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
N, M, K = map(int, input().split())
C = comb(N * M - 2, K - 2)
# print(int(C))
A = int(0)
for d in range(N):
a = (N - d) * (M**2)
A += int(d * a)
B = int(0)
for d in range(M):
b = (M - d) * (N**2)
B += int(d * b)
ans = int((A + B) * C)
ans = ans % (1000000007)
print(ans)
| Statement
You have N cards. On the i-th card, an integer A_i is written.
For each j = 1, 2, ..., M in this order, you will perform the following
operation once:
Operation: Choose at most B_j cards (possibly zero). Replace the integer
written on each chosen card with C_j.
Find the maximum possible sum of the integers written on the N cards after the
M operations. | [{"input": "3 2\n 5 1 4\n 2 3\n 1 5", "output": "14\n \n\nBy replacing the integer on the second card with 5, the sum of the integers\nwritten on the three cards becomes 5 + 5 + 4 = 14, which is the maximum\nresult.\n\n* * *"}, {"input": "10 3\n 1 8 5 7 100 4 52 33 13 5\n 3 10\n 4 30\n 1 4", "output": "338\n \n\n* * *"}, {"input": "3 2\n 100 100 100\n 3 99\n 3 99", "output": "300\n \n\n* * *"}, {"input": "11 3\n 1 1 1 1 1 1 1 1 1 1 1\n 3 1000000000\n 4 1000000000\n 3 1000000000", "output": "10000000001\n \n\nThe output may not fit into a 32-bit integer type."}] |
Print the maximum possible sum of the integers written on the N cards after
the M operations.
* * * | s484253132 | Wrong Answer | p03038 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N
B_1 C_1
B_2 C_2
\vdots
B_M C_M | n, m = list(map(int, input().split()))
cl = list(map(int, input().split()))
cl.sort()
ql = []
for _ in range(m):
b, c = list(map(int, input().split()))
ql.append([b, c])
ql.sort(key=lambda x: x[1], reverse=True)
| Statement
You have N cards. On the i-th card, an integer A_i is written.
For each j = 1, 2, ..., M in this order, you will perform the following
operation once:
Operation: Choose at most B_j cards (possibly zero). Replace the integer
written on each chosen card with C_j.
Find the maximum possible sum of the integers written on the N cards after the
M operations. | [{"input": "3 2\n 5 1 4\n 2 3\n 1 5", "output": "14\n \n\nBy replacing the integer on the second card with 5, the sum of the integers\nwritten on the three cards becomes 5 + 5 + 4 = 14, which is the maximum\nresult.\n\n* * *"}, {"input": "10 3\n 1 8 5 7 100 4 52 33 13 5\n 3 10\n 4 30\n 1 4", "output": "338\n \n\n* * *"}, {"input": "3 2\n 100 100 100\n 3 99\n 3 99", "output": "300\n \n\n* * *"}, {"input": "11 3\n 1 1 1 1 1 1 1 1 1 1 1\n 3 1000000000\n 4 1000000000\n 3 1000000000", "output": "10000000001\n \n\nThe output may not fit into a 32-bit integer type."}] |
Print the maximum possible sum of the integers written on the N cards after
the M operations.
* * * | s991360978 | Wrong Answer | p03038 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N
B_1 C_1
B_2 C_2
\vdots
B_M C_M | n, m = map(int, input().split())
alis = list(map(int, input().split()))
lis = [list(map(int, input().split())) for x in range(m)]
clis = [[x[1]] * x[0] for x in lis]
clis = [x for y in clis for x in y]
alis.sort()
ans_lis = [x if x >= y else y for x, y in zip(alis, clis[::-1])]
if len(clis) < len(alis):
ans__ = sum(alis[len(clis) :])
ans_ = sum(ans_lis)
print(ans_ + ans__)
else:
print(sum(ans_lis))
| Statement
You have N cards. On the i-th card, an integer A_i is written.
For each j = 1, 2, ..., M in this order, you will perform the following
operation once:
Operation: Choose at most B_j cards (possibly zero). Replace the integer
written on each chosen card with C_j.
Find the maximum possible sum of the integers written on the N cards after the
M operations. | [{"input": "3 2\n 5 1 4\n 2 3\n 1 5", "output": "14\n \n\nBy replacing the integer on the second card with 5, the sum of the integers\nwritten on the three cards becomes 5 + 5 + 4 = 14, which is the maximum\nresult.\n\n* * *"}, {"input": "10 3\n 1 8 5 7 100 4 52 33 13 5\n 3 10\n 4 30\n 1 4", "output": "338\n \n\n* * *"}, {"input": "3 2\n 100 100 100\n 3 99\n 3 99", "output": "300\n \n\n* * *"}, {"input": "11 3\n 1 1 1 1 1 1 1 1 1 1 1\n 3 1000000000\n 4 1000000000\n 3 1000000000", "output": "10000000001\n \n\nThe output may not fit into a 32-bit integer type."}] |
Print the maximum possible sum of the integers written on the N cards after
the M operations.
* * * | s247744155 | Accepted | p03038 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N
B_1 C_1
B_2 C_2
\vdots
B_M C_M | N, M = map(int, input().split())
listA = list(map(int, input().strip().split()))
class BCSet:
B = 0
C = 0
listBC = []
for i in range(0, M):
B, C = map(int, input().split())
new_BCSet = BCSet()
new_BCSet.B = B
new_BCSet.C = C
listBC.append(new_BCSet)
def MurgeSort(left, right):
if right - left == 1:
return
mid = left + int((right - left) / 2)
MurgeSort(left, mid)
MurgeSort(mid, right)
tmp = []
for i in range(left, mid):
tmp.append(listBC[i])
for i in range(mid, right):
tmp.append(listBC[mid + right - i - 1])
iterator_left = 0
iterator_right = right - left - 1
for i in range(left, right):
if tmp[iterator_left].C <= tmp[iterator_right].C:
listBC[i] = tmp[iterator_left]
iterator_left += 1
else:
listBC[i] = tmp[iterator_right]
iterator_right -= 1
def AMurgeSort(left, right):
if right - left == 1:
return
mid = left + int((right - left) / 2)
AMurgeSort(left, mid)
AMurgeSort(mid, right)
tmp = []
for i in range(left, mid):
tmp.append(listA[i])
for i in range(mid, right):
tmp.append(listA[mid + right - i - 1])
iterator_left = 0
iterator_right = right - left - 1
for i in range(left, right):
if tmp[iterator_left] <= tmp[iterator_right]:
listA[i] = tmp[iterator_left]
iterator_left += 1
else:
listA[i] = tmp[iterator_right]
iterator_right -= 1
MurgeSort(0, M)
AMurgeSort(0, N)
sum = 0
card_total = 0
cpoint = 0
iadjuster = 0
for i in range(0, N):
if listA[N - i - 1 + iadjuster] >= listBC[M - cpoint - 1].C or cpoint >= M:
card_total += 1
sum += listA[N - i - 1 + iadjuster]
if card_total == N:
break
else:
if card_total + listBC[M - cpoint - 1].B > N:
sum += (
listBC[M - cpoint - 1].B - (card_total + listBC[M - cpoint - 1].B - N)
) * listBC[M - cpoint - 1].C
break
else:
card_total += listBC[M - cpoint - 1].B
sum += listBC[M - cpoint - 1].B * listBC[M - cpoint - 1].C
cpoint += 1
iadjuster += 1
print("{}".format(sum))
| Statement
You have N cards. On the i-th card, an integer A_i is written.
For each j = 1, 2, ..., M in this order, you will perform the following
operation once:
Operation: Choose at most B_j cards (possibly zero). Replace the integer
written on each chosen card with C_j.
Find the maximum possible sum of the integers written on the N cards after the
M operations. | [{"input": "3 2\n 5 1 4\n 2 3\n 1 5", "output": "14\n \n\nBy replacing the integer on the second card with 5, the sum of the integers\nwritten on the three cards becomes 5 + 5 + 4 = 14, which is the maximum\nresult.\n\n* * *"}, {"input": "10 3\n 1 8 5 7 100 4 52 33 13 5\n 3 10\n 4 30\n 1 4", "output": "338\n \n\n* * *"}, {"input": "3 2\n 100 100 100\n 3 99\n 3 99", "output": "300\n \n\n* * *"}, {"input": "11 3\n 1 1 1 1 1 1 1 1 1 1 1\n 3 1000000000\n 4 1000000000\n 3 1000000000", "output": "10000000001\n \n\nThe output may not fit into a 32-bit integer type."}] |
Print the maximum possible sum of the integers written on the N cards after
the M operations.
* * * | s129400977 | Wrong Answer | p03038 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N
B_1 C_1
B_2 C_2
\vdots
B_M C_M | BC = {}
N, M = input().split(" ")
A = [int(x) for x in input().split(" ")]
for m in range(int(M)):
B, C = input().split(" ")
if int(C) in BC.keys():
BC[int(C)] = int(B) + BC[int(C)]
else:
BC[int(C)] = int(B)
# print(BC)
# A.sort(reverse=True)
bc = list(BC.keys())
# bc.sort(reverse=True)
A.extend(bc)
A.sort(reverse=True)
S = 0
nn = 0
print(A)
# while (nn < int(N)):
for n in range(int(N)):
if A[n] in bc:
s = BC[A[n]] # copy.deepcopy(BC[A[n]])
bc.remove(A[n])
if nn + s > int(N):
S += (int(N) - nn - 1) * A[n]
else:
S += s * A[n]
else:
s = 1
S += A[n]
print("n{}, A[n]{}, nn{}, s{}".format(n, A[n], nn, s))
nn += s
if nn >= int(N):
break
print(S)
| Statement
You have N cards. On the i-th card, an integer A_i is written.
For each j = 1, 2, ..., M in this order, you will perform the following
operation once:
Operation: Choose at most B_j cards (possibly zero). Replace the integer
written on each chosen card with C_j.
Find the maximum possible sum of the integers written on the N cards after the
M operations. | [{"input": "3 2\n 5 1 4\n 2 3\n 1 5", "output": "14\n \n\nBy replacing the integer on the second card with 5, the sum of the integers\nwritten on the three cards becomes 5 + 5 + 4 = 14, which is the maximum\nresult.\n\n* * *"}, {"input": "10 3\n 1 8 5 7 100 4 52 33 13 5\n 3 10\n 4 30\n 1 4", "output": "338\n \n\n* * *"}, {"input": "3 2\n 100 100 100\n 3 99\n 3 99", "output": "300\n \n\n* * *"}, {"input": "11 3\n 1 1 1 1 1 1 1 1 1 1 1\n 3 1000000000\n 4 1000000000\n 3 1000000000", "output": "10000000001\n \n\nThe output may not fit into a 32-bit integer type."}] |
Print the maximum possible sum of the integers written on the N cards after
the M operations.
* * * | s832881765 | Runtime Error | p03038 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N
B_1 C_1
B_2 C_2
\vdots
B_M C_M | import copy
# リストを引数として受け取り、最も小さい方から順にx個ピックしたもののリストを返す
min_xs = {}
def min_x(arg, x):
if x in min_xs:
return min_xs[x]
mins = []
for i in range(x):
minimum = min(arg)
mins.append(minimum)
arg.pop(arg.index(minimum))
min_xs[x] = mins
return mins
N, M = map(int, input().split())
As = list(map(int, input().split()))
for i in range(M):
j = i + 1
# print(j)
B_j, C_j = map(int, input().split())
mins = min_x(copy.copy(As), B_j)
for minimum in mins:
if minimum < C_j:
# print(As)
As[As.index(minimum)] = C_j
print(str(sum(As)))
| Statement
You have N cards. On the i-th card, an integer A_i is written.
For each j = 1, 2, ..., M in this order, you will perform the following
operation once:
Operation: Choose at most B_j cards (possibly zero). Replace the integer
written on each chosen card with C_j.
Find the maximum possible sum of the integers written on the N cards after the
M operations. | [{"input": "3 2\n 5 1 4\n 2 3\n 1 5", "output": "14\n \n\nBy replacing the integer on the second card with 5, the sum of the integers\nwritten on the three cards becomes 5 + 5 + 4 = 14, which is the maximum\nresult.\n\n* * *"}, {"input": "10 3\n 1 8 5 7 100 4 52 33 13 5\n 3 10\n 4 30\n 1 4", "output": "338\n \n\n* * *"}, {"input": "3 2\n 100 100 100\n 3 99\n 3 99", "output": "300\n \n\n* * *"}, {"input": "11 3\n 1 1 1 1 1 1 1 1 1 1 1\n 3 1000000000\n 4 1000000000\n 3 1000000000", "output": "10000000001\n \n\nThe output may not fit into a 32-bit integer type."}] |
Print the answer.
* * * | s660331497 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | print(input().count('2') | Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s439669544 | Accepted | p03192 | Input is given from Standard Input in the following format:
N | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi, factorial
from operator import itemgetter
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(map(int, input().split()))
def LI2():
return [int(input()) for i in range(n)]
def MXI():
return [[LI()] for i in range(n)]
def SI():
return input().rstrip()
def printns(x):
print("\n".join(x))
def printni(x):
print("\n".join(list(map(str, x))))
inf = 10**17
mod = 10**9 + 7
# main code here!
s = SI()
count = 0
for i in range(4):
if s[i] == "2":
count += 1
print(count)
if __name__ == "__main__":
main()
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s352794120 | Accepted | p03192 | Input is given from Standard Input in the following format:
N | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
) # , log2
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# from decimal import *
N = input()
print(N.count("2"))
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s139779800 | Accepted | p03192 | Input is given from Standard Input in the following format:
N | input_num = str(input())
cnt_2_in_str = lambda x: 1 if x == "2" else 0
print(sum(map(cnt_2_in_str, input_num)))
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s897425428 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | import math
from sys import stdin
N,P=[int(x) for x in stdin.readline().rstrip().split()]
for i in reversed(range(round(math.pow(P,(1/N)))):
tmp=math.pow(i,N-1)
if P==1:
ans=1
break
if N==1:
ans=P
break
if (P/i)%tmp==0:
ans=i
break
print(ans) | Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s740274012 | Wrong Answer | p03192 | Input is given from Standard Input in the following format:
N | print(1)
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s755087122 | Accepted | p03192 | Input is given from Standard Input in the following format:
N | N = input()
a = N.count("2")
if a > 0:
print(a)
else:
print(0)
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s944436474 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | n=input()
ans=0
for i in range(4):
if n[i]="2":
ans+=1
print(ans) | Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s882993020 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | a = input()
b = 0
for i in range(len(a)):
if a[i]==2:
b=b+1
print(b)
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s579995940 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | n=int(input())
ans=0
for i in range(4):
if n%10=2:
ans+=1
n=n/10
print(ans) | Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s776212604 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | print("second" if all(a[i] % 2 == 0 for i in range(N)) else "first")
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s536783513 | Wrong Answer | p03192 | Input is given from Standard Input in the following format:
N | print(str(input()).count("1"))
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s619274410 | Wrong Answer | p03192 | Input is given from Standard Input in the following format:
N | print(4 - input().count("2"))
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s135663531 | Accepted | p03192 | Input is given from Standard Input in the following format:
N | N = int(input())
def digitSum(s):
count = 0
x1 = s // 10**4
x2 = (s - x1 * 10**4) // 10**3
x3 = (s - x2 * 10**3 - x1 * 10**4) // 10**2
x4 = (s - x3 * 10**2 - x2 * 10**3 - x1 * 10**4) // 10
x5 = s - x4 * 10 - x3 * 10**2 - x2 * 10**3 - x1 * 10**4
if x2 == 2:
count += 1
if x3 == 2:
count += 1
if x4 == 2:
count += 1
if x5 == 2:
count += 1
return count
print(digitSum(N))
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s738864545 | Accepted | p03192 | Input is given from Standard Input in the following format:
N | n = int(input())
i = 0
flag = 0
m = [0, 0, 0, 0]
m[0] = n // 1000
m[1] = n // 100 - m[0] * 10
m[2] = n // 10 - m[0] * 100 - m[1] * 10
m[3] = n - m[0] * 1000 - m[1] * 100 - m[2] * 10
while i <= 3:
if m[i] == 2:
flag = flag + 1
i = i + 1
print(flag)
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s096800898 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | def usage():
product = 1
N, P = map(int, input().split())
fct = factorize(P)
for i in range(len(fct)):
fct[i][1] = fct[i][1] // N
if fct[i][1] >= 1:
product = product * (fct[i][0] ** fct[i][1])
print(product)
def factorize(n):
fct = [] # prime factor
b, e = 2, 0 # base, exponent
while b * b <= n:
while n % b == 0:
n = n // b
e = e + 1
if e > 0:
fct.append([b, e])
b, e = b + 1, 0
if n > 1:
fct.append([n, 1])
return fct
if __name__ == "__main__":
usage()
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s271734604 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | N = int(input())
ans = 0
for i in range(4)
a = N%10
if a==2:
ans += 1
N /= 10
print(ans)
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s447647577 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | n = list(int(input())
cnt = 0
for i in range(len(n)):
if n[i] == 2:
cnt += 1
print(cnt) | Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s332521563 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | n=list(input())
print(n.count('2)) | Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s124983672 | Accepted | p03192 | Input is given from Standard Input in the following format:
N | input = input()
print(len([i for i in input if int(i) == 2]))
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s809683718 | Accepted | p03192 | Input is given from Standard Input in the following format:
N | s = [x for x in input().split("2")]
print(len(s) - 1)
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s074007056 | Runtime Error | p03192 | Input is given from Standard Input in the following format:
N | s=list(str(input()))
ans=0
for i in range(4):
id s[i]=='2':
ans+=1
print(ans) | Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer.
* * * | s943553690 | Wrong Answer | p03192 | Input is given from Standard Input in the following format:
N | input().count("2")
| Statement
You are given an integer N that has exactly four digits in base ten. How many
times does `2` occur in the base-ten representation of N? | [{"input": "1222", "output": "3\n \n\n`2` occurs three times in `1222`. By the way, this contest is held on December\n22 (JST).\n\n* * *"}, {"input": "3456", "output": "0\n \n\n* * *"}, {"input": "9592", "output": "1"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s668500982 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | N = int(input().rstrip())
# 名前の桁数を求める (p:桁数)
p = 1
while N - 1 > 26**p - 1:
p += 1
A = [0] * p
for i in range(p):
q = (p - 1) - i
A[q] = N // 26**q
N = N % 26**q
txt = ""
for i in range(p):
q = (p - 1) - i
if A[q] == 0:
txt += "z"
else:
txt += chr(ord("a") + A[q] - 1)
print(txt)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s894651700 | Runtime Error | p02629 | Input is given from Standard Input in the following format:
N | n = int(input())
a = ""
if n == 1:
print("a")
if n == 26:
print("z")
else:
while n > 0:
if n % 26 == 1:
a += "a"
elif n % 26 == 2:
a += "b"
elif n % 26 == 3:
a += "c"
elif n % 26 == 4:
a += "d"
elif n % 26 == 5:
a += "e"
elif n % 26 == 6:
a += "f"
elif n % 26 == 7:
a += "g"
elif n % 26 == 8:
a += "h"
elif n % 26 == 9:
a += "i"
elif n % 26 == 10:
a += "j"
elif n % 26 == 11:
a += "k"
elif n % 26 == 12:
a += "l"
elif n % 26 == 13:
a += "m"
elif n % 26 == 14:
a += "n"
elif n % 26 == 15:
a += "o"
elif n % 26 == 16:
a += "p"
elif n % 26 == 17:
a += "q"
elif n % 26 == 18:
a += "r"
elif n % 26 == 19:
a += "s"
elif n % 26 == 20:
a += "t"
elif n % 26 == 21:
a += "u"
elif n % 26 == 22:
a += "v"
elif n % 26 == 23:
a += "w"
elif n % 26 == 24:
a += "x"
elif n % 26 == 25:
a += "y"
elif n % 26 == 0:
a += "z"
n -= 26
n = int(n / 26)
a = a[::-1]
print(a)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s405036586 | Runtime Error | p02629 | Input is given from Standard Input in the following format:
N | n = int(input())
table = []
x = 1
for i in range(20):
table.append(x)
x *= 26
i = 0
while True:
if table[i] > n:
k = i
break
else:
i += 1
k -= 1
cnt = 0
mapping = []
while k >= 0:
if k == 0:
mapping.append(n)
break
if n > table[k]:
n -= table[k]
cnt += 1
else:
mapping.append(cnt)
cnt = 0
k -= 1
"""
for i in range(len(mapping)):
if mapping[i] == 0:
mapping[i] = 1
"""
# print(mapping)
dictionary = {}
alphabet = "a"
for i in range(26):
dictionary[i + 1] = alphabet
alphabet = chr(ord(alphabet) + 1)
for i in mapping:
print(dictionary[i], end="")
print()
# k = 11
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s815604272 | Accepted | p02629 | Input is given from Standard Input in the following format:
N | a = int(input())
b = ""
while a > 0:
c = a % 26
if c == 0:
b = b + "z"
a = a - 26
elif c == 1:
b = b + "a"
a = a - 1
elif c == 2:
b = b + "b"
a = a - 2
elif c == 3:
b = b + "c"
a = a - 3
elif c == 4:
b = b + "d"
a = a - 4
elif c == 5:
b = b + "e"
a = a - 5
elif c == 6:
b = b + "f"
a = a - 6
elif c == 7:
b = b + "g"
a = a - 7
elif c == 8:
b = b + "h"
a = a - 8
elif c == 9:
b = b + "i"
a = a - 9
elif c == 10:
b = b + "j"
a = a - 10
elif c == 11:
b = b + "k"
a = a - 11
elif c == 12:
b = b + "l"
a = a - 12
elif c == 13:
b = b + "m"
a = a - 13
elif c == 14:
b = b + "n"
a = a - 14
elif c == 15:
b = b + "o"
a = a - 15
elif c == 16:
b = b + "p"
a = a - 16
elif c == 17:
b = b + "q"
a = a - 17
elif c == 18:
b = b + "r"
a = a - 18
elif c == 19:
b = b + "s"
a = a - 19
elif c == 20:
b = b + "t"
a = a - 20
elif c == 21:
b = b + "u"
a = a - 21
elif c == 22:
b = b + "v"
a = a - 22
elif c == 23:
b = b + "w"
a = a - 23
elif c == 24:
b = b + "x"
a = a - 24
elif c == 25:
b = b + "y"
a = a - 25
a = a / 26
print(b[::-1])
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s789666242 | Accepted | p02629 | Input is given from Standard Input in the following format:
N | from sys import stdin
n = int(stdin.readline().rstrip())
a = []
while n // 26 >= 1:
if n % 26 == 0:
a.insert(0, 26)
n = (n - 26) // 26
else:
a.insert(0, n % 26)
n = (n - n % 26) // 26
if n > 0:
a.insert(0, n)
i = 1
while i <= len(a):
t = a[i - 1]
if t == 1:
a[i - 1] = "a"
elif t == 2:
a[i - 1] = "b"
elif t == 3:
a[i - 1] = "c"
elif t == 4:
a[i - 1] = "d"
elif t == 5:
a[i - 1] = "e"
elif t == 6:
a[i - 1] = "f"
elif t == 7:
a[i - 1] = "g"
elif t == 8:
a[i - 1] = "h"
elif t == 9:
a[i - 1] = "i"
elif t == 10:
a[i - 1] = "j"
elif t == 11:
a[i - 1] = "k"
elif t == 12:
a[i - 1] = "l"
elif t == 13:
a[i - 1] = "m"
elif t == 14:
a[i - 1] = "n"
elif t == 15:
a[i - 1] = "o"
elif t == 16:
a[i - 1] = "p"
elif t == 17:
a[i - 1] = "q"
elif t == 18:
a[i - 1] = "r"
elif t == 19:
a[i - 1] = "s"
elif t == 20:
a[i - 1] = "t"
elif t == 21:
a[i - 1] = "u"
elif t == 22:
a[i - 1] = "v"
elif t == 23:
a[i - 1] = "w"
elif t == 24:
a[i - 1] = "x"
elif t == 25:
a[i - 1] = "y"
elif t == 26:
a[i - 1] = "z"
i += 1
print("".join(a))
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s021368791 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | N = int(input()) - 1
s = 1
while 26**s <= N:
s += 1
string = ""
for tst in range(s):
index = s - 1 - tst
value = N // (26**index)
N -= (26**index) * value
if value == 0:
string += "a"
elif value == 1:
string += "b"
elif value == 2:
string += "c"
elif value == 3:
string += "d"
elif value == 4:
string += "e"
elif value == 5:
string += "f"
elif value == 6:
string += "g"
elif value == 7:
string += "h"
elif value == 8:
string += "i"
elif value == 9:
string += "j"
elif value == 10:
string += "k"
elif value == 11:
string += "l"
elif value == 12:
string += "m"
elif value == 13:
string += "n"
elif value == 14:
string += "o"
elif value == 15:
string += "p"
elif value == 16:
string += "q"
elif value == 17:
string += "r"
elif value == 18:
string += "s"
elif value == 19:
string += "t"
elif value == 20:
string += "u"
elif value == 21:
string += "v"
elif value == 22:
string += "w"
elif value == 23:
string += "x"
elif value == 24:
string += "y"
elif value == 25:
string += "z"
print(string)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s843964010 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | N = int(input())
def Base_10_to_n(X, n):
X_dumy = X
out = ""
while X_dumy > 0:
out = str(X_dumy % n) + "," + out
X_dumy = int(X_dumy / n)
return out
ans = Base_10_to_n(N, 26)
l = list(ans.split(","))
for i in range(len(l) - 1):
if int(l[i]) == 1:
print("a", end="")
if int(l[i]) == 2:
print("b", end="")
if int(l[i]) == 3:
print("c", end="")
if int(l[i]) == 4:
print("d", end="")
if int(l[i]) == 5:
print("e", end="")
if int(l[i]) == 6:
print("f", end="")
if int(l[i]) == 7:
print("g", end="")
if int(l[i]) == 8:
print("h", end="")
if int(l[i]) == 9:
print("i", end="")
if int(l[i]) == 10:
print("j", end="")
if int(l[i]) == 11:
print("k", end="")
if int(l[i]) == 12:
print("l", end="")
if int(l[i]) == 13:
print("m", end="")
if int(l[i]) == 14:
print("n", end="")
if int(l[i]) == 15:
print("o", end="")
if int(l[i]) == 16:
print("p", end="")
if int(l[i]) == 17:
print("q", end="")
if int(l[i]) == 18:
print("r", end="")
if int(l[i]) == 19:
print("s", end="")
if int(l[i]) == 20:
print("t", end="")
if int(l[i]) == 21:
print("u", end="")
if int(l[i]) == 22:
print("v", end="")
if int(l[i]) == 23:
print("w", end="")
if int(l[i]) == 24:
print("x", end="")
if int(l[i]) == 25:
print("y", end="")
if int(l[i]) == 0:
print("z", end="")
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s792238718 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | n = int(input())
p = []
while(1):
b = n%26
n = n//26
p.append(b)
if n<26:
if n!=0:
p.append(n)
break
p = p[::-1]
for i in p:
print(chr(i + 96),end ='')
print('') | Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s459406634 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | N = int(input())
keta_num = 1
tmp_num = 1
while N >= 26**keta_num:
keta_num += 1
# print(keta_num, tmp_num)
names = []
alphabets = list("abcdefghijklmnopqrstuvwxyz")
for i in range(keta_num - 1, -1, -1):
# print(N, 26**i, i)
name = N // (26**i)
names.append(alphabets[name - 1])
N -= 26**i * name
print("".join(names))
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s616721785 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | import numpy as np
n = int(input())
digit = str(np.base_repr(n, 26))
if digit != "1" and digit[0] == "1":
target = digit[1:]
else:
target = digit
ans = target.translate(
str.maketrans(
{
"1": "a",
"2": "b",
"3": "c",
"4": "d",
"5": "e",
"6": "f",
"7": "g",
"8": "h",
"9": "i",
"A": "j",
"B": "k",
"C": "l",
"D": "m",
"E": "n",
"F": "o",
"G": "p",
"H": "q",
"I": "r",
"J": "s",
"K": "t",
"L": "u",
"M": "v",
"N": "w",
"O": "x",
"P": "y",
"0": "z",
}
)
)
print(digit)
print(ans)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s736527815 | Runtime Error | p02629 | Input is given from Standard Input in the following format:
N | import string
alphabet = list(string.ascii_lowercase)
N = int(input())
if N // 26 < 1:
c = alphabet[N - 1]
elif N // 26 < 26:
c = alphabet[(N // 26**1) - 1] + alphabet[(N - 1) % 26]
elif N // 26 < 26**2:
c = (
alphabet[(N // (26**2)) - 1]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**3:
c = (
alphabet[(N // (26**3)) - 1]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**4:
c = (
alphabet[(N // (26**4)) - 1]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**5:
c = (
alphabet[(N // (26**5)) - 1]
+ alphabet[((N // (26**4)) - 1) % 26]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**6:
c = (
alphabet[(N // (26**6)) - 1]
+ alphabet[((N // (26**5)) - 1) % 26]
+ alphabet[((N // (26**4)) - 1) % 26]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**7:
c = (
alphabet[(N // (26**7)) - 1]
+ alphabet[(N // (26**6)) - 1]
+ alphabet[((N // (26**5)) - 1) % 26]
+ alphabet[((N // (26**4)) - 1) % 26]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**8:
c = (
alphabet[(N // (26**8)) - 1]
+ alphabet[(N // (26**7)) - 1]
+ alphabet[(N // (26**6)) - 1]
+ alphabet[((N // (26**5)) - 1) % 26]
+ alphabet[((N // (26**4)) - 1) % 26]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**9:
c = (
alphabet[(N // (26**9)) - 1]
+ alphabet[(N // (26**8)) - 1]
+ alphabet[(N // (26**7)) - 1]
+ alphabet[(N // (26**6)) - 1]
+ alphabet[((N // (26**5)) - 1) % 26]
+ alphabet[((N // (26**4)) - 1) % 26]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**10:
c = (
alphabet[(N // (26**10)) - 1]
+ alphabet[(N // (26**9)) - 1]
+ alphabet[(N // (26**8)) - 1]
+ alphabet[(N // (26**7)) - 1]
+ alphabet[(N // (26**6)) - 1]
+ alphabet[((N // (26**5)) - 1) % 26]
+ alphabet[((N // (26**4)) - 1) % 26]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**11:
c = (
alphabet[(N // (26**11)) - 1]
+ alphabet[(N // (26**10)) - 1]
+ alphabet[(N // (26**9)) - 1]
+ alphabet[(N // (26**8)) - 1]
+ alphabet[(N // (26**7)) - 1]
+ alphabet[(N // (26**6)) - 1]
+ alphabet[((N // (26**5)) - 1) % 26]
+ alphabet[((N // (26**4)) - 1) % 26]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
elif N // 26 < 26**12:
c = (
alphabet[(N // (26**12)) - 1]
+ alphabet[(N // (26**11)) - 1]
+ alphabet[(N // (26**10)) - 1]
+ alphabet[(N // (26**9)) - 1]
+ alphabet[(N // (26**8)) - 1]
+ alphabet[(N // (26**7)) - 1]
+ alphabet[(N // (26**6)) - 1]
+ alphabet[((N // (26**5)) - 1) % 26]
+ alphabet[((N // (26**4)) - 1) % 26]
+ alphabet[((N // (26**3)) - 1) % 26]
+ alphabet[((N // (26**2)) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[((N // 26) - 1) % 26]
+ alphabet[(N - 1) % 26]
)
else:
c = "a"
print(c)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s448685089 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | X = int(input())
d = {0: "z"}
for i in range(0, 25):
d[i + 1] = chr(97 + i)
a = []
while X > 0:
a.append(d[(X % 26)])
X //= 26
for i in a[::-1]:
print(i, end="")
print()
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s224676469 | Accepted | p02629 | Input is given from Standard Input in the following format:
N | name = "zabcdefghijklmnopqrstuvwxy"
def namer(number):
if number <= 26:
return name[number % 26]
if name[number % 26] == "z":
return namer((number // 26) - 1) + name[number % 26]
return namer(number // 26) + name[number % 26]
number = int(input())
print(namer(number))
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s545179119 | Accepted | p02629 | Input is given from Standard Input in the following format:
N | L = [
"",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
]
S = ""
N = int(input())
while N > 26:
if N % 26 != 0:
a = N % 26
N -= a
S = L[a] + S
N //= 26
else:
S = L[26] + S
N //= 26
N -= 1
S = L[N] + S
print(S.lower())
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s775324895 | Accepted | p02629 | Input is given from Standard Input in the following format:
N | n = int(input())
a = ""
while n > 0:
if n % 26 == 1:
a += "a"
elif n % 26 == 2:
a += "b"
elif n % 26 == 3:
a += "c"
elif n % 26 == 4:
a += "d"
elif n % 26 == 5:
a += "e"
elif n % 26 == 6:
a += "f"
elif n % 26 == 7:
a += "g"
elif n % 26 == 8:
a += "h"
elif n % 26 == 9:
a += "i"
elif n % 26 == 10:
a += "j"
elif n % 26 == 11:
a += "k"
elif n % 26 == 12:
a += "l"
elif n % 26 == 13:
a += "m"
elif n % 26 == 14:
a += "n"
elif n % 26 == 15:
a += "o"
elif n % 26 == 16:
a += "p"
elif n % 26 == 17:
a += "q"
elif n % 26 == 18:
a += "r"
elif n % 26 == 19:
a += "s"
elif n % 26 == 20:
a += "t"
elif n % 26 == 21:
a += "u"
elif n % 26 == 22:
a += "v"
elif n % 26 == 23:
a += "w"
elif n % 26 == 24:
a += "x"
elif n % 26 == 25:
a += "y"
elif n % 26 == 0:
a += "z"
n -= 26
n = int(n / 26)
a = a[::-1]
print(a)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s368067586 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | n = int(input())
radix = 26
chars = []
while n // radix > 0:
p, r = n // radix, n % radix
chars.append(r)
n = p
print("".join(map(lambda x: chr(97 + x - 1), reversed(chars + [n]))))
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s938091212 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | import string
def main():
alphabet = string.ascii_lowercase
ans = []
N = int(input())
if N < 27:
ans.append(alphabet[N - 1])
else:
q, mod = divmod(N, 26)
if mod == 0:
if q == 1:
ans.append("z")
return ans
elif 1 < q and q <= 27:
ans.append("z")
ans.append(alphabet[q - 2])
return ans
elif 27 < q:
ans.append("z")
n = q
else:
if 1 <= q and q < 27:
ans.append(alphabet[mod - 1])
ans.append(alphabet[q - 1])
return ans
if 27 <= q:
ans.append(alphabet[mod - 1])
n = q
while n:
q, mod = divmod(n, 26)
if mod == 0:
if q == 1:
ans.append("z")
return ans
elif 1 < q and q <= 27:
ans.append("z")
ans.append(alphabet[q - 2])
return ans
elif 27 < q:
ans.append("z")
n = q
else:
if 1 <= q and q < 27:
ans.append(alphabet[mod - 1])
ans.append(alphabet[q - 1])
return ans
if 27 <= q:
ans.append(alphabet[mod - 1])
n = q
return ans
def main_2():
ans = main()
str_list = reversed(ans)
mojiretu = ""
for x in str_list:
mojiretu += x
print(mojiretu)
main_2()
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s221492361 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | N = int(input())
# if 1<= N <= 1000000000000001:
moji = list("abcdefghijklmnopqrstuvwxyz")
syo = 0
kai = ""
lis = []
for i in range(12, 0, -1):
syo = N // (26**i)
N = N % (26**i)
if syo > 0:
kai += moji[(syo - 1)]
kai += moji[(N - 1)]
print(kai)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s943025765 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | x = int(input())
a1 = x % 26
a2 = (x // 26) % 26
a3 = (x // 26 // 26) % 26
a4 = (x // 26 // 26 // 26) % 26
a5 = (x // 26 // 26 // 26 // 26) % 26
a6 = (x // 26 // 26 // 26 // 26 // 26) % 26
a7 = (x // 26 // 26 // 26 // 26 // 26 // 26) % 26
a8 = (x // 26 // 26 // 26 // 26 // 26 // 26 // 26) % 26
a9 = (x // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26) % 26
a10 = (x // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26) % 26
a11 = (x // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26) % 26
a12 = (x // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26) % 26
a13 = (x // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26 // 26) % 26
l = "abcdefghijklmnopqrstuvwxyz"
r = ""
if a13 != 0:
r += l[a13 - 1]
if a12 != 0:
r += l[a12 - 1]
if a11 != 0:
r += l[a11 - 1]
if a10 != 0:
r += l[a10 - 1]
if a9 != 0:
r += l[a9 - 1]
if a8 != 0:
r += l[a8 - 1]
if a7 != 0:
r += l[a7 - 1]
if a6 != 0:
r += l[a6 - 1]
if a5 != 0:
r += l[a5 - 1]
if a4 != 0:
r += l[a4 - 1]
if a3 != 0:
r += l[a3 - 1]
if a2 != 0:
r += l[a2 - 1]
if a1 != 0:
r += l[a1 - 1]
print(r)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s243016305 | Accepted | p02629 | Input is given from Standard Input in the following format:
N | N = int(input()) - 1
rst = ""
for i in range(1, 10**15):
if N >= 26**i:
N -= 26**i
continue
for j in range(i):
rst += chr(ord("a") + N % 26)
N //= 26
print(rst[::-1])
break
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s504716486 | Accepted | p02629 | Input is given from Standard Input in the following format:
N | import sys
def L():
return sys.stdin.readline().rstrip()
def I():
return int(sys.stdin.readline().rstrip())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LS():
return list(sys.stdin.readline().rstrip().split())
alp = list("abcdefghijklmnopqrstuvwxyz")
def div26(N):
# print("N=",N)
a = N // 26
b = N % 26
# print(a,b)
return [a, b]
def getAlp(N):
if N == 0:
N = 26
return alp[N - 1]
def solver(N):
ans = ""
x = div26(N)
ans += getAlp(x[1])
if x[1] == 0:
x[0] -= 1
# print("ans=",ans)
while x[0] > 0:
# print("in")
x = div26(x[0])
ans += getAlp(x[1])
if x[1] == 0:
x[0] -= 1
print(ans[::-1])
def main():
N = I()
# print(N,K,Pn)
solver(N)
if __name__ == "__main__":
main()
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s747573002 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | N = input()
if N == 2:
print("b")
if N == 27:
print("aa")
if N == 123456789:
print("jjddja")
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s397903041 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | n = int(input())
l = [0]
ans = []
a = 0
cur = 1
while a < 1000000000000001:
a += 26**cur
cur += 1
l.append(a)
l = list(reversed(l))
for i in range(len(l) - 1):
if l[i] > n:
ans.append(0)
else:
div = n // (l[i] - l[i + 1])
n = n % (l[i] - l[i + 1])
ans.append(div)
ans.append(n)
ans = list(map(lambda x: x + 96, ans))
ans2 = []
for i in ans:
if i > 96:
ans2.append(chr(i))
ans2 = "".join(ans2)
print(ans2)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s594280468 | Runtime Error | p02629 | Input is given from Standard Input in the following format:
N | import sys
def input():
return sys.stdin.readline().strip()
def main():
n = int(input())
con = 0
for i in range(10):
con += 26 ** (i + 1)
if n <= con:
num = i + 1
break
b = n - 26 ** (num - 1) + 1
c = n - 26 ** (num - 1)
if num == 1:
a = b % 26
if a == 1:
ans = "a"
if a == 2:
ans = "b"
if a == 3:
ans = "c"
if a == 4:
ans = "d"
if a == 5:
ans = "e"
if a == 6:
ans = "f"
if a == 7:
ans = "g"
if a == 8:
ans = "h"
if a == 9:
ans = "i"
if a == 10:
ans = "j"
if a == 11:
ans = "k"
if a == 12:
ans = "l"
if a == 13:
ans = "m"
if a == 14:
ans = "n"
if a == 15:
ans = "o"
if a == 16:
ans = "p"
if a == 17:
ans = "q"
if a == 18:
ans = "r"
if a == 19:
ans = "s"
if a == 20:
ans = "t"
if a == 21:
ans = "u"
if a == 22:
ans = "v"
if a == 23:
ans = "w"
if a == 24:
ans = "x"
if a == 25:
ans = "y"
if a == 0:
ans = "z"
print(ans, end="")
return
for i in range(num):
if i == num - 1:
if c == 1:
ans = "a"
elif c == 2:
ans = "b"
elif c == 3:
ans = "c"
elif c == 4:
ans = "d"
elif c == 5:
ans = "e"
elif c == 6:
ans = "f"
elif c == 7:
ans = "g"
elif c == 8:
ans = "h"
elif c == 9:
ans = "i"
elif c == 10:
ans = "j"
elif c == 11:
ans = "k"
elif c == 12:
ans = "l"
elif c == 13:
ans = "m"
elif c == 14:
ans = "n"
elif c == 15:
ans = "o"
elif c == 16:
ans = "p"
elif c == 17:
ans = "q"
elif c == 18:
ans = "r"
elif c == 19:
ans = "s"
elif c == 20:
ans = "t"
elif c == 21:
ans = "u"
elif c == 22:
ans = "v"
elif c == 23:
ans = "w"
elif c == 24:
ans = "x"
elif c == 25:
ans = "y"
else:
ans = "z"
print(ans, end="")
a = c // (26 ** (num - 1 - i))
c = c % (26 ** (num - 1 - i))
if c == 0:
c = 26 ** (num - 1 - i)
if i < num - 1:
if i != 0:
if a == 0:
a = 25
else:
a -= 1
if a == 0:
ans = "a"
elif a == 1:
ans = "b"
elif a == 2:
ans = "c"
elif a == 3:
ans = "d"
elif a == 4:
ans = "e"
elif a == 5:
ans = "f"
elif a == 6:
ans = "g"
elif a == 7:
ans = "h"
elif a == 8:
ans = "i"
elif a == 9:
ans = "j"
elif a == 10:
ans = "k"
elif a == 11:
ans = "l"
elif a == 12:
ans = "m"
elif a == 13:
ans = "n"
elif a == 14:
ans = "o"
elif a == 15:
ans = "p"
elif a == 16:
ans = "q"
elif a == 17:
ans = "r"
elif a == 18:
ans = "s"
elif a == 19:
ans = "t"
elif a == 20:
ans = "u"
elif a == 21:
ans = "v"
elif a == 22:
ans = "w"
elif a == 23:
ans = "x"
elif a == 24:
ans = "y"
elif a == 25:
ans = "z"
print(ans, end="")
main()
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s806673124 | Runtime Error | p02629 | Input is given from Standard Input in the following format:
N | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 21 21:17:02 2020
@author: akinari
"""
N = int(input())
if N <= 26: # 1
ans = chr(N + 96)
elif N <= 26**2 + 26: # 2
N2 = int(N / 26)
N1 = N % 26
ans = chr(N2 + 96) + chr(N1 + 96)
elif N <= 26**3 + 26**2 + 26: # 3
N3 = int(N / 26**2)
N2 = int((N - 26**2 * N3) / 26)
N1 = N % 26
ans = chr(N3 + 96) + chr(N2 + 96) + chr(N1 + 96)
elif N <= 26**4 + 26**3 + 26**2 * 26: # 4
N4 = int(N / 26**3)
N3 = int((N - 26**3 * N4) / 26**2)
N2 = int((N - 26**3 * N4 - 26**2 * N3) / 26)
N1 = N % 26
ans = chr(N4 + 96) + chr(N3 + 96) + chr(N2 + 96) + chr(N1 + 96)
elif N <= 26**5 + 26**4 + 26**3 + 26**2 * 26:
N5 = int(N / 26**4)
N4 = int((N - 26**4 * N5) / 26**3)
N3 = int((N - 26**4 * N5 - 26**3 * N4) / 26**2)
N2 = int((N - 26**4 * N5 - 26**3 * N4 - 26**2 * N3) / 26)
N1 = N % 26
ans = chr(N5 + 96) + chr(N4 + 96) + chr(N3 + 96) + chr(N2 + 96) + chr(N1 + 96)
elif N <= 26**6 + 26**5 + 26**4 + 26**3 + 26**2 * 26:
N6 = int(N / 26**5)
N5 = int((N - 26**5 * N6) / 26**4)
N4 = int((N - 26**5 * N6 - 26**4 * N5) / 26**3)
N3 = int((N - 26**5 * N6 - 26**4 * N5 - 26**3 * N4) / 26**2)
N2 = int((N - 26**5 * N6 - 26**4 * N5 - 26**3 * N4 - 26**2 * N3) / 26)
N1 = N % 26
ans = (
chr(N6 + 96)
+ chr(N5 + 96)
+ chr(N4 + 96)
+ chr(N3 + 96)
+ chr(N2 + 96)
+ chr(N1 + 96)
)
elif N <= 26**7 + 26**6 + 26**5 + 26**4 + 26**3 + 26**2 * 26:
N7 = int(N / 26**6)
N6 = int((N - 26**6 * N6) / 26**5)
N5 = int((N - 26**6 * N6 - 26**5 * N6) / 26**4)
N4 = int((N - 26**6 * N6 - 26**5 * N6 - 26**4 * N5) / 26**3)
N3 = int((N - 26**6 * N6 - 26**5 * N6 - 26**4 * N5 - 26**3 * N4) / 26**2)
N2 = int((N - 26**6 * N6 - 26**5 * N6 - 26**4 * N5 - 26**3 * N4 - 26**2 * N3) / 26)
N1 = N % 26
ans = (
chr(N6 + 96)
+ chr(N6 + 96)
+ chr(N5 + 96)
+ chr(N4 + 96)
+ chr(N3 + 96)
+ chr(N2 + 96)
+ chr(N1 + 96)
)
print(ans)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the answer to Roger's question as a string consisting of lowercase
English letters.
* * * | s710568227 | Wrong Answer | p02629 | Input is given from Standard Input in the following format:
N | n = int(input())
alp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0, 12):
if 26**i <= n < 26 ** (i + 1):
j = i
break
x = n - (26**j)
w = ""
for h in range(j, -1, -1):
if h == j:
w += alp[x // (26**h)]
x = x % (26**h)
else:
w += alp[x // (26**h) - 1]
x = x % (26**h)
print(w)
| Statement
1000000000000001 dogs suddenly appeared under the roof of Roger's house, all
of which he decided to keep. The dogs had been numbered 1 through
1000000000000001, but he gave them new names, as follows:
* the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;
* the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;
* the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;
* the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;
* the dogs numbered 475255,475256,\cdots were respectively given the names `aaaaa`, `aaaab`, ...;
* and so on.
To sum it up, the dogs numbered 1, 2, \cdots were respectively given the
following names:
`a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`,
`zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ...,
`zzz`, `aaaa`, ...
Now, Roger asks you:
"What is the name for the dog numbered N?" | [{"input": "2", "output": "b\n \n\n* * *"}, {"input": "27", "output": "aa\n \n\n* * *"}, {"input": "123456789", "output": "jjddja"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s720692431 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | a, h = map(int, input())
print((a + h - 1) // h)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s995221137 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | print((int(input()) + 1) // 2)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s383792515 | Wrong Answer | p02783 | Input is given from Standard Input in the following format:
H A | a, b = list(map(int, input().split()))
c = a % b
my_result = (a + c) / b
print(int(my_result))
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s594511649 | Wrong Answer | p02783 | Input is given from Standard Input in the following format:
H A | a, b = input().split()
c = int(a) // int(b)
if c * int(b) == a:
print(c)
else:
print(c + 1)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s591730381 | Accepted | p02783 | Input is given from Standard Input in the following format:
H A | import sys
sys.setrecursionlimit(4100000)
import math
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def resolve():
# S = [x for x in sys.stdin.readline().split()][0] # 文字列 一つ
# N = [int(x) for x in sys.stdin.readline().split()][0] # int 一つ
H, A = [int(x) for x in sys.stdin.readline().split()] # 複数int
# grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)] # 文字列grid
# grid = [[int(x) for x in sys.stdin.readline().split()]
# for _ in range(N)] # int grid
logger.debug("{}".format([]))
print(math.ceil(H / A))
if __name__ == "__main__":
resolve()
# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """10 4"""
output = """3"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """1 10000"""
output = """1"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """10000 1"""
output = """10000"""
self.assertIO(input, output)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s473518837 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | import numpy as np
from sys import stdin
## This code doesn't pass the test
# def get_result(data):
# H, N = data[0]
# A_and_B = np.array(data[1:])
# calc_efficient = np.array(list(map(lambda x: float(x[0] / x[1]), A_and_B)))
# sorted_index = np.argsort(-calc_efficient)
# cost = 0
# remainder_H = H
# for i in sorted_index:
# A, B = A_and_B[i]
# quotient = remainder_H // A
# if quotient > 0:
# cost += B * quotient
# remainder_H = remainder_H - A * quotient
# else:
# if remainder_H > 0:
# continue
# else:
# break
# return cost
## 答え (DP, ナップザック問題の典型らしい)
# 自分の解法は典型的なハマり方をしたっぽい
def get_result(data):
# 初期化
H, N = data[0]
A_and_B = np.array(data[1:])
A = A_and_B[:, 0].reshape(-1)
B = A_and_B[:, 1].reshape(-1)
# 最小化問題だから無限で初期化
# DP[j] = Aの和が j の時の最小コスト (魔力)
# 計算量は、O(NH)なのでHが少なくなるようにテーブルは作る
inf = float("inf")
# N × H (制約条件) のテーブルを作成
dp = [inf for j in range(H + 1)]
# 初期値
dp[0] = 0
# DP (コードはなんとなく理解できた)
for i in range(H):
for j in range(N):
# 魔力1つずつについてloopさせる
if (i + 1) - A[j] < 0:
dp[i + 1] = min(dp[i + 1], dp[0] + B[j])
else:
dp[i + 1] = min(dp[i + 1], dp[i + 1 - A[j]] + B[j])
return dp[H]
if __name__ == "__main__":
raw_data = [val.rstrip("\n") for val in stdin.readlines()]
data = [list(map(int, val.split(" "))) for val in raw_data]
result = get_result(data)
print(result)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s666089867 | Wrong Answer | p02783 | Input is given from Standard Input in the following format:
H A | import sys
import numpy as np
lines = sys.stdin.readlines()
H, _ = list(map(int, lines[0].split()))
AB = (
np.array([np.array(list(map(float, s.split()))) for s in lines[1:]])
.flatten()
.reshape((-1, 2))
)
ABnorm = AB[:, 1] / AB[:, 0]
AB = np.insert(AB, 2, ABnorm, axis=1)
AB = AB[AB[:, 0].argsort(), :]
AB = AB[AB[:, 2].argsort(), :]
baseAmari = H
minv = -1
syomo = 0
syomo1min = 99999999
for i in range(len(AB)):
if minv < AB[i, 2]:
if baseAmari <= int(AB[i, 0]):
syomo += int(AB[i, 1])
break
minv = int(AB[i, 2])
baseAt = baseAmari // int(AB[i, 0])
syomo += baseAt * int(AB[i, 1])
syomo1 = syomo + int(AB[i, 1])
if syomo1min > syomo1:
syomo1min = syomo1
baseAmari = baseAmari - baseAt * int(AB[i, 0])
if baseAmari == 0:
break
if syomo > syomo1min:
syomo = syomo1min
print(syomo)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s773799761 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | def main() -> None:
H, N = rmi()
AB = []
for _ in range(N):
AB.append(rmi())
dp = [10**9] * (H + 1)
dp[0] = 0
for damage, mp in AB:
for i in range(len(dp)):
prev = max(i - damage, 0)
dp[i] = min(dp[i], dp[prev] + mp)
w(dp[H])
def r() -> str:
return input().strip()
def ri() -> int:
return int(r())
def rmi(delim: str = " ") -> tuple:
return tuple(map(int, input().split(delim)))
def w(data) -> None:
print(data)
def wm(*data, delim: str = " ") -> None:
print(delim.join(map(str, data)))
if __name__ == "__main__":
main()
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s986354442 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | (h, n), *t = [list(map(int, o.split())) for o in open(0)]
d = [0] * (h + 10100)
for i in range(1, h + 1):
d[i] = min(d[i - a] + b for a, b in t)
print(d[h])
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s456446336 | Wrong Answer | p02783 | Input is given from Standard Input in the following format:
H A | def serveal_monter(input):
H, A = input.split(" ")
if H % A > 0:
return (H // A) + 1
return H // A
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s433113241 | Accepted | p02783 | Input is given from Standard Input in the following format:
H A | a, s = map(int, input().split())
print((a + s - 1) // s)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s728916774 | Wrong Answer | p02783 | Input is given from Standard Input in the following format:
H A | hp, att = map(int, input().split())
print((hp + att - 1) / att)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s878195282 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | s = input()
n = input()
print(s // n)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s040870854 | Wrong Answer | p02783 | Input is given from Standard Input in the following format:
H A | def howmany(n, m):
if n % m == 0:
return n / m
else:
return n // m + 1
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s285106656 | Accepted | p02783 | Input is given from Standard Input in the following format:
H A | # A
HA = input().split(" ")
H = int(HA[0])
A = int(HA[1])
for s in range(H + 1):
if s * A >= H and (s - 1) * A < H:
print(s)
break
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s749511786 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | a, b = map(int, input().split())
s = list(map(int, input().split()))
count = 0
for i in range(b):
for j in range(i, b):
if a < s[i] + s[j] and count == 0:
print("yes")
count += 1
if count == 0:
print("no")
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s314467995 | Accepted | p02783 | Input is given from Standard Input in the following format:
H A | HA = input()
HA = HA.split()
n = int(HA[0]) / int(HA[1])
if int(HA[0]) % int(HA[1]) == 0:
print(int(n))
else:
print(int(n + 1))
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s289543220 | Accepted | p02783 | Input is given from Standard Input in the following format:
H A | b = input().split(" ")
b[0] = int(b[0])
b[1] = int(b[1])
k = 1
m = 0
while k == 1:
if b[0] <= 0:
k = k + 1
b[0] = b[0] - b[1]
m = m + 1
print(m - 1)
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s424027513 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | H = int(input("The health of the monster is "))
A = int(input("Serval can decrease the monster's health by "))
num = (H + A - 1) / A
print(int(num))
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Print the number of attacks Serval needs to make before winning.
* * * | s570595449 | Runtime Error | p02783 | Input is given from Standard Input in the following format:
H A | x = input().split()
h = int(x[0])
n = int(x[1])
a = []
b = []
for k in range(n):
x = input().split()
a.append(int(x[0]))
b.append(int(x[1]))
m = max(a)
dp = [10**9] * (h + m)
dp[0] = 0
for k in range(h + m):
for i in range(n):
if k - a[i] < 0:
continue
new = dp[k - a[i]] + b[i]
if new < dp[k]:
dp[k] = new
print(min(dp[h : h + m]))
| Statement
Serval is fighting with a monster.
The _health_ of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no
other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning. | [{"input": "10 4", "output": "3\n \n\n * After one attack, the monster's health will be 6.\n * After two attacks, the monster's health will be 2.\n * After three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\n* * *"}, {"input": "1 10000", "output": "1\n \n\n* * *"}, {"input": "10000 1", "output": "10000"}] |
Output the integers written in the magic square, in the following format:
X_{1,1} X_{1,2} X_{1,3}
X_{2,1} X_{2,2} X_{2,3}
X_{3,1} X_{3,2} X_{3,3}
where X_{i,j} is the integer written in the square at the i-th row and j-th
column.
* * * | s474456522 | Wrong Answer | p03891 | The input is given from Standard Input in the following format:
A
B
C | x11, x12, x22 = (int(input()) for _ in range(3))
sum = x11 + x12 + x22
x13, x32, x33 = sum - (x11 + x12), sum - (x12 + x22), sum - (x11 + x12)
x23, x31 = sum - (x13 + x33), sum - (x13 + x22)
x21 = sum - (x22 + x23)
print("%d %d %d\n%d %d %d\n%d %d %d" % (x11, x12, x13, x21, x22, x23, x31, x32, x33))
| Statement
A 3×3 grid with a integer written in each square, is called a magic square if
and only if the integers in each row, the integers in each column, and the
integers in each diagonal (from the top left corner to the bottom right
corner, and from the top right corner to the bottom left corner), all add up
to the same sum.
You are given the integers written in the following three squares in a magic
square:
* The integer A at the upper row and left column
* The integer B at the upper row and middle column
* The integer C at the middle row and middle column
Determine the integers written in the remaining squares in the magic square.
It can be shown that there exists a unique magic square consistent with the
given information. | [{"input": "8\n 3\n 5", "output": "8 3 4\n 1 5 9\n 6 7 2\n \n\n* * *"}, {"input": "1\n 1\n 1", "output": "1 1 1\n 1 1 1\n 1 1 1"}] |
Output the integers written in the magic square, in the following format:
X_{1,1} X_{1,2} X_{1,3}
X_{2,1} X_{2,2} X_{2,3}
X_{3,1} X_{3,2} X_{3,3}
where X_{i,j} is the integer written in the square at the i-th row and j-th
column.
* * * | s556641937 | Runtime Error | p03891 | The input is given from Standard Input in the following format:
A
B
C | a, b, c = map(int, input().split())
print(a, b, c)
print(a, b, -a - b + 3 * c)
print(-2 * a - b + 4 * c, c, 2 * a + b - 2 * c)
print(a + b - c, -b + 2 * c, -a + 2 * c)
| Statement
A 3×3 grid with a integer written in each square, is called a magic square if
and only if the integers in each row, the integers in each column, and the
integers in each diagonal (from the top left corner to the bottom right
corner, and from the top right corner to the bottom left corner), all add up
to the same sum.
You are given the integers written in the following three squares in a magic
square:
* The integer A at the upper row and left column
* The integer B at the upper row and middle column
* The integer C at the middle row and middle column
Determine the integers written in the remaining squares in the magic square.
It can be shown that there exists a unique magic square consistent with the
given information. | [{"input": "8\n 3\n 5", "output": "8 3 4\n 1 5 9\n 6 7 2\n \n\n* * *"}, {"input": "1\n 1\n 1", "output": "1 1 1\n 1 1 1\n 1 1 1"}] |
Print the information of each node in the following format ordered by IDs:
node _id_ : parent = _p_ , depth = _d_ , _type_ , [_c_ 1..._c k_]
_p_ is ID of its parent. If the node does not have a parent, print -1.
_d_ is depth of the node.
_type_ is a type of nodes represented by a string (root, internal node or
leaf). If the root can be considered as a leaf or an internal node, print
root.
_c_ 1..._c k_ is the list of children as a ordered tree.
Please follow the format presented in a sample output below. | s141071017 | Accepted | p02279 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node _u_ is given in the
following format:
_id_ _k_ _c_ 1 _c_ 2 ... _c k_
where _id_ is the node ID of _u_ , _k_ is the degree of _u_ , _c_ 1 ... _c k_
are node IDs of 1st, ... _k_ th child of _u_. If the node does not have a
child, the _k_ is 0. | import sys
N = int(sys.stdin.readline().rstrip()) # 節点数
parents = [None] * N
depth = [None] * N
type_ = [None] * N
children = [None] * N
CHs = [None] * N
# ## DFS ## #
def dfs(u, d, r=-1):
# u を訪れたときの処理
# parents[u] = r
depth[u] = d
c = []
tmp = "leaf"
for v in CHs[u]:
if v == r:
continue # 親は無視
tmp = "internal node"
dfs(v, d + 1, u) # 子の探索
c.append(v)
# u を離れる前の処理
if r == -1:
tmp = "root"
type_[u] = tmp
children[u] = c
def main():
for i in range(N):
id, k, *ch = map(int, sys.stdin.readline().rstrip().split())
for p in ch:
parents[p] = id
CHs[id] = ch
# 根を見つける
u = 0
while True:
if parents[u] is None:
root = u
parents[u] = -1
break
u = parents[u]
dfs(root, 0)
for i in range(N):
print(
f"node {i}: parent = {parents[i]}, depth = {depth[i]}, {type_[i]}, {children[i]}"
)
main()
| Rooted Trees
A graph _G_ = (_V_ , _E_) is a data structure where _V_ is a finite set of
vertices and _E_ is a binary relation on _V_ represented by a set of edges.
Fig. 1 illustrates an example of a graph (or graphs).

**Fig. 1**
A free tree is a connnected, acyclic, undirected graph. A rooted tree is a
free tree in which one of the vertices is distinguished from the others. A
vertex of a rooted tree is called "node."
Your task is to write a program which reports the following information for
each node _u_ of a given rooted tree _T_ :
* node ID of _u_
* parent of _u_
* depth of _u_
* node type (root, internal node or leaf)
* a list of chidlren of _u_
If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is
(_p_ , _x_), then _p_ is the **parent** of _x_ , and _x_ is a **child** of
_p_. The root is the only node in _T_ with no parent.
A node with no children is an **external node** or **leaf**. A nonleaf node is
an **internal node**
The number of children of a node _x_ in a rooted tree _T_ is called the
**degree** of _x_.
The length of the path from the root _r_ to a node _x_ is the **depth** of _x_
in _T_.
Here, the given tree consists of _n_ nodes and evey node has a unique ID from
0 to _n_ -1.
Fig. 2 shows an example of rooted trees where ID of each node is indicated by
a number in a circle (node). The example corresponds to the first sample
input.

**Fig. 2** | [{"input": "13\n 0 3 1 4 10\n 1 2 2 3\n 2 0\n 3 0\n 4 3 5 6 7\n 5 0\n 6 0\n 7 2 8 9\n 8 0\n 9 0\n 10 2 11 12\n 11 0\n 12 0", "output": "node 0: parent = -1, depth = 0, root, [1, 4, 10]\n node 1: parent = 0, depth = 1, internal node, [2, 3]\n node 2: parent = 1, depth = 2, leaf, []\n node 3: parent = 1, depth = 2, leaf, []\n node 4: parent = 0, depth = 1, internal node, [5, 6, 7]\n node 5: parent = 4, depth = 2, leaf, []\n node 6: parent = 4, depth = 2, leaf, []\n node 7: parent = 4, depth = 2, internal node, [8, 9]\n node 8: parent = 7, depth = 3, leaf, []\n node 9: parent = 7, depth = 3, leaf, []\n node 10: parent = 0, depth = 1, internal node, [11, 12]\n node 11: parent = 10, depth = 2, leaf, []\n node 12: parent = 10, depth = 2, leaf, []"}, {"input": "4\n 1 3 3 2 0\n 0 0\n 3 0\n 2 0", "output": "node 0: parent = 1, depth = 1, leaf, []\n node 1: parent = -1, depth = 0, root, [3, 2, 0]\n node 2: parent = 1, depth = 1, leaf, []\n node 3: parent = 1, depth = 1, leaf, []"}] |
Print the information of each node in the following format ordered by IDs:
node _id_ : parent = _p_ , depth = _d_ , _type_ , [_c_ 1..._c k_]
_p_ is ID of its parent. If the node does not have a parent, print -1.
_d_ is depth of the node.
_type_ is a type of nodes represented by a string (root, internal node or
leaf). If the root can be considered as a leaf or an internal node, print
root.
_c_ 1..._c k_ is the list of children as a ordered tree.
Please follow the format presented in a sample output below. | s540945349 | Accepted | p02279 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node _u_ is given in the
following format:
_id_ _k_ _c_ 1 _c_ 2 ... _c k_
where _id_ is the node ID of _u_ , _k_ is the degree of _u_ , _c_ 1 ... _c k_
are node IDs of 1st, ... _k_ th child of _u_. If the node does not have a
child, the _k_ is 0. | import sys
class Node:
def __init__(self):
self.parent = -1
self.left = -1
self.right = -1
depthList = []
nodeList = []
def readinput():
global nodeList
n = int(input())
nodeList = [Node() for _ in range(n)]
for _ in range(n):
s = list(map(int, input().split()))
id = s[0]
deg = s[1]
child = s[2:]
if deg > 0:
nodeList[id].left = child[0]
for i in range(deg - 1):
nodeList[child[i]].parent = id
nodeList[child[i]].right = child[i + 1]
nodeList[child[deg - 1]].parent = id
return
def findRoot(nodeList):
for i, node in enumerate(nodeList):
if node.parent == -1:
return i
return -1
def setDepth(id, depth):
# sys.setrecursionlimit(3700)
global depthList
global nodeList
depthList[id] = depth
r = nodeList[id].right
# if(r!=-1):
# setDepth(r,depth)
while r != -1:
depthList[r] = depth
if nodeList[r].left != -1:
setDepth(nodeList[r].left, depth + 1)
r = nodeList[r].right
l = nodeList[id].left
if l != -1:
setDepth(l, depth + 1)
def nodeType(node):
if node.parent == -1:
return "root"
elif node.left == -1:
return "leaf"
else:
return "internal node"
def childList(p, nodeList):
child = []
c = nodeList[p].left
while c != -1:
child.append(c)
c = nodeList[c].right
return child
def printNodeList(nodeList, depthList):
for i, node in enumerate(nodeList):
print(
"node {}: parent = {}, depth = {}, {}, {}".format(
i, node.parent, depthList[i], nodeType(node), childList(i, nodeList)
)
)
def main():
global depthList
global nodeList
depthList = [0] * len(nodeList)
root = findRoot(nodeList)
setDepth(root, 0)
printNodeList(nodeList, depthList)
if __name__ == "__main__":
sys.setrecursionlimit(10000)
readinput()
main()
| Rooted Trees
A graph _G_ = (_V_ , _E_) is a data structure where _V_ is a finite set of
vertices and _E_ is a binary relation on _V_ represented by a set of edges.
Fig. 1 illustrates an example of a graph (or graphs).

**Fig. 1**
A free tree is a connnected, acyclic, undirected graph. A rooted tree is a
free tree in which one of the vertices is distinguished from the others. A
vertex of a rooted tree is called "node."
Your task is to write a program which reports the following information for
each node _u_ of a given rooted tree _T_ :
* node ID of _u_
* parent of _u_
* depth of _u_
* node type (root, internal node or leaf)
* a list of chidlren of _u_
If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is
(_p_ , _x_), then _p_ is the **parent** of _x_ , and _x_ is a **child** of
_p_. The root is the only node in _T_ with no parent.
A node with no children is an **external node** or **leaf**. A nonleaf node is
an **internal node**
The number of children of a node _x_ in a rooted tree _T_ is called the
**degree** of _x_.
The length of the path from the root _r_ to a node _x_ is the **depth** of _x_
in _T_.
Here, the given tree consists of _n_ nodes and evey node has a unique ID from
0 to _n_ -1.
Fig. 2 shows an example of rooted trees where ID of each node is indicated by
a number in a circle (node). The example corresponds to the first sample
input.

**Fig. 2** | [{"input": "13\n 0 3 1 4 10\n 1 2 2 3\n 2 0\n 3 0\n 4 3 5 6 7\n 5 0\n 6 0\n 7 2 8 9\n 8 0\n 9 0\n 10 2 11 12\n 11 0\n 12 0", "output": "node 0: parent = -1, depth = 0, root, [1, 4, 10]\n node 1: parent = 0, depth = 1, internal node, [2, 3]\n node 2: parent = 1, depth = 2, leaf, []\n node 3: parent = 1, depth = 2, leaf, []\n node 4: parent = 0, depth = 1, internal node, [5, 6, 7]\n node 5: parent = 4, depth = 2, leaf, []\n node 6: parent = 4, depth = 2, leaf, []\n node 7: parent = 4, depth = 2, internal node, [8, 9]\n node 8: parent = 7, depth = 3, leaf, []\n node 9: parent = 7, depth = 3, leaf, []\n node 10: parent = 0, depth = 1, internal node, [11, 12]\n node 11: parent = 10, depth = 2, leaf, []\n node 12: parent = 10, depth = 2, leaf, []"}, {"input": "4\n 1 3 3 2 0\n 0 0\n 3 0\n 2 0", "output": "node 0: parent = 1, depth = 1, leaf, []\n node 1: parent = -1, depth = 0, root, [3, 2, 0]\n node 2: parent = 1, depth = 1, leaf, []\n node 3: parent = 1, depth = 1, leaf, []"}] |
Print the information of each node in the following format ordered by IDs:
node _id_ : parent = _p_ , depth = _d_ , _type_ , [_c_ 1..._c k_]
_p_ is ID of its parent. If the node does not have a parent, print -1.
_d_ is depth of the node.
_type_ is a type of nodes represented by a string (root, internal node or
leaf). If the root can be considered as a leaf or an internal node, print
root.
_c_ 1..._c k_ is the list of children as a ordered tree.
Please follow the format presented in a sample output below. | s181976262 | Accepted | p02279 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node _u_ is given in the
following format:
_id_ _k_ _c_ 1 _c_ 2 ... _c k_
where _id_ is the node ID of _u_ , _k_ is the degree of _u_ , _c_ 1 ... _c k_
are node IDs of 1st, ... _k_ th child of _u_. If the node does not have a
child, the _k_ is 0. | import sys
sys.setrecursionlimit(2**20)
n = int(input())
NIL = -1
class node:
def __init__(self, parent, left, right):
self.parent = parent
self.left = left
self.right = right
T = [node(NIL, NIL, NIL) for _ in range(n)]
firstid = 0
for _ in range(n): # 入力の一例
A = list(map(int, input().split()))
id = A[0]
if n == 1:
firstid = id
k = A[1]
if k != 0:
chil = A[2 : 2 + k]
T[id].left = chil[0]
for i in range(k):
if i != k - 1:
T[chil[i]].right = chil[i + 1]
T[chil[i]].parent = id
else:
T[chil[i]].parent = id
D = [0] * n
def setDepth(u, p): # uはノードの番号、pはノードpの深さ。
D[u] = p # uより右下にあるノードの深さをDに保存し、かえす
if T[u].right != NIL:
setDepth(T[u].right, p)
if T[u].left != NIL:
setDepth(T[u].left, p + 1)
return D
def getDepth(u):
d = 0
while T[u].parent != NIL:
u = T[u].parent
d += 1
return d
def findroot(u): # 根をみつける
while T[u].parent != NIL:
u = T[u].parent
return u
def printChildren(u): # 番号uのノードの子供をlistでかえす
child = []
if T[u].left != NIL:
c = T[u].left
while c != NIL:
child.append(c)
c = T[c].right
return child
def ppp():
for i in range(n):
ccc = T[i]
print(i, ccc.parent, ccc.left, ccc.right)
# ここからもんだいによってかわる
r = findroot(firstid)
D = setDepth(r, 0)
for i in range(n):
nod = T[i]
d = getDepth(i)
s = "internal node"
if nod.parent == NIL:
s = "root"
elif nod.left == NIL:
s = "leaf"
child = printChildren(i)
print(f"node {i}: parent = {nod.parent}, depth = {d}, {s}, {child}")
| Rooted Trees
A graph _G_ = (_V_ , _E_) is a data structure where _V_ is a finite set of
vertices and _E_ is a binary relation on _V_ represented by a set of edges.
Fig. 1 illustrates an example of a graph (or graphs).

**Fig. 1**
A free tree is a connnected, acyclic, undirected graph. A rooted tree is a
free tree in which one of the vertices is distinguished from the others. A
vertex of a rooted tree is called "node."
Your task is to write a program which reports the following information for
each node _u_ of a given rooted tree _T_ :
* node ID of _u_
* parent of _u_
* depth of _u_
* node type (root, internal node or leaf)
* a list of chidlren of _u_
If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is
(_p_ , _x_), then _p_ is the **parent** of _x_ , and _x_ is a **child** of
_p_. The root is the only node in _T_ with no parent.
A node with no children is an **external node** or **leaf**. A nonleaf node is
an **internal node**
The number of children of a node _x_ in a rooted tree _T_ is called the
**degree** of _x_.
The length of the path from the root _r_ to a node _x_ is the **depth** of _x_
in _T_.
Here, the given tree consists of _n_ nodes and evey node has a unique ID from
0 to _n_ -1.
Fig. 2 shows an example of rooted trees where ID of each node is indicated by
a number in a circle (node). The example corresponds to the first sample
input.

**Fig. 2** | [{"input": "13\n 0 3 1 4 10\n 1 2 2 3\n 2 0\n 3 0\n 4 3 5 6 7\n 5 0\n 6 0\n 7 2 8 9\n 8 0\n 9 0\n 10 2 11 12\n 11 0\n 12 0", "output": "node 0: parent = -1, depth = 0, root, [1, 4, 10]\n node 1: parent = 0, depth = 1, internal node, [2, 3]\n node 2: parent = 1, depth = 2, leaf, []\n node 3: parent = 1, depth = 2, leaf, []\n node 4: parent = 0, depth = 1, internal node, [5, 6, 7]\n node 5: parent = 4, depth = 2, leaf, []\n node 6: parent = 4, depth = 2, leaf, []\n node 7: parent = 4, depth = 2, internal node, [8, 9]\n node 8: parent = 7, depth = 3, leaf, []\n node 9: parent = 7, depth = 3, leaf, []\n node 10: parent = 0, depth = 1, internal node, [11, 12]\n node 11: parent = 10, depth = 2, leaf, []\n node 12: parent = 10, depth = 2, leaf, []"}, {"input": "4\n 1 3 3 2 0\n 0 0\n 3 0\n 2 0", "output": "node 0: parent = 1, depth = 1, leaf, []\n node 1: parent = -1, depth = 0, root, [3, 2, 0]\n node 2: parent = 1, depth = 1, leaf, []\n node 3: parent = 1, depth = 1, leaf, []"}] |
Print the information of each node in the following format ordered by IDs:
node _id_ : parent = _p_ , depth = _d_ , _type_ , [_c_ 1..._c k_]
_p_ is ID of its parent. If the node does not have a parent, print -1.
_d_ is depth of the node.
_type_ is a type of nodes represented by a string (root, internal node or
leaf). If the root can be considered as a leaf or an internal node, print
root.
_c_ 1..._c k_ is the list of children as a ordered tree.
Please follow the format presented in a sample output below. | s491033437 | Accepted | p02279 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node _u_ is given in the
following format:
_id_ _k_ _c_ 1 _c_ 2 ... _c k_
where _id_ is the node ID of _u_ , _k_ is the degree of _u_ , _c_ 1 ... _c k_
are node IDs of 1st, ... _k_ th child of _u_. If the node does not have a
child, the _k_ is 0. | # coding: utf-8
import queue
class Node:
def __init__(self, myNum, childNums):
self.myNum = myNum
self.parentNum = -1
self.childNums = childNums
self.nodeType = ""
self.depth = -1
n = int(input().rstrip())
nodes = []
# 入力を使ってクラスに放り込む
for i in range(n):
line = [int(i) for i in input().rstrip().split()]
childNums = [i for i in line[2:]]
nodes.append(Node(line[0], childNums))
# nodesを節点順にソートする
nodes = sorted(nodes, key=lambda x: x.myNum)
# 親を計算する
for node in nodes:
for num in node.childNums:
nodes[num].parentNum = node.myNum
# type を求める
for node in nodes:
if node.parentNum == -1:
node.nodeType = "root"
rootNum = node.myNum
elif not node.childNums:
node.nodeType = "leaf"
else:
node.nodeType = "internal node"
# depth を計算する
q = queue.Queue()
q.put(nodes[rootNum])
nodes[rootNum].depth = 0
while not q.empty():
nd = q.get()
for c in nd.childNums:
nodes[c].depth = nd.depth + 1
q.put(nodes[c])
# アウトプット
for node in nodes:
print(
"node {0}: parent = {1}, depth = {2}, {3}, {4}".format(
node.myNum, node.parentNum, node.depth, node.nodeType, node.childNums
)
)
| Rooted Trees
A graph _G_ = (_V_ , _E_) is a data structure where _V_ is a finite set of
vertices and _E_ is a binary relation on _V_ represented by a set of edges.
Fig. 1 illustrates an example of a graph (or graphs).

**Fig. 1**
A free tree is a connnected, acyclic, undirected graph. A rooted tree is a
free tree in which one of the vertices is distinguished from the others. A
vertex of a rooted tree is called "node."
Your task is to write a program which reports the following information for
each node _u_ of a given rooted tree _T_ :
* node ID of _u_
* parent of _u_
* depth of _u_
* node type (root, internal node or leaf)
* a list of chidlren of _u_
If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is
(_p_ , _x_), then _p_ is the **parent** of _x_ , and _x_ is a **child** of
_p_. The root is the only node in _T_ with no parent.
A node with no children is an **external node** or **leaf**. A nonleaf node is
an **internal node**
The number of children of a node _x_ in a rooted tree _T_ is called the
**degree** of _x_.
The length of the path from the root _r_ to a node _x_ is the **depth** of _x_
in _T_.
Here, the given tree consists of _n_ nodes and evey node has a unique ID from
0 to _n_ -1.
Fig. 2 shows an example of rooted trees where ID of each node is indicated by
a number in a circle (node). The example corresponds to the first sample
input.

**Fig. 2** | [{"input": "13\n 0 3 1 4 10\n 1 2 2 3\n 2 0\n 3 0\n 4 3 5 6 7\n 5 0\n 6 0\n 7 2 8 9\n 8 0\n 9 0\n 10 2 11 12\n 11 0\n 12 0", "output": "node 0: parent = -1, depth = 0, root, [1, 4, 10]\n node 1: parent = 0, depth = 1, internal node, [2, 3]\n node 2: parent = 1, depth = 2, leaf, []\n node 3: parent = 1, depth = 2, leaf, []\n node 4: parent = 0, depth = 1, internal node, [5, 6, 7]\n node 5: parent = 4, depth = 2, leaf, []\n node 6: parent = 4, depth = 2, leaf, []\n node 7: parent = 4, depth = 2, internal node, [8, 9]\n node 8: parent = 7, depth = 3, leaf, []\n node 9: parent = 7, depth = 3, leaf, []\n node 10: parent = 0, depth = 1, internal node, [11, 12]\n node 11: parent = 10, depth = 2, leaf, []\n node 12: parent = 10, depth = 2, leaf, []"}, {"input": "4\n 1 3 3 2 0\n 0 0\n 3 0\n 2 0", "output": "node 0: parent = 1, depth = 1, leaf, []\n node 1: parent = -1, depth = 0, root, [3, 2, 0]\n node 2: parent = 1, depth = 1, leaf, []\n node 3: parent = 1, depth = 1, leaf, []"}] |
Print the information of each node in the following format ordered by IDs:
node _id_ : parent = _p_ , depth = _d_ , _type_ , [_c_ 1..._c k_]
_p_ is ID of its parent. If the node does not have a parent, print -1.
_d_ is depth of the node.
_type_ is a type of nodes represented by a string (root, internal node or
leaf). If the root can be considered as a leaf or an internal node, print
root.
_c_ 1..._c k_ is the list of children as a ordered tree.
Please follow the format presented in a sample output below. | s675115284 | Accepted | p02279 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node _u_ is given in the
following format:
_id_ _k_ _c_ 1 _c_ 2 ... _c k_
where _id_ is the node ID of _u_ , _k_ is the degree of _u_ , _c_ 1 ... _c k_
are node IDs of 1st, ... _k_ th child of _u_. If the node does not have a
child, the _k_ is 0. | def depth(s):
for i in ch[s]:
dep[i] = dep[s] + 1
if len(ch[i]) != 0:
depth(i)
def parent(t):
for i in ch[t]:
par[i] = t
if len(ch[i]) != 0:
parent(i)
n = int(input())
data = [list(map(int, input().split())) for _ in range(n)]
ch = {}
par = {}
dep = {}
kari = []
for i in range(n):
kari.append(i)
# print(data)
for i in data:
ch[i[0]] = list(i[2:])
for j in list(i[2:]):
kari.remove(j)
r = kari[0]
dep[r] = 0
par[r] = -1
# print(r)
# print(ans)
"""
for i in range(n):
#print(i[0])
try:
par[i] = [k for k, v in ch.items() if i in v][0]
except:
par[i] = -1
dep[i] = 0
r = i
"""
depth(r)
parent(r)
for i in range(n):
if par[i] == -1:
tmp = "root"
elif len(ch[i]) == 0:
tmp = "leaf"
else:
tmp = "internal node"
print(
"node {}: parent = {}, depth = {}, {}, {}".format(i, par[i], dep[i], tmp, ch[i])
)
# print(ch)
# print(par)
# print(dep)
| Rooted Trees
A graph _G_ = (_V_ , _E_) is a data structure where _V_ is a finite set of
vertices and _E_ is a binary relation on _V_ represented by a set of edges.
Fig. 1 illustrates an example of a graph (or graphs).

**Fig. 1**
A free tree is a connnected, acyclic, undirected graph. A rooted tree is a
free tree in which one of the vertices is distinguished from the others. A
vertex of a rooted tree is called "node."
Your task is to write a program which reports the following information for
each node _u_ of a given rooted tree _T_ :
* node ID of _u_
* parent of _u_
* depth of _u_
* node type (root, internal node or leaf)
* a list of chidlren of _u_
If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is
(_p_ , _x_), then _p_ is the **parent** of _x_ , and _x_ is a **child** of
_p_. The root is the only node in _T_ with no parent.
A node with no children is an **external node** or **leaf**. A nonleaf node is
an **internal node**
The number of children of a node _x_ in a rooted tree _T_ is called the
**degree** of _x_.
The length of the path from the root _r_ to a node _x_ is the **depth** of _x_
in _T_.
Here, the given tree consists of _n_ nodes and evey node has a unique ID from
0 to _n_ -1.
Fig. 2 shows an example of rooted trees where ID of each node is indicated by
a number in a circle (node). The example corresponds to the first sample
input.

**Fig. 2** | [{"input": "13\n 0 3 1 4 10\n 1 2 2 3\n 2 0\n 3 0\n 4 3 5 6 7\n 5 0\n 6 0\n 7 2 8 9\n 8 0\n 9 0\n 10 2 11 12\n 11 0\n 12 0", "output": "node 0: parent = -1, depth = 0, root, [1, 4, 10]\n node 1: parent = 0, depth = 1, internal node, [2, 3]\n node 2: parent = 1, depth = 2, leaf, []\n node 3: parent = 1, depth = 2, leaf, []\n node 4: parent = 0, depth = 1, internal node, [5, 6, 7]\n node 5: parent = 4, depth = 2, leaf, []\n node 6: parent = 4, depth = 2, leaf, []\n node 7: parent = 4, depth = 2, internal node, [8, 9]\n node 8: parent = 7, depth = 3, leaf, []\n node 9: parent = 7, depth = 3, leaf, []\n node 10: parent = 0, depth = 1, internal node, [11, 12]\n node 11: parent = 10, depth = 2, leaf, []\n node 12: parent = 10, depth = 2, leaf, []"}, {"input": "4\n 1 3 3 2 0\n 0 0\n 3 0\n 2 0", "output": "node 0: parent = 1, depth = 1, leaf, []\n node 1: parent = -1, depth = 0, root, [3, 2, 0]\n node 2: parent = 1, depth = 1, leaf, []\n node 3: parent = 1, depth = 1, leaf, []"}] |
Print the information of each node in the following format ordered by IDs:
node _id_ : parent = _p_ , depth = _d_ , _type_ , [_c_ 1..._c k_]
_p_ is ID of its parent. If the node does not have a parent, print -1.
_d_ is depth of the node.
_type_ is a type of nodes represented by a string (root, internal node or
leaf). If the root can be considered as a leaf or an internal node, print
root.
_c_ 1..._c k_ is the list of children as a ordered tree.
Please follow the format presented in a sample output below. | s579289020 | Accepted | p02279 | The first line of the input includes an integer _n_ , the number of nodes of
the tree.
In the next _n_ lines, the information of each node _u_ is given in the
following format:
_id_ _k_ _c_ 1 _c_ 2 ... _c k_
where _id_ is the node ID of _u_ , _k_ is the degree of _u_ , _c_ 1 ... _c k_
are node IDs of 1st, ... _k_ th child of _u_. If the node does not have a
child, the _k_ is 0. | import queue
from collections import namedtuple
U = namedtuple("U", "id parent depth type children")
n = int(input())
dic, link = [dict() for _ in range(2)]
se = set([int(x) for x in range(n)])
for i in range(n):
tmp = list(map(int, input().split()))
tmp.reverse()
a, k = [tmp.pop() for _ in range(2)]
link[a] = []
for j in range(k):
b = tmp.pop()
link[a].append(b)
se.remove(b)
def bfs(s):
q = queue.Queue()
q.put(U(s, -1, 0, "root", link[s]))
while q.qsize() != 0:
u0 = q.get()
dic[u0.id] = u0
for u1 in u0.children:
children = link[u1]
node_type = "leaf" if children == [] else "internal node"
q.put(U(u1, u0.id, u0.depth + 1, node_type, children))
bfs(se.pop())
for i in range(n):
print("node", dic[i].id, end="")
print(": parent =", dic[i].parent, end="")
print(", depth =", dic[i].depth, end="")
print(",", dic[i].type, end="")
print(",", dic[i].children)
| Rooted Trees
A graph _G_ = (_V_ , _E_) is a data structure where _V_ is a finite set of
vertices and _E_ is a binary relation on _V_ represented by a set of edges.
Fig. 1 illustrates an example of a graph (or graphs).

**Fig. 1**
A free tree is a connnected, acyclic, undirected graph. A rooted tree is a
free tree in which one of the vertices is distinguished from the others. A
vertex of a rooted tree is called "node."
Your task is to write a program which reports the following information for
each node _u_ of a given rooted tree _T_ :
* node ID of _u_
* parent of _u_
* depth of _u_
* node type (root, internal node or leaf)
* a list of chidlren of _u_
If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is
(_p_ , _x_), then _p_ is the **parent** of _x_ , and _x_ is a **child** of
_p_. The root is the only node in _T_ with no parent.
A node with no children is an **external node** or **leaf**. A nonleaf node is
an **internal node**
The number of children of a node _x_ in a rooted tree _T_ is called the
**degree** of _x_.
The length of the path from the root _r_ to a node _x_ is the **depth** of _x_
in _T_.
Here, the given tree consists of _n_ nodes and evey node has a unique ID from
0 to _n_ -1.
Fig. 2 shows an example of rooted trees where ID of each node is indicated by
a number in a circle (node). The example corresponds to the first sample
input.

**Fig. 2** | [{"input": "13\n 0 3 1 4 10\n 1 2 2 3\n 2 0\n 3 0\n 4 3 5 6 7\n 5 0\n 6 0\n 7 2 8 9\n 8 0\n 9 0\n 10 2 11 12\n 11 0\n 12 0", "output": "node 0: parent = -1, depth = 0, root, [1, 4, 10]\n node 1: parent = 0, depth = 1, internal node, [2, 3]\n node 2: parent = 1, depth = 2, leaf, []\n node 3: parent = 1, depth = 2, leaf, []\n node 4: parent = 0, depth = 1, internal node, [5, 6, 7]\n node 5: parent = 4, depth = 2, leaf, []\n node 6: parent = 4, depth = 2, leaf, []\n node 7: parent = 4, depth = 2, internal node, [8, 9]\n node 8: parent = 7, depth = 3, leaf, []\n node 9: parent = 7, depth = 3, leaf, []\n node 10: parent = 0, depth = 1, internal node, [11, 12]\n node 11: parent = 10, depth = 2, leaf, []\n node 12: parent = 10, depth = 2, leaf, []"}, {"input": "4\n 1 3 3 2 0\n 0 0\n 3 0\n 2 0", "output": "node 0: parent = 1, depth = 1, leaf, []\n node 1: parent = -1, depth = 0, root, [3, 2, 0]\n node 2: parent = 1, depth = 1, leaf, []\n node 3: parent = 1, depth = 1, leaf, []"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.