output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s701658849 | Runtime Error | p02570 | Input is given from Standard Input in the following format:
D T S | N, M = map(int, input().split())
edge = []
for i in range(M):
a, b = map(int, input().split())
add = []
for j in range(len(edge)):
if a in edge[j] or b in edge[j]:
edge[j].append(a)
edge[j].append(b)
add.append(j)
if len(add) == 0:
edge.append([a, b])
elif len(add) >= 2:
for j in range(1, len(add)):
edge[add[0]].extend(edge[add[j]])
for j in range(1, len(add)):
edge.pop(add[j])
ans = 0
for i in range(len(edge)):
x = list(set(edge[i]))
if len(x) > ans:
ans = len(x)
print(ans)
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s573637117 | Wrong Answer | p02570 | Input is given from Standard Input in the following format:
D T S | D, T, S = list(map(lambda x: int(x), input().split()))
print("Yes" if T > D / S else "No")
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
Print an integer representing the minimum amount of money needed before
cutting the bar into two parts with the same length.
* * * | s396185201 | Wrong Answer | p02854 | Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N | print(0)
| Statement
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1
notches, which divide the bar into N sections. The i-th section from the left
has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two
parts with the same length. However, this may not be possible as is, so he
will do the following operations some number of times **before** he does the
cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts
with the same length. | [{"input": "3\n 2 4 3", "output": "3\n \n\nThe initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi\ncan cut the bar equally after doing the following operations for 3 yen:\n\n * Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].\n * Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].\n * Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.\n\n* * *"}, {"input": "12\n 100 104 102 105 103 103 101 105 104 102 104 101", "output": "0"}] |
Print an integer representing the minimum amount of money needed before
cutting the bar into two parts with the same length.
* * * | s116047113 | Accepted | p02854 | Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N | n = int(input())
l = tuple(map(int, input().split()))
s = sum(l)
m = 0
p = 0
while 2 * m < s:
m += l[p]
p += 1
a = 2 * m - s
b = s - 2 * (m - l[p - 1])
print(min(a, b))
| Statement
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1
notches, which divide the bar into N sections. The i-th section from the left
has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two
parts with the same length. However, this may not be possible as is, so he
will do the following operations some number of times **before** he does the
cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts
with the same length. | [{"input": "3\n 2 4 3", "output": "3\n \n\nThe initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi\ncan cut the bar equally after doing the following operations for 3 yen:\n\n * Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].\n * Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].\n * Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.\n\n* * *"}, {"input": "12\n 100 104 102 105 103 103 101 105 104 102 104 101", "output": "0"}] |
Print an integer representing the minimum amount of money needed before
cutting the bar into two parts with the same length.
* * * | s244731836 | Wrong Answer | p02854 | Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N | N = int(input())
P = list(map(int, input().split()))
cnt = 1 # P[0] is counted forcely
min_num = P[0]
for p in P:
if p < min_num:
min_num = p
cnt += 1
print(cnt)
| Statement
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1
notches, which divide the bar into N sections. The i-th section from the left
has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two
parts with the same length. However, this may not be possible as is, so he
will do the following operations some number of times **before** he does the
cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts
with the same length. | [{"input": "3\n 2 4 3", "output": "3\n \n\nThe initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi\ncan cut the bar equally after doing the following operations for 3 yen:\n\n * Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].\n * Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].\n * Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.\n\n* * *"}, {"input": "12\n 100 104 102 105 103 103 101 105 104 102 104 101", "output": "0"}] |
Print an integer representing the minimum amount of money needed before
cutting the bar into two parts with the same length.
* * * | s745134056 | Accepted | p02854 | Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N | # 2019/11/23
# DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選 - B
# Binary Search
def binSearch(tlis, tval):
lf = 0
rg = len(tlis)
while lf <= rg:
ct = int((lf + rg) / 2)
if tlis[ct] < tval:
lf = ct + 1
elif tlis[ct] > tval:
rg = ct - 1
else:
return ct
return ct
# Input
n = int(input())
a = list(map(int, input().split()))
acm_a = list()
acm_a.append(0)
# Sum
for i in range(len(a)):
acm_a.append(a[i] + acm_a[i])
acm_a.append(acm_a[len(a)])
# Calc Center
center = acm_a[len(a)] / 2
ctidx = binSearch(acm_a, center)
ans = min(
abs((acm_a[len(a)] - acm_a[ctidx - 1]) - acm_a[ctidx - 1]),
abs((acm_a[len(a)] - acm_a[ctidx]) - acm_a[ctidx]),
abs((acm_a[len(a)] - acm_a[ctidx + 1]) - acm_a[ctidx + 1]),
)
# Output
print(ans)
| Statement
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1
notches, which divide the bar into N sections. The i-th section from the left
has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two
parts with the same length. However, this may not be possible as is, so he
will do the following operations some number of times **before** he does the
cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts
with the same length. | [{"input": "3\n 2 4 3", "output": "3\n \n\nThe initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi\ncan cut the bar equally after doing the following operations for 3 yen:\n\n * Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].\n * Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].\n * Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.\n\n* * *"}, {"input": "12\n 100 104 102 105 103 103 101 105 104 102 104 101", "output": "0"}] |
Print an integer representing the minimum amount of money needed before
cutting the bar into two parts with the same length.
* * * | s866799807 | Wrong Answer | p02854 | Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N | n = int(input())
S = list(map(int, input().split()))
Sum = sum(S)
# print(Sum)
wa = 0
count = 0
for i in range(n):
if wa < Sum / 2:
wa = wa + S[i]
count = count + 1
if count == n:
wa = wa - S[n - 1]
# print(wa,Sum-wa)
print(int(abs(Sum - 2 * wa)))
| Statement
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1
notches, which divide the bar into N sections. The i-th section from the left
has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two
parts with the same length. However, this may not be possible as is, so he
will do the following operations some number of times **before** he does the
cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts
with the same length. | [{"input": "3\n 2 4 3", "output": "3\n \n\nThe initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi\ncan cut the bar equally after doing the following operations for 3 yen:\n\n * Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].\n * Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].\n * Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.\n\n* * *"}, {"input": "12\n 100 104 102 105 103 103 101 105 104 102 104 101", "output": "0"}] |
Find one path that satisfies the conditions, and print it in the following
format. In the first line, print the count of the vertices contained in the
path. In the second line, print a space-separated list of the indices of the
vertices, in order of appearance in the path.
* * * | s054090339 | Accepted | p03746 | Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
:
A_M B_M | import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
def main():
from collections import defaultdict, deque
N, M = map(int, readline().split())
edge = defaultdict(list)
for _ in range(M):
a, b = map(int, readline().split())
edge[a].append(b)
edge[b].append(a)
first = 1
second = edge[1][0]
visited = [False] * (N + 1)
visited[first] = True
visited[second] = True
que = deque()
que.append(first)
path1 = []
path2 = []
flag = True
while flag:
u = que.popleft()
path1.append(u)
flag = False
for v in edge[u]:
if not visited[v]:
visited[v] = True
que.append(v)
flag = True
break
que = deque()
que.append(second)
flag = True
while flag:
u = que.popleft()
path2.append(u)
flag = False
for v in edge[u]:
if not visited[v]:
visited[v] = True
que.append(v)
flag = True
break
print(len(path1) + len(path2))
print(*path1[::-1], *path2)
if __name__ == "__main__":
main()
| Statement
You are given a connected undirected simple graph, which has N vertices and M
edges. The vertices are numbered 1 through N, and the edges are numbered 1
through M. Edge i connects vertices A_i and B_i. Your task is to find a path
that satisfies the following conditions:
* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.
It can be proved that such a path always exists. Also, if there are more than
one solution, any of them will be accepted. | [{"input": "5 6\n 1 3\n 1 4\n 2 3\n 1 5\n 3 5\n 2 4", "output": "4\n 2 3 1 4\n \n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4. There\nare also two vertices directly connected to vertex 4: vertices 1 and 2. Hence,\nthe path 2 \u2192 3 \u2192 1 \u2192 4 satisfies the conditions.\n\n* * *"}, {"input": "7 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 5\n 2 6", "output": "7\n 1 2 3 4 5 6 7"}] |
Find one path that satisfies the conditions, and print it in the following
format. In the first line, print the count of the vertices contained in the
path. In the second line, print a space-separated list of the indices of the
vertices, in order of appearance in the path.
* * * | s645085796 | Runtime Error | p03746 | Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
:
A_M B_M | #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
int main(void)
{
LL n, m;
cin >> n >> m;
vector<vector<LL>> a(n+1);
vector<bool> b(n+1, false);
vector<LL> s(1),t(1);
cin >> s[0] >> t[0];
b[s[0]]=true;
b[t[0]]=true;
REP(i,m-1) {
LL l, r;
cin >> l >> r;
a[l].push_back(r);
a[r].push_back(l);
}
for(;;) {
LL l=s.back();
for(LL x:a[l]) {
if(b[x]) continue;
b[x] = true;
s.push_back(x);
break;
}
if(l==s.back()) break;
}
for(;;) {
LL r=t.back();
for(LL x:a[r]) {
if(b[x]) continue;
b[x] = true;
t.push_back(x);
break;
}
if(r==t.back()) break;
}
reverse(s.begin(),s.end());
for(auto x:t) s.push_back(x);
cout << s.size() << endl;
REP(i, s.size()) {
if(i) cout << " ";
cout << s[i];
}
cout << endl;
return 0;
}
| Statement
You are given a connected undirected simple graph, which has N vertices and M
edges. The vertices are numbered 1 through N, and the edges are numbered 1
through M. Edge i connects vertices A_i and B_i. Your task is to find a path
that satisfies the following conditions:
* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.
It can be proved that such a path always exists. Also, if there are more than
one solution, any of them will be accepted. | [{"input": "5 6\n 1 3\n 1 4\n 2 3\n 1 5\n 3 5\n 2 4", "output": "4\n 2 3 1 4\n \n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4. There\nare also two vertices directly connected to vertex 4: vertices 1 and 2. Hence,\nthe path 2 \u2192 3 \u2192 1 \u2192 4 satisfies the conditions.\n\n* * *"}, {"input": "7 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 5\n 2 6", "output": "7\n 1 2 3 4 5 6 7"}] |
Find one path that satisfies the conditions, and print it in the following
format. In the first line, print the count of the vertices contained in the
path. In the second line, print a space-separated list of the indices of the
vertices, in order of appearance in the path.
* * * | s663272686 | Runtime Error | p03746 | Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
:
A_M B_M | import heapq
n, x = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
tt = [[] for _ in range(10**5 + 1)]
for i in range(n):
tt[t[i]].append(-a[i])
def max_score(time):
q = []
heapq.heapify(q)
for i in range(time, 10**5 + 1):
for j in tt[i]:
heapq.heappush(q, j)
ans = 0
for i in reversed(range(time)):
if q:
ans += heapq.heappop(q)
for j in tt[i]:
heapq.heappush(q, j)
return -ans
if max_score(10**5) < x:
print(-1)
exit()
mi = 0
ma = 10**5
while mi != ma:
m = (mi + ma) // 2
if max_score(m) >= x:
ma = m
else:
mi += 1
print(mi)
| Statement
You are given a connected undirected simple graph, which has N vertices and M
edges. The vertices are numbered 1 through N, and the edges are numbered 1
through M. Edge i connects vertices A_i and B_i. Your task is to find a path
that satisfies the following conditions:
* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.
It can be proved that such a path always exists. Also, if there are more than
one solution, any of them will be accepted. | [{"input": "5 6\n 1 3\n 1 4\n 2 3\n 1 5\n 3 5\n 2 4", "output": "4\n 2 3 1 4\n \n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4. There\nare also two vertices directly connected to vertex 4: vertices 1 and 2. Hence,\nthe path 2 \u2192 3 \u2192 1 \u2192 4 satisfies the conditions.\n\n* * *"}, {"input": "7 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 5\n 2 6", "output": "7\n 1 2 3 4 5 6 7"}] |
Find one path that satisfies the conditions, and print it in the following
format. In the first line, print the count of the vertices contained in the
path. In the second line, print a space-separated list of the indices of the
vertices, in order of appearance in the path.
* * * | s004573919 | Accepted | p03746 | Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
:
A_M B_M | from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")
def main():
N, M = map(int, input().split())
graph = defaultdict(list)
for _ in range(M):
A, B = map(int, input().split())
graph[A].append(B)
graph[B].append(A)
route = deque()
used = set()
route.appendleft(1)
used.add(1)
for n in graph[1]:
route.append(n)
used.add(n)
break
while True:
start, end = route[0], route[-1]
start_ok = True
for n in graph[start]:
if n not in used:
start_ok = False
route.appendleft(n)
used.add(n)
break
end_ok = True
for n in graph[end]:
if n not in used:
end_ok = False
route.append(n)
used.add(n)
break
if start_ok and end_ok:
break
print(len(route))
print(*route, sep=" ")
if __name__ == "__main__":
main()
| Statement
You are given a connected undirected simple graph, which has N vertices and M
edges. The vertices are numbered 1 through N, and the edges are numbered 1
through M. Edge i connects vertices A_i and B_i. Your task is to find a path
that satisfies the following conditions:
* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.
It can be proved that such a path always exists. Also, if there are more than
one solution, any of them will be accepted. | [{"input": "5 6\n 1 3\n 1 4\n 2 3\n 1 5\n 3 5\n 2 4", "output": "4\n 2 3 1 4\n \n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4. There\nare also two vertices directly connected to vertex 4: vertices 1 and 2. Hence,\nthe path 2 \u2192 3 \u2192 1 \u2192 4 satisfies the conditions.\n\n* * *"}, {"input": "7 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 5\n 2 6", "output": "7\n 1 2 3 4 5 6 7"}] |
Find one path that satisfies the conditions, and print it in the following
format. In the first line, print the count of the vertices contained in the
path. In the second line, print a space-separated list of the indices of the
vertices, in order of appearance in the path.
* * * | s980215331 | Accepted | p03746 | Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
:
A_M B_M | n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
d = {}
for i, j in a:
d[i] = d.get(i, set()) | {j}
d[j] = d.get(j, set()) | {i}
path = a[0][:]
sp = set(path)
while d[path[-1]] - sp:
t = d[path[-1]] - sp
t = t.pop()
path.append(t)
sp.add(t)
path = path[::-1]
while d[path[-1]] - sp:
t = d[path[-1]] - sp
t = t.pop()
path.append(t)
sp.add(t)
print(len(path))
print(*path)
| Statement
You are given a connected undirected simple graph, which has N vertices and M
edges. The vertices are numbered 1 through N, and the edges are numbered 1
through M. Edge i connects vertices A_i and B_i. Your task is to find a path
that satisfies the following conditions:
* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.
It can be proved that such a path always exists. Also, if there are more than
one solution, any of them will be accepted. | [{"input": "5 6\n 1 3\n 1 4\n 2 3\n 1 5\n 3 5\n 2 4", "output": "4\n 2 3 1 4\n \n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4. There\nare also two vertices directly connected to vertex 4: vertices 1 and 2. Hence,\nthe path 2 \u2192 3 \u2192 1 \u2192 4 satisfies the conditions.\n\n* * *"}, {"input": "7 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 5\n 2 6", "output": "7\n 1 2 3 4 5 6 7"}] |
Find one path that satisfies the conditions, and print it in the following
format. In the first line, print the count of the vertices contained in the
path. In the second line, print a space-separated list of the indices of the
vertices, in order of appearance in the path.
* * * | s052120555 | Accepted | p03746 | Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
:
A_M B_M | # -*- coding: utf-8 -*-
temp = input().split()
N = int(temp[0])
M = int(temp[1])
AB = [[int(j) - 1 for j in input().split()] for i in range(M)]
chain = [[] for i in range(N)] # 各頂点の連結先
used = [False for i in range(N)] # 使ったかどうか
ans = [] # 答え(連結順にする)
# 連結データ作成
for i in range(M):
chain[AB[i][0]].append(AB[i][1])
chain[AB[i][1]].append(AB[i][0])
# 少なくとも連結のある頂点を探す
# 連結のある頂点をstartに格納
# ansとusedに、使った証拠を残す
# startは後で使うので、nextに移す
start = 0
while len(chain[start]) == 0:
start += 1
ans.append(start)
used[start] = True
next = start
# 連結先が無くなるまで連結する
while True:
# 連結先で、使っていない場所を探す
for point in chain[next]:
if used[point] == False:
break
else:
break # for文完走なら、もう完結
# 使ってないところをusedとnextとansに代入して進める
used[point] = True
next = point
ans.append(point)
# 逆方向に進める
while True:
for point in chain[start]:
if used[point] == False:
break
else:
break
used[point] = True
start = point
ans.insert(0, start)
print(len(ans))
ANS = ""
for i in ans:
ANS += str(i + 1) + " "
print(ANS[:-1])
| Statement
You are given a connected undirected simple graph, which has N vertices and M
edges. The vertices are numbered 1 through N, and the edges are numbered 1
through M. Edge i connects vertices A_i and B_i. Your task is to find a path
that satisfies the following conditions:
* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.
It can be proved that such a path always exists. Also, if there are more than
one solution, any of them will be accepted. | [{"input": "5 6\n 1 3\n 1 4\n 2 3\n 1 5\n 3 5\n 2 4", "output": "4\n 2 3 1 4\n \n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4. There\nare also two vertices directly connected to vertex 4: vertices 1 and 2. Hence,\nthe path 2 \u2192 3 \u2192 1 \u2192 4 satisfies the conditions.\n\n* * *"}, {"input": "7 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 5\n 2 6", "output": "7\n 1 2 3 4 5 6 7"}] |
Find one path that satisfies the conditions, and print it in the following
format. In the first line, print the count of the vertices contained in the
path. In the second line, print a space-separated list of the indices of the
vertices, in order of appearance in the path.
* * * | s498273110 | Wrong Answer | p03746 | Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
:
A_M B_M | import random
N, M = list(map(int, input().split()))
path = [[] for i in range(0, N + 1)]
np = [0 for i in range(0, N + 1)]
np[0] = -1
for i in range(0, M):
a, b = list(map(int, input().split()))
path[a].append(b)
path[b].append(a)
np[a] += 1
np[b] += 2
visited = [False for i in range(0, N + 1)]
visited[0] = True
start = np.index(max(np))
now = start
res = [now]
visited[now] = True
path_org = path[:]
for n in range(0, N):
if len(path[now]) == 0:
break
for i in range(1, N + 1):
if i == now:
continue
if now in path[i]:
path[i].remove(now)
tmp = path[now][random.randint(0, len(path[now]) - 1)]
cnt = 0
while len(path[tmp]) == 0:
tmp = path[now][random.randint(0, len(path[now]) - 1)]
cnt += 1
if cnt == N:
break
now = tmp
res.append(now)
visited[now] = True
res_str = str(res[0])
for i in range(1, len(res)):
res_str = res_str + " " + str(res[i])
print(str(len(res)))
print(res_str)
| Statement
You are given a connected undirected simple graph, which has N vertices and M
edges. The vertices are numbered 1 through N, and the edges are numbered 1
through M. Edge i connects vertices A_i and B_i. Your task is to find a path
that satisfies the following conditions:
* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.
It can be proved that such a path always exists. Also, if there are more than
one solution, any of them will be accepted. | [{"input": "5 6\n 1 3\n 1 4\n 2 3\n 1 5\n 3 5\n 2 4", "output": "4\n 2 3 1 4\n \n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4. There\nare also two vertices directly connected to vertex 4: vertices 1 and 2. Hence,\nthe path 2 \u2192 3 \u2192 1 \u2192 4 satisfies the conditions.\n\n* * *"}, {"input": "7 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 5\n 2 6", "output": "7\n 1 2 3 4 5 6 7"}] |
Find one path that satisfies the conditions, and print it in the following
format. In the first line, print the count of the vertices contained in the
path. In the second line, print a space-separated list of the indices of the
vertices, in order of appearance in the path.
* * * | s929462499 | Runtime Error | p03746 | Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
:
A_M B_M | # -*- coding: utf-8 -*-
from queue import Queue
N, M = [int(n) for n in input().split()]
graph = {n: [] for n in range(1, N + 1)}
for m in range(M):
A, B = [int(n) for n in input().split()]
graph[A].append(B)
graph[B].append(A)
starts_ = sorted(graph.keys(), key=lambda x: len(graph[x]))
starts = iter(starts_)
result_path = []
for start in starts:
q = Queue()
needs_start = graph[start]
q.put([start])
while not q.empty():
path = q.get()
for t in graph[path[-1]]:
if t in path:
continue
if len(set(needs_start + graph[t]) - set(path + [t])) == 0:
result_path = path + [t]
q = Queue()
break
else:
if len(path + t) < N:
q.put(path + [t])
if len(result_path) > 0:
break
print(len(result_path))
result = ""
for r in result_path:
result += " {}".format(r)
print(result[1:])
| Statement
You are given a connected undirected simple graph, which has N vertices and M
edges. The vertices are numbered 1 through N, and the edges are numbered 1
through M. Edge i connects vertices A_i and B_i. Your task is to find a path
that satisfies the following conditions:
* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.
It can be proved that such a path always exists. Also, if there are more than
one solution, any of them will be accepted. | [{"input": "5 6\n 1 3\n 1 4\n 2 3\n 1 5\n 3 5\n 2 4", "output": "4\n 2 3 1 4\n \n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4. There\nare also two vertices directly connected to vertex 4: vertices 1 and 2. Hence,\nthe path 2 \u2192 3 \u2192 1 \u2192 4 satisfies the conditions.\n\n* * *"}, {"input": "7 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 5\n 2 6", "output": "7\n 1 2 3 4 5 6 7"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s826073731 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | N=int(input())
s=0
S=str(N):
for i in S:
s+=i
if S%s==0:
print("Yes")
else:
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s941925516 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | N=int(input())
s=0
S=str(N):
for i in S:
s+=i
if N%s==0:
print("Yes")
else:
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s318737320 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n = int(input())
s = sum(map(int, list(str(n)))
if n % s == 0:
print("Yes")
else:
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s065336952 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n = int(input())
s = n
b = []
while n:
b.append(n%10)
n = n // 10
if s % sum(b) == 0:
print("Yes")
else: | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s288895486 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n = int(input())
i = n
m = 0
while i > 0
m += i % 10
i = i // 10
if n % m != 0:
print('No')
else:
print('Yes') | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s356868811 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | input = input()
sn = list(str(input))
y = 0
for i in sn:
x = int(i)
y = y + x
if input%%y == 0:
print('Yes')
else:
print('No')
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s877419205 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | N = input()
num = int(N)
Nls = list(N)
sum1 = sum([int(i) for in Nls])
if num%sum1 == 0:
print('Yes')
else:
print('No') | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s898153028 | Accepted | p03316 | Input is given from Standard Input in the following format:
N | def examB():
N = I()
SN = 0
for i in str(N):
SN += int(i)
if N % SN == 0:
ans = "Yes"
else:
ans = "No"
print(ans)
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float("inf")
examB()
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s978614861 | Accepted | p03316 | Input is given from Standard Input in the following format:
N | import sys
import os
import math
import string
import collections
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: x * y / math.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")
def f(N):
return sum(map(int, str(N)))
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
q = f(N)
print("No" if N % q else "Yes")
if __name__ == "__main__":
main()
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s155205609 | Accepted | p03316 | Input is given from Standard Input in the following format:
N | ###############################################################################
from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
mod = 1
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * y) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def combination(x, y):
assert x >= y
if y > x // 2:
y = x - y
ret = 1
for i in range(0, y):
j = x - i
i = i + 1
ret = ret * j
ret = ret // i
return ret
def get_divisors(x):
retlist = []
for i in range(1, int(x**0.5) + 3):
if x % i == 0:
retlist.append(i)
retlist.append(x // i)
return retlist
def get_factors(x):
retlist = []
for i in range(2, int(x**0.5) + 3):
while x % i == 0:
retlist.append(i)
x = x // i
retlist.append(x)
return retlist
def make_linklist(xylist):
linklist = {}
for a, b in xylist:
linklist.setdefault(a, [])
linklist.setdefault(b, [])
linklist[a].append(b)
linklist[b].append(a)
return linklist
def calc_longest_distance(linklist, v=1):
distance_list = {}
distance_count = 0
distance = 0
vlist_previous = []
vlist = [v]
nodecount = len(linklist)
while distance_count < nodecount:
vlist_next = []
for v in vlist:
distance_list[v] = distance
distance_count += 1
vlist_next.extend(linklist[v])
distance += 1
vlist_to_del = vlist_previous
vlist_previous = vlist
vlist = list(set(vlist_next) - set(vlist_to_del))
max_distance = -1
max_v = None
for v, distance in distance_list.items():
if distance > max_distance:
max_distance = distance
max_v = v
return (max_distance, max_v)
def calc_tree_diameter(linklist, v=1):
_, u = calc_longest_distance(linklist, v)
distance, _ = calc_longest_distance(linklist, u)
return distance
###############################################################################
def main():
n = intin()
nn = n
s = 0
while nn:
s += nn % 10
nn = nn // 10
if n % s == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s779272119 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | import sys, collections, math
sys.setrecursionlimit(10**7)
def Is():
return [int(x) for x in sys.stdin.readline().split()]
def Ss():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def S():
return input()
n, k = Is()
ls = Is()
_1 = ls.index(1)
if _1 < k - 1:
_1 = k - 1
elif _1 < n - k:
_1 = n - k
print(math.ceil(_1 / (k - 1)) + math.ceil((n - 1 - _1) / (k - 1)))
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s329914560 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | from a import resolve
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 = """12"""
output = """Yes"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """101"""
output = """No"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """999999999"""
output = """Yes"""
self.assertIO(input, output)
if __name__ == "__main__":
unittest.main()
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s537370290 | Wrong Answer | p03316 | Input is given from Standard Input in the following format:
N | import sys
import math
def input():
return sys.stdin.readline().rstrip()
def euc(a, b):
while b != 0:
a, b = b, a % b
return a
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append(i)
if temp != 1:
arr.append(temp)
if arr == []:
arr.append(n)
return arr
def sieve_of_erastosthenes(num):
input_list = [False if i % 2 == 0 else True for i in range(num)]
input_list[0] = input_list[1] = False
input_list[2] = True
sqrt = int(math.sqrt(num)) + 1
for serial in range(3, num, 2):
if input_list[serial] == False:
continue
if serial >= sqrt:
return input_list
for s in range(serial**2, num, serial * 2):
input_list[s] = False
def main():
N = input()
n = int(N)
s = 0
while n:
s += n % 10
n = n // 10
if int(N) % 2 == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s149385099 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | # your code goes here
import copy
N=int(input())
k = copy.copy(N)
a=[]
while k != 0:
a.append(k%10)
k = k//10
if N%sum(a)==0:
print('Yes')
else:
print('No' | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s705669581 | Wrong Answer | p03316 | Input is given from Standard Input in the following format:
N | print(*[["Yes", "No"][(int(s) % sum(int(i) for i in s)) & 1] for s in [input()]])
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s705745102 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n=input()
print("Yes" if int(n)%sum(map(int,n)==0 else "No") | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s568418966 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n = str(input())
sum = 0
for i in n:
sum += int(i)
if n%sum=0:
print('Yes')
else:
print('No') | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s229336495 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | s = input()
sum = 0
i = 0
while i < 9:
sum = sum + s % 10
s = s // 10
i = i + 1
if s % sum = 0:
print("Yes")
else:
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s970608674 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | N = input()
dsum = 0
tmp = N
while tmp > 0:
dsum += tmp % 10
tmp /= 10
if N % dsum != 0:
print ("No")
else:
print ("Yes") | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s442505816 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | A = int(input())
B = input()
m = 0
for i in range(A):
c = set(B[:i])
a = set(B[i:])
l = a & c
m = max(m, len(l))
print(m)
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s827509094 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | s = 123456789
sum = 0
i = 0
while i < 9:
sum = sum + s % 10
s = s // 10
i = i + 1
if s % sum = 0:
print("Yes")
else:
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s078932067 | Accepted | p03316 | Input is given from Standard Input in the following format:
N | def getinputdata():
array_result = []
array_result.append(input().split(" "))
flg = True
try:
while flg:
data = input()
if data != "":
array_result.append(data.split(" "))
flg = True
else:
flg = False
finally:
return array_result
arr_data = getinputdata()
s = arr_data[0][0]
sumdata = sum(list(map(int, list(s))))
print("Yes" if int(s) % sumdata == 0 else "No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s011577298 | Accepted | p03316 | Input is given from Standard Input in the following format:
N | #!/usr/bin/env python3
import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter # itemgetter(1), itemgetter('key')
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate # accumulate(iter[, f])
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy # to copy multi-dimentional matrix without reference
# from fractions import gcd # for Python 3.4 (previous contest @AtCoder)
def main():
mod = 1000000007 # 10^9+7
inf = float("inf") # sys.float_info.max = 1.79...e+308
# inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input():
return sys.stdin.readline().rstrip()
def ii():
return int(input())
def mi():
return map(int, input().split())
def mi_0():
return map(lambda x: int(x) - 1, input().split())
def lmi():
return list(map(int, input().split()))
def lmi_0():
return list(map(lambda x: int(x) - 1, input().split()))
def li():
return list(input())
n = input()
s_n = 0
for char in n:
s_n += int(char)
print("Yes") if int(n) % s_n == 0 else print("No")
if __name__ == "__main__":
main()
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s527784336 | Wrong Answer | p03316 | Input is given from Standard Input in the following format:
N | N = int(input())
ten_count = 0
process_N = 0
process = 0
S = 0
bigger = 0
while True:
if N < 10:
break
if bigger == 0:
bigger = int(N / 10)
elif bigger != 0:
bigger = int(bigger / 10)
ten_count += 1
if bigger < 10:
break
for i in range(ten_count + 1):
if ten_count == 0:
break
if (ten_count - i) >= 1 and process_N == 0:
process = int(N / (10 ** (ten_count - i)))
process_N = N - (process * (10 ** (ten_count - i)))
S += process
if (ten_count - i) >= 1 and process_N != 0:
process = int(process_N / (10 ** (ten_count - i)))
process_N = process_N - (process * (10 ** (ten_count - i)))
S += process
if (ten_count - i) < 1:
S += process_N
break
if ten_count == 0:
S = N
if N % S == 0:
print("Yes")
else:
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s548299949 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n = input()
s = sum(map(int,n))
if int(n)% s == 0:
print("Yes")
else:
print("No | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s964232504 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n=input()
sm=0
fot i in range(10):
sm+=n[i]
res='No'
if n%sm==0:
res='Yes'
print(res) | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s039579783 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | print(*[["Yes", "No"][int(s) % sum(int(i) for i in s)] for s in [input()]])
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s926212292 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n=int(input())
m=sum(list(map(int,str(n)))
if n%m==0:
print('Yes')
exit()
print("No") | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s879979275 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | s=int(input())
d=0
while s!=0:
d+=s%10
s=s//10
print(["YES","NO"][s%d]) | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s423426082 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | print(*["YNeos"[(int(s) % sum(int(i)) for i in s) > 0 :: 2] for s in [input()]])
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s076142218 | Wrong Answer | p03316 | Input is given from Standard Input in the following format:
N | print(*[["Yes", "No"][int(s) % sum(int(i) for i in s) & 1] for s in [input()]])
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s066158812 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | N = input()
ans = 0
for n in N:
ans += int(n)
if N % ans == 0:
print("Yes")
else:s
print("No") | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s128108958 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n, k = map(int, input().split())
print(n // (k - 1))
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s041967715 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n=int(input())
m=sum(map(int,list(str(n)))
if n%m==0:
print('Yes')
exit()
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s149024915 | Wrong Answer | p03316 | Input is given from Standard Input in the following format:
N | print(["No", "Yes"][int(input()) % 3 == 0])
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s064724039 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | s=input()
n=int(s)
ss=0
for i in len(s):
ss+=int(s[i])
if n%ss=0:
print("Yes")
else:
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s960437302 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | N = input()
sum = 0
for n in N:
sum += int(n)
res = int(N) % sum
if res == 0:
print("Yes")
else
print("No") | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s981622286 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n = str(input())
sum = 0
for i in range(len(n)):
sum += int(n[i])
if n%sum=0:
print('Yes')
else:
print('No') | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s252441150 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | S=input()
num=0
for i in range(len(S)):
num+=int(S[i])
if ((int)S%num)==0 :
print("Yes")
else :
print("No") | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s235469166 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | s = input()
a = 0
for i in range(len(s)):
a += s[i]
s = int(s)
if s % a = 0 :
print('Yes')
else :
print('No') | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s721642403 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n = int( input ())
s = sum(list( map ( int ,list ( str ( n ) ) ) )
if n % s == 0:
ans = 'Yes'
else :
ans = 'No'
print(ans) | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s834793042 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n=int(input())
s=list(str(n))
S=0
for i in range(len(s)):
S+=int(s[i])
if n%S==0:
print('Yes')
elsE:
print('No')
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s797702335 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | input_str = input()
sum = 0
for dig in input_str:
sum += int(dig)
if int(input_str) % sum == 0
print('Yes')
else:
print('No') | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s325714403 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | def s(n):
rtn=0
while n>0:
rtn+=n%10
n//10
return rtn
n=int(input())
print("Yes" if n%s(n)==0 else "No") | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s894415360 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | import sys
def solve (N):
s=0
for b in str(N):
s = s + int(b)
if N % s ==0:
return 'Yes'
else:
return 'No'
# 関数 solve は,もちろん,問題に応じて書き換える
def solve(n):
# ここから下は,入力・出力形式が同じであれば,変えなくて良い.
def readQuestion():
line = sys.stdin.readline().rstrip()
return int(line)
def main():
n = readQuestion()
answer = solve(n)
print(answer)
if __name__ == '__main__':
main() | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s480040440 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | n = input())
total = 0
for i in range(len(n)):
total+=int(n[i])
if(total == 0):
print("No")
if(int(n) % total == 0):
print("Yes")
else:
print("No")
| Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s992942934 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | N = list(input())
n = 0
S = 0
for i in range(len(N)):
S = S + int(N[i])
n = (int(N[i])999999999 * (10 ** (len(N) - i - 1))) + n
if n % S == 0:
print('Yes')
else:
print('No') | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
If S(N) divides N, print `Yes`; if it does not, print `No`.
* * * | s437238350 | Runtime Error | p03316 | Input is given from Standard Input in the following format:
N | import sys
def solve(n):
a = 0
for s in str(n):
a += int(s)
if n%a == 0:
return("Yes")
else:
return("No")
def readQuestion():
line = sys.stdin.readline().rstrip()
[str_a] = line.split(' ')
return (int(str_a)
def main():
a = readQuestion()
answer = solve(a)
print(answer)
if __name__ == '__main__':
main() | Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For
example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N. | [{"input": "12", "output": "Yes\n \n\nIn this input, N=12. As S(12) = 1 + 2 = 3, S(N) divides N.\n\n* * *"}, {"input": "101", "output": "No\n \n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\n* * *"}, {"input": "999999999", "output": "Yes"}] |
Print N lines. The i-th line should contain `Yes` if Player i survived the
game, and `No` otherwise.
* * * | s165253301 | Runtime Error | p02911 | Input is given from Standard Input in the following format:
N K Q
A_1
A_2
.
.
.
A_Q | N, K, Q = map(int, input().split())
a = {i: K for i in range(N)}
b = [int(input()) for i in range(Q)]
for i in b:
a[i] = a[i] + 1
for v in a.values():
ans = "Yes"
if v - Q <= 0:
ans = "No"
print(ans)
| Statement
Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who
is in charge of making the scoreboard, is struggling to write the program that
manages the players' scores in a game, which proceeds as follows.
A game is played by N players, numbered 1 to N. At the beginning of a game,
each player has K points.
When a player correctly answers a question, each of the other N-1 players
receives minus one (-1) point. There is no other factor that affects the
players' scores.
At the end of a game, the players with 0 points or lower are eliminated, and
the remaining players survive.
In the last game, the players gave a total of Q correct answers, the i-th of
which was given by Player A_i. For Kizahashi, write a program that determines
whether each of the N players survived this game. | [{"input": "6 3 4\n 3\n 1\n 3\n 2", "output": "No\n No\n Yes\n No\n No\n No\n \n\nIn the beginning, the players' scores are (3, 3, 3, 3, 3, 3).\n\n * Player 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2).\n * Player 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1).\n * Player 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0).\n * Player 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1).\n\nPlayers 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and\nPlayer 3 survives this game.\n\n* * *"}, {"input": "6 5 4\n 3\n 1\n 3\n 2", "output": "Yes\n Yes\n Yes\n Yes\n Yes\n Yes\n \n\n* * *"}, {"input": "10 13 15\n 3\n 1\n 4\n 1\n 5\n 9\n 2\n 6\n 5\n 3\n 5\n 8\n 9\n 7\n 9", "output": "No\n No\n No\n No\n Yes\n No\n No\n No\n Yes\n No"}] |
Print N lines. The i-th line should contain `Yes` if Player i survived the
game, and `No` otherwise.
* * * | s531186616 | Wrong Answer | p02911 | Input is given from Standard Input in the following format:
N K Q
A_1
A_2
.
.
.
A_Q | corr = [] # 正解した人
n, k, q = input().split()
n = int(n) # n人の人がいる
k = int(k) # もともとのポイント
q = int(q) # 正解した数
for i in range(q):
a = input()
corr.append(int(a) - 1)
ptcp = [] # それぞれのポイント
for i in range(n):
ptcp.append(k - q)
for i in range(q):
ptcp[corr[i]] += 1
win = []
for i in range(n):
if ptcp[i] <= 0:
win.append("No")
else:
win.append("Yes")
print(win)
| Statement
Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who
is in charge of making the scoreboard, is struggling to write the program that
manages the players' scores in a game, which proceeds as follows.
A game is played by N players, numbered 1 to N. At the beginning of a game,
each player has K points.
When a player correctly answers a question, each of the other N-1 players
receives minus one (-1) point. There is no other factor that affects the
players' scores.
At the end of a game, the players with 0 points or lower are eliminated, and
the remaining players survive.
In the last game, the players gave a total of Q correct answers, the i-th of
which was given by Player A_i. For Kizahashi, write a program that determines
whether each of the N players survived this game. | [{"input": "6 3 4\n 3\n 1\n 3\n 2", "output": "No\n No\n Yes\n No\n No\n No\n \n\nIn the beginning, the players' scores are (3, 3, 3, 3, 3, 3).\n\n * Player 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2).\n * Player 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1).\n * Player 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0).\n * Player 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1).\n\nPlayers 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and\nPlayer 3 survives this game.\n\n* * *"}, {"input": "6 5 4\n 3\n 1\n 3\n 2", "output": "Yes\n Yes\n Yes\n Yes\n Yes\n Yes\n \n\n* * *"}, {"input": "10 13 15\n 3\n 1\n 4\n 1\n 5\n 9\n 2\n 6\n 5\n 3\n 5\n 8\n 9\n 7\n 9", "output": "No\n No\n No\n No\n Yes\n No\n No\n No\n Yes\n No"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s627519305 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | from collections import Counter
from math import factorial
N,M = map(int,input().split())
# 因数分解
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
# 重複組み合わせ
# フェルマーの小定理nHk≡(n+k−1)!⋅(k!)M−2⋅((n−1)!)M−2(modM)
def comb(n,k,p):
"""power_funcを用いて(nCk) mod p を求める"""
if n<=0 or k<0 or n<k: return 0
if k==0 or n==1: return 1
a=factorial(n+k-1) %p
b=factorial(k) %p
c=factorial(n-1) %p
return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
"""a^b mod p を求める"""
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
a = prime_factorize(M)
c = Counter(a)
l = []
ans = 1
for i in c.values():
# それぞれの余りがわかっている時、その積の余りを求める時は以下
ans *= comb(N,i,10**9+7)
ans %= 10**9+7
print(ans) | Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s799150278 | Accepted | p03253 | Input is given from Standard Input in the following format:
N M | # a module for any prime implication
import random
def primesbelow(N):
# http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
# """ Input N>=6, Returns a list of primes, 2 <= p < N """
correction = N % 6 > 1
N = {0: N, 1: N - 1, 2: N + 4, 3: N + 3, 4: N + 2, 5: N + 1}[N % 6]
sieve = [True] * (N // 3)
sieve[0] = False
for i in range(int(N**0.5) // 3 + 1):
if sieve[i]:
k = (3 * i + 1) | 1
sieve[k * k // 3 :: 2 * k] = [False] * (
(N // 6 - (k * k) // 6 - 1) // k + 1
)
sieve[(k * k + 4 * k - 2 * k * (i % 2)) // 3 :: 2 * k] = [False] * (
(N // 6 - (k * k + 4 * k - 2 * k * (i % 2)) // 6 - 1) // k + 1
)
return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N // 3 - correction) if sieve[i]]
smallprimeset = set(primesbelow(100000))
_smallprimeset = 100000
def isprime(n, precision=7):
# http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time
if n < 1:
raise ValueError("Out of bounds, first argument must be > 0")
elif n <= 3:
return n >= 2
elif n % 2 == 0:
return False
elif n < _smallprimeset:
return n in smallprimeset
d = n - 1
s = 0
while d % 2 == 0:
d //= 2
s += 1
for repeat in range(precision):
a = random.randrange(2, n - 2)
x = pow(a, d, n)
if x == 1 or x == n - 1:
continue
for r in range(s - 1):
x = pow(x, 2, n)
if x == 1:
return False
if x == n - 1:
break
else:
return False
return True
# https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/
def pollard_brent(n):
if n % 2 == 0:
return 2
if n % 3 == 0:
return 3
y, c, m = (
random.randint(1, n - 1),
random.randint(1, n - 1),
random.randint(1, n - 1),
)
g, r, q = 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = (pow(y, 2, n) + c) % n
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = (pow(y, 2, n) + c) % n
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r *= 2
if g == n:
while True:
ys = (pow(ys, 2, n) + c) % n
g = gcd(abs(x - ys), n)
if g > 1:
break
return g
smallprimes = primesbelow(
1000
) # might seem low, but 1000*1000 = 1000000, so this will fully factor every composite < 1000000
def primefactors(n, sort=False):
factors = []
for checker in smallprimes:
while n % checker == 0:
factors.append(checker)
n //= checker
if checker > n:
break
if n < 2:
return factors
while n > 1:
if isprime(n):
factors.append(n)
break
factor = pollard_brent(
n
) # trial division did not fully factor, switch to pollard-brent
factors.extend(
primefactors(factor)
) # recurse to factor the not necessarily prime factor returned by pollard-brent
n //= factor
if sort:
factors.sort()
return factors
def factorization(n):
factors = {}
for p1 in primefactors(n):
try:
factors[p1] += 1
except KeyError:
factors[p1] = 1
return factors
def gcd(a, b):
if a == b:
return a
while b > 0:
a, b = b, a % b
return a
N = 1000000007
def c(n, r):
a = 1
b = 1
for i in range(n, n - r, -1):
a = (a * i) % N
for i in range(1, r + 1):
b = (b * i) % N
binv = pow(b, N - 2, N)
return (a * binv) % N
n, m = map(int, input().strip().split(" "))
d = factorization(m)
ans = 1
for i in d.values():
ans = (ans * c(i + n - 1, n - 1)) % N
print(ans)
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s700554829 | Wrong Answer | p03253 | Input is given from Standard Input in the following format:
N M | import math
n, m = map(int, input().split())
dict1 = {}
def yakusuu(m):
if int(m) != 1:
"""
if m % 2 == 0:
if 2 not in dict1.keys():
dict1[2] = 0
dict1[2] += 1
yakusuu(m/2)
elif m % 3 == 0:
if 3 not in dict1.keys():
dict1[3] = 0
dict1[3] += 1
yakusuu(m/3)
elif m % 5 == 0:
if 5 not in dict1.keys():
dict1[5] = 0
dict1[5] += 1
yakusuu(m/5)
else:
"""
flag = True
for i in range(2, int(math.sqrt(m) + 1)):
if m % i == 0:
if i not in dict1.keys():
dict1[i] = 0
dict1[i] += 1
yakusuu(m / i)
flag = False
break
if flag == True:
m = int(m)
if m not in dict1.keys():
dict1[m] = 0
dict1[m] += 1
yakusuu(m)
print(dict1)
count = 1
for i in dict1.values():
print(i)
a = int(math.factorial(n + i - 1) / (math.factorial(n - 1) * math.factorial(i)))
count *= a
print(a)
print(count % (10**9 + 7))
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s393428621 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | def main()
N, M = map(int, input().split())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == [] and n != 1:
arr.append([n, 1])
return arr
mod = 10**9 + 7
def cmb(n, r, mod):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N+100 + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod//i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
primes = factorization(M)
# 何箇所に分けるか(cnt以下),その中でどう分けるか(しきりをどこにおくか(振り分けられないものが出ると選べれないのとおなじになるので、cnt - 選んだ数))
ans = 1
for p, cnt in primes:
tmp = cmb(N+cnt-1, N-1, mod)
ans *= tmp
ans %= mod
print(ans)
main()
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s419901136 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | def main():
N, M = map(int, input().split())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == [] and n != 1:
arr.append([n, 1])
return arr
mod = 10**9 + 7
def cmb(n, r, mod):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N+100 + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod//i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
primes = factorization(M)
# 何箇所に分けるか(cnt以下),その中でどう分けるか(しきりをどこにおくか(振り分けられないものが出ると選べれないのとおなじになるので、cnt - 選んだ数))
ans = 1
for p, cnt in primes:
tmp = cmb(N+cnt-1, N-1, mod)
ans *= tmp
ans %= mod
print(ans)
main()
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s099477487 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | import math
n, m = map(int, input().split())
mod = 10 ** 9 + 7
b = []
c = int(math.sqrt(m))
for i in range(2, c+2):
if m % i == 0:
count = 0
while m % i == 0:
count += 1
m = m // i
b.append(count)
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n + max(b)+3):
fac.append(fac[i-1] * i % mod)
inv.append(mod - inv[mod%i] * (mod//i) % mod)
finv.append(finv[i-1] * inv[i] % mod)
def nck(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n-k] % mod) % mod
ans = 1
for i in b:
ans = (ans * nck(n-1+i, n-1)) % mod
print(ans) | Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s744742263 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | import sys
n,m=map(int,input().split())
MOD = 10**9+7
ans=1
def inv_mod(a, p=MOD):
def inv_mod_sub(a, p):
if a == 1:
return 1, 0
else:
d, r = p//a, p%a
x, y = inv_mod_sub(r, a)
return y-d*x, x
if p < 0: p = -p
a %= p
return inv_mod_sub(a,p)[0] % p
def comb_mod(n, k):
if k < 0 or k > n:
return 0
else:
return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
pf={}
for i in range(2,int(m**0.5)+1):
while m%i==0:
pf[i]=pf.get(i,0)+1
m//=i
if m>1:pf[m]=1
if m==1
print(1)
sys.exit()
Max=max(list(pf.values()))
f_mod=[1]*(Max+n+1)
f_mod_inverse=[1]*(Max+n+1)
for i in range(1,Max+n+1):
f_mod[i]=(f_mod[i-1]*i)%MOD
f_mod_inverse[i]=(f_mod_inverse[i-1]*inv_mod(i)) % MOD
for i in pf.values():
ans*=comb_mod(i+n-1,n-1)
print(ans%MOD)
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s850832652 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | import math
N,M = map(int,input().split())
D = {}
m = M
for i in range(2, int M):
while m % i == 0:
D[i] = D.get(i,0)+1
m = m//i
d = []
for v in D.values():
d.append(v)
tmp = [0] * len(d)
for i in range(len(d)):
tmp[i] = (math.factorial(N-1+d[i]) // (math.factorial(N-1)*math.factorial(d[i])))%(10**9 + 7)
ans = 1
for i in range(len(tmp)):
ans = ans*tmp[i]%(10**9 +7)
print(ans)
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s974712640 | Wrong Answer | p03253 | Input is given from Standard Input in the following format:
N M | print(1)
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s383191197 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | import collections
def factor(m):
num=m
s=[]
i=2
while i*i<=m:
if num%i:
i+=1
else:
s.append(i)
num//=i
if num!=1:
s.append(num)
return s
def conb(n,r):
r=min(r,n-r)
if r==0:
return 1
else:
N,R=n,r
for i in range(1,r):
N*=n-i
R*=r-i
return N//R
n,m=map(int,input().split())
a=factor(m)
b=collections.Counter(a)
mod=10**9+7
ans=1
for i in b.values():
ans=(ans*conb(n+i-1,i))%mod
print(ans) | Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s955819240 | Accepted | p03253 | Input is given from Standard Input in the following format:
N M | if __name__ == "__main__":
# from time import perf_counter
mod = 10**9 + 7
n, m = map(int, input().split())
pow_ = [0] * 31
# perf = perf_counter()
x = m
divisor = 2
power = 0
while x % divisor == 0:
x //= divisor
power += 1
if power > 0:
pow_[power] += 1
divisor = 3
while x > 1 and divisor**2 <= m:
power = 0
while x % divisor == 0:
x //= divisor
power += 1
if power > 0:
pow_[power] += 1
divisor += 2
if x > 1:
pow_[1] += 1
# print('prime_factorization', perf_counter() - perf)
# print(pow_)
# def prime_factorization(n):
# i = 2
# res = []
# while i * i <= n:
# cnt = 0
# while n % i == 0:
# n /= i
# cnt += 1
# if cnt > 0:
# res.append(cnt)
# i += 1
# if n > 1:
# res.append(1)
# return res
# perf = perf_counter()
# res = prime_factorization(m)
# print('prime_factorization', perf_counter() - perf)
# print(res)
# perf = perf_counter()
ans = 1
t = 1
d = 1
for power, cnt in enumerate(pow_[1:], 1):
# 1 <= power <= 30
t = t * (n - 1 + power) % mod
d = d * pow(power, mod - 2, mod) % mod
# print(power, cnt, ans, t, d)
ans = ans * pow(t * d % mod, cnt, mod) % mod
# for _ in range(cnt):
# ans = ans * t * d % mod
print(ans)
# print('calculation', perf_counter() - perf)
# TLEの原因は、巨大素数の判定
# divisor ** 2 <= m
# で探索を打ち切って、m>1なら巨大な素数
# 冪数をリストにappendする方式の方が数ms速いが、
# 冪数indexに該当素数数を加算していくと
# 最後の計算で、同じ冪数を一括計算できるから、大差ないか
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s083616200 | Accepted | p03253 | Input is given from Standard Input in the following format:
N M | import math
class Solution:
def solve(self, N: int, M: int) -> int:
mod = 10**9 + 7
INT_MAX = 10**9
# calculate {m+n}C{n}
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x - (b // a) * y, y
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception("modular inverse does not exist")
else:
return x % m
def combination(n: int, r: int, mod: int = 10**9 + 7) -> int:
r = min(r, n - r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i + 1, mod) % mod
return res
# solve
m = M
answer = 1
factors = {}
for i in range(2, int(math.sqrt(M)) + 1):
factor = 0
while m % i == 0:
m //= i
factor += 1
if factor > 0:
answer *= combination(N + factor - 1, N - 1, mod=mod)
answer %= mod
if m > 1:
answer *= N
answer %= mod
return answer
if __name__ == "__main__":
# standard input
N, M = map(int, input().split())
# solve
solution = Solution()
print(solution.solve(N, M))
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s267256572 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;
vector<pair<long long, long long> > prime_factorize(long long n) {
vector<pair<long long, long long> > res;
for (long long p = 2; p * p <= n; ++p) {
if (n % p != 0) continue;
int num = 0;
while (n % p == 0) { ++num; n /= p; }
res.push_back(make_pair(p, num));
}
if (n != 1) res.push_back(make_pair(n, 1));
return res;
}
const int MAX = 210000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for(int i = 2; i < MAX; i++){
fac[i] = fac[i-1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
finv[i] = finv[i-1] * inv[i] % MOD;
}
}
long long COM(int n, int k){
if(n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(){
ll N,M;
cin >> N >> M;
COMinit();
auto vec = prime_factorize(M);
ll ans = 1;
for(auto v: vec){
int num = v.second;
ll ret = COM(num+N-1,N-1);
ans = ans*ret % MOD;
}
cout << ans << endl;
return 0;
}
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s237528793 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPI(i,f,n) for(int i=(f);i<(n);++i)
using namespace std;
typedef long long ll;
const int MAX = 210000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector< ll > frac;
int main() {
// 前処理
COMinit();
ll N,M;
cin >> N >> M;
// Mの素因数分解
ll mm = M;
for (ll i=2; i*i<=mm; ++i ) {
ll cnt = 0;
while ( mm % i == 0 ) {
cnt++;
mm /= i;
}
if (cnt != 0) frac.emplace_back( cnt );
}
if (mm !=1 ) frac.emplace_back( 1 );
ll ans = 1;
for ( auto x : frac ) {
ans = (ans * COM( x + N-1, x )) % MOD;
}
cout << (ans%MOD) << endl;
}
| Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print the number of the sequences consisting of positive integers that satisfy
the condition, modulo 10^9 + 7.
* * * | s747835001 | Runtime Error | p03253 | Input is given from Standard Input in the following format:
N M | # encoding: utf-8
import math
N, M = map(int, input().split())
def distribute(pos, full, tmp):
return memo[tmp][pos]
# define search range
p_max = int(M / 2) # M is prime if M has a factor p (> p_max)
ip_up = int(math.log2(p_max))
#### O(MlogM) below (if M has a very large prime factor)
M_tmp = M
ips = []
for p in range(2, p_max + 1):
if M_tmp % p > 0: continue
# how many times M_tmp can be divided
p_tmp = p
for i_p in range(ip_up + 1):
if M_tmp % p_tmp > 0: break
p_tmp = p_tmp * p
# calculate later
ips.append(i_p)
# next
M_tmp = M_tmp // (p_tmp // p)
if M_tmp == 1: break
#### O(Mlog M) above
#### O(N) below
# create memo
## init
if len(ips) > 0: ip_max = max(ips)
else: ip_max = 0
memo = [[None] * N for i in range(ip_max + 1)] # max ip
for j in range(N): memo[0][j] = 1
for i in range(1, ip_max + 1): memo[i][N - 1] = 1
## fill
for i in range(1, ip_max + 1):
sum_tmp = 0
vals = list(memo[i - 1])[::-1]
p_memo = memo[i]
for j, val in enumerate(vals):
sum_tmp += val
p_memo[N - 1 - j] = sum_tmp
#### O(N) above
# calculate ans
ans = 1
for i_p in ips: ans = (ans * distribute(0, i_p, i_p)) % (10 ** 9 + 7)
if ip_max = 0: print(N)
else: print(ans) | Statement
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1
\times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some
i such that a_i' \neq a_i''. | [{"input": "2 6", "output": "4\n \n\nFour sequences satisfy the condition: \\\\{a_1, a_2\\\\} = \\\\{1, 6\\\\}, \\\\{2, 3\\\\},\n\\\\{3, 2\\\\} and \\\\{6, 1\\\\}.\n\n* * *"}, {"input": "3 12", "output": "18\n \n\n* * *"}, {"input": "100000 1000000000", "output": "957870001"}] |
Print 1 $B$ is greater than $A$, otherwise 0. | s895890014 | Accepted | p02442 | The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$m$
$b_0 \; b_1, ..., \; b_{m-1}$
The number of elements in $A$ and its elements $a_i$ are given in the first
and second lines respectively. The number of elements in $B$ and its elements
$b_i$ are given in the third and fourth lines respectively. All input are
given in integers. | input()
a = input()
input()
print(+(a < input()))
| Lexicographical Comparison
Compare given two sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0,
b_1, ..., b_{m-1}$ lexicographically. | [{"input": "3\n 1 2 3\n 2\n 2 4", "output": "1"}, {"input": "4\n 5 4 7 0\n 5\n 1 2 3 4 5", "output": "0"}, {"input": "3\n 1 1 2\n 4\n 1 1 2 2", "output": "1"}] |
Print 1 $B$ is greater than $A$, otherwise 0. | s144369078 | Accepted | p02442 | The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$m$
$b_0 \; b_1, ..., \; b_{m-1}$
The number of elements in $A$ and its elements $a_i$ are given in the first
and second lines respectively. The number of elements in $B$ and its elements
$b_i$ are given in the third and fourth lines respectively. All input are
given in integers. | n = int(input())
a = list(input().split())
m = int(input())
b = list(input().split())
# for i in range(max(len(a),len(b))):
# if a[i] == b[i]:
# if i+1 >= len(a) and len(b) > i+1 :
# print('1')
# break
# elif i+1 >= len(b):
# print('0')
# break
# pass
# elif a[i] < b[i]:
# print('1')
# break
# else:
# print('0')
# break
print(+(a < b))
| Lexicographical Comparison
Compare given two sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0,
b_1, ..., b_{m-1}$ lexicographically. | [{"input": "3\n 1 2 3\n 2\n 2 4", "output": "1"}, {"input": "4\n 5 4 7 0\n 5\n 1 2 3 4 5", "output": "0"}, {"input": "3\n 1 1 2\n 4\n 1 1 2 2", "output": "1"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s310472023 | Wrong Answer | p03480 | Input is given from Standard Input in the following format:
S | S = input()
pos_0 = [0]
pos_1 = [0]
for i, s in enumerate(S):
if s == "0":
pos_0.append(i)
else:
pos_1.append(i)
pos_0.append(len(S) - 1)
pos_1.append(len(S) - 1)
interval_0 = [pos_0[i + 1] - pos_0[i] for i in range(len(pos_0) - 1)]
interval_1 = [pos_1[i + 1] - pos_1[i] for i in range(len(pos_1) - 1)]
print(max(max(interval_0), max(interval_1)))
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s166798986 | Accepted | p03480 | Input is given from Standard Input in the following format:
S | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2, N + 1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X // n:
return base_10_to_n_without_0(X // n, n) + [X % n]
return [X % n]
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
S = S()
N = len(S)
if N == 1:
print(1)
exit()
if N % 2:
c = S[N // 2]
l, r = N // 2 - 1, N // 2 + 1
ans = N // 2 + 1
while l >= 0 and c == S[l] == S[r]:
ans += 1
l -= 1
r += 1
print(ans)
else:
ans = N // 2
l, r = N // 2 - 1, N // 2
while l >= 0 and S[l] == S[r] == S[l + 1]:
ans += 1
l -= 1
r += 1
print(ans)
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s501684968 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | x, y = map(int, input().split())
print(len(bin(y // x)) - 2)
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s677655317 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | S=input()
l=len(S)
if l%2==1:
m=S[l//2]
c=1
for i in range l//2:
if S[l//2-i-1]==m and S[l//2+i+1]==m:
c+=2
else:
break
ans=c+(l-c)//2
else:
m1=S[l//2-1]
m2=S[l//2]
c=0
if m1==m2:
c=2
for i in range l//2-1:
if S[l//2-i-2]==m1 and S[l//2+i+1]==m1:
c+=2
else:
break
ans=c+(l-c)//2
print(ans) | Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s757985525 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | def main():
s = input()
max_k = 0
#バラバラ
slist = []
for i in range(len(s)):
slist.append(s[i:i+1])
for k in range(len(slist)):
tmplist = slist
judge = testmethod(tmplist, k)
if judge == 0:
max_k = k
print(max_k)
def testmethod(list, k):
for i in range(0, len(list) - k):
target = list[i:i+k]
for t2 in range(len(target)):
if target[t2] == '0':
target[t2] = '1'
else:
target[t2] = '0'
list[i:i+k] = target
for t in range(len(list)):
if list[t] == '1'
return 1
return 0
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s122863752 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | def main():
s = input()
max_k = 0
#バラバラ
slist = []
for i in range(len(s)):
slist.append(s[i:i+1])
for k in range(len(slist)):
tmplist = slist
judge = testmethod(tmplist, k)
if judge == 0:
max_k = k
print(max_k)
def testmethod(list, k):
for i in range(0, len(list) - k):
target = list[i:i+k]
for t2 in range(len(target)):
if target[t2] == '0':
target[t2] = '1'
else:
target[t2] = '0'
list[i:i+k] = target
for t in range(len(list)):
if list[t:t+1] == '1'
return 1
return 0
if __name__ == "__main__":
main()
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s302638316 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | import pandas as pd
def main():
s = input()
max_k = 0
#バラバラ
slist = []
for i in range(len(s)):
slist.append(s[i:i+1])
for k in range(len(slist)):
judge = testmethod(slist, k)
if judge == 0:
max_k = k
print(max_k)
def testmethod(list, k):
for i in range(0, len(list) - k):
target = list[i:i+k]
for t2 in range(len(target)):
if target[t2] == '0':
target[t2] = '1'
else:
target[t2] = '0'
list[i:i+k] = target
for t in range(len(list)):
if list[t] == '1'
return 1
return 0
if __name__ == "__main__":
main()
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s122138416 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S |
s = input()
max_k = 0
#バラバラ
slist = []
for i in range(len(s)):
slist.append(s[i:i+1])
for k in range(len(slist)):
judge = testmethod(slist, k)
if judge == 0:
max_k = k
print(max_k)
def testmethod(list, k):
for i in range(0, len(list) - k):
target = list[i:i+k]
for t2 in range(len(target)):
if target[t2] == '0':
target[t2] = '1'
else:
target[t2] = '0'
list[i:i+k] = target
for t in range(len(list)):
if list[t] == '1'
return 1
return 0
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s212181172 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | def main():
s = input()
max_k = 0
#バラバラ
slist = []
for i in range(len(s)):
slist.append(s[i:i+1])
for k in range(len(slist)):
judge = testmethod(slist, k)
if judge == 0:
max_k = k
print(max_k)
def testmethod(list, k):
for i in range(0, len(list) - k):
target = list[i:i+k]
for t2 in range(len(target)):
if target[t2] == '0':
target[t2] = '1'
else:
target[t2] = '0'
list[i:i+k] = target
for t in range(len(list)):
if list[t] == '1'
return 1
return 0
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s751721280 | Wrong Answer | p03480 | Input is given from Standard Input in the following format:
S | N = input()
a = N.count("0")
b = N.count("1")
print(max(a, b))
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s642453294 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | = input()
t = s[len(s)//2]
j = len(s)//2
i = len(s)-j-1
ans = j
while i >= 0:
if s[i] != t or s[j] != t:
break
ans += 1
i -= 1
j += 1
print(ans) | Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s978669669 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | s = input()
if len(s) == 1:
tmp = []
for i in range(len(s)-1):
if s[i] != s[i+1]:
tmp.append(max(i+1,len(s)-(i+1)))
if len(tmp) == 0:
#元から全部同じ
print(len(s))
else:
print(min(tmp)) | Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s899844456 | Wrong Answer | p03480 | Input is given from Standard Input in the following format:
S | a = list(input())
print(a.count("0"))
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s932434829 | Runtime Error | p03480 | Input is given from Standard Input in the following format:
S | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
bool k_flip(string s, int k)
{
int n = s.length();
int status = 0;
deque<int> endindex;
rep(i, n - k + 1)
{
if (endindex.size() % 2 == 0 && s[i] == '1')
{
s[i] = '0';
endindex.push_back(i + k - 1);
}
else if (endindex.size() % 2 == 1 && s[i] == '1')
{
s[i] = '0';
}
else if (endindex.size() % 2 == 1 && s[i] == '0')
{
endindex.push_back(i + k - 1);
}
if (endindex.front() == i)
endindex.pop_front();
}
rep2(i, n - k + 1, n)
{
if (endindex.size() % 2 == 1)
{
if (s[i] == '0')
s[i] = '1';
else
s[i] = '0';
}
if (endindex.front() == i)
endindex.pop_front();
}
rep(i, k)
if (s[i] == '1')
status++;
if (!status)
return 1;
else
return 0;
}
int main()
{
#ifdef DEBUG
cout << "DEBUG MODE" << endl;
ifstream in("input.txt"); //for debug
cin.rdbuf(in.rdbuf()); //for debug
#endif
string s;
cin >> s;
int ok, ng, mid;
if (k_flip(s, s.length()))
cout << s.length() << endl;
else
{
ok = 0, ng = s.length();
while (ng - ok> 1)
{
mid = (ok + ng) / 2;
if (k_flip(s, mid))
ok = mid;
else
ng = mid;
}
cout << ok << endl;
}
return 0;
} | Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s435509779 | Accepted | p03480 | Input is given from Standard Input in the following format:
S | S = input()
if len(S) == 1:
print(1)
quit()
if len(S) % 2 == 0:
A = S[: len(S) // 2]
B = S[len(S) // 2 :]
A = A[::-1]
s = A[0]
ans = len(S) // 2
if len(S) % 2 == 1:
A = S[: len(S) // 2]
B = S[len(S) // 2 + 1 :]
A = A[::-1]
s = S[len(S) // 2]
ans = len(S) // 2 + 1
for i in range(len(A)):
if A[i] != s or B[i] != s:
print(ans + i)
quit()
print(len(S))
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s106372939 | Wrong Answer | p03480 | Input is given from Standard Input in the following format:
S | A = list(input())
L = len(A)
num = L
while True:
pre = A[0]
end = True
for i in range(1, L):
if A[i] != pre:
if i * 2 < L:
num = L - i
else:
num = i
for j in range(i):
A[j] = "0" if A[j] == "1" else "1"
end = False
break
if end:
break
print(num)
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s615619184 | Accepted | p03480 | Input is given from Standard Input in the following format:
S | A = list(map(int, list(input())))
L = len(A)
num = L
pre = A[0]
end = True
for i in range(1, L):
if A[i] != pre:
if i * 2 < L and L - i < num:
num = L - i
elif i < num:
num = i
pre = A[i]
print(num)
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Print the maximum integer K such that we can turn all the characters of S into
`0` by repeating the operation some number of times.
* * * | s159236173 | Accepted | p03480 | Input is given from Standard Input in the following format:
S | S = [0] + list(map(int, list(input())))
N = len(S) - 1
def change(s, c):
if c == 0:
return s
else:
return 1 - s
def check(k):
count = [0] * (N + 1)
T = S.copy()
for i in range(1, N + 1):
c = count[i - 1]
s = change(S[i], c)
if i < N - k + 2:
T[i] = 0
if s == 1:
count[i] = (c + 1) % 2
else:
count[i] = c
else:
T[i] = s
count[i] = c
n = 0
for t in T[1:]:
if t == 1:
break
n += 1
return n >= k
left = 1 # True
right = N
while left + 1 < right:
mid = (left + right) // 2
if check(mid):
left = mid
else:
right = mid
if right == N and check(N):
print(N)
else:
print(left)
| Statement
You are given a string S consisting of `0` and `1`. Find the maximum integer K
not greater than |S| such that we can turn all the characters of S into `0` by
repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`. | [{"input": "010", "output": "2\n \n\nWe can turn all the characters of S into `0` by the following operations:\n\n * Perform the operation on the segment S[1,3] with length 3. S is now `101`.\n * Perform the operation on the segment S[1,2] with length 2. S is now `011`.\n * Perform the operation on the segment S[2,3] with length 2. S is now `000`.\n\n* * *"}, {"input": "100000000", "output": "8\n \n\n* * *"}, {"input": "00001111", "output": "4"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.