output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s534277040
Accepted
p02712
Input is given from Standard Input in the following format: N
print(sum(i for i in range(1, int(input()) + 1) if i % 3 and i % 5))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s854543584
Accepted
p02712
Input is given from Standard Input in the following format: N
score = int(input()) souwa = int((score * (score + 1)) / 2) kou3 = score // 3 souwa3 = int((kou3 * (kou3 + 1) * 3) / 2) kou5 = score // 5 souwa5 = int((kou5 * (kou5 + 1) * 5) / 2) kou15 = score // 15 souwa15 = int((kou15 * (kou15 + 1) * 15) / 2) answer = souwa - souwa3 - souwa5 + souwa15 print(answer)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s246787557
Runtime Error
p02712
Input is given from Standard Input in the following format: N
from collections import defaultdict def solve(rr, gg, bb): d1, d2 = defaultdict(list), defaultdict(list) for i in range(len(gg)): ii = gg[i] for j in range(len(rr)): jj = rr[j] if ii > jj: d1[ii].append(ii - jj) for i in range(len(gg)): ii = gg[i] for j in range(len(bb)): jj = bb[j] if ii < jj: d2[ii].append(jj - ii) s = 0 # print(d1,d2) for x in d1: for y in d1[x]: for z in d2[x]: if y != z: s += 1 return s n = int(input()) s = input() l = list(s) rr, gg, bb = [], [], [] for i in range(len(s)): ii = s[i] if ii == "R": rr.append(i) if ii == "G": gg.append(i) if ii == "B": bb.append(i) # print(rr,gg,bb) print( solve(rr, gg, bb) + solve(rr, bb, gg) + solve(bb, rr, gg) + solve(bb, gg, rr) + solve(gg, rr, bb) + solve(gg, bb, rr) )
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s818058610
Accepted
p02712
Input is given from Standard Input in the following format: N
n = int(input()) f = sum([3 * (i + 1) for i in range(n // 3)]) b = sum([5 * (i + 1) for i in range(n // 5)]) fb = sum([15 * (i + 1) for i in range(n // 15)]) print(n * (n + 1) // 2 - f - b + fb)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s288545692
Accepted
p02712
Input is given from Standard Input in the following format: N
N = int(input()) val = ( N * (N + 1) - 3 * (N // 3) * ((N // 3) + 1) - 5 * (N // 5) * ((N // 5) + 1) + 15 * (N // 15) * ((N // 15) + 1) ) // 2 print(int(val))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s528620862
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
a = int(input("a")) b = sum(range(3, a + 1, 3)) c = sum(range(5, a + 1, 5)) d = sum(range(15, a + 1, 15)) e = a * (a + 1) / 2 print(int(e - b - c + d))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s935248429
Accepted
p02712
Input is given from Standard Input in the following format: N
N = int(input()) if 1 <= N <= 10**6: a = N * (N + 1) / 2 b = N // 15 c_3 = 3 * 5 * b * (5 * b + 1) / 2 c_5 = 5 * 3 * b * (3 * b + 1) / 2 c_15 = 15 * b * (b + 1) / 2 a = a - c_3 - c_5 + c_15 i = 15 * b + 1 if N % 15 == 0: a = int(a) print(a) else: for i in range(15 * b + 1, N + 1): if (i % 5 == 0) or (i % 3 == 0): a = a - i i += 1 a = int(a) print(a)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s757018648
Accepted
p02712
Input is given from Standard Input in the following format: N
K = int(input()) x = (K + 1) * K // 2 num_devisible_three = (3 + 3 * (K // 3)) * (K // 3) // 2 num_devisible_five = (5 + 5 * (K // 5)) * (K // 5) // 2 num_devisible_fifteen = (15 + 15 * (K // 15)) * (K // 15) // 2 print(x - num_devisible_three - num_devisible_five + num_devisible_fifteen)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s968412920
Accepted
p02712
Input is given from Standard Input in the following format: N
n = int(input()) k = n % 15 l = n // 15 m = l * l * 60 if k == 1: print(m + 1 + 15 * l) if k == 2 or k == 3: print(m + 3 + 30 * l) if k == 4 or k == 5 or k == 6: print(m + 7 + 45 * l) if k == 7: print(m + 14 + 60 * l) if k == 8 or k == 9 or k == 10: print(m + 22 + 75 * l) if k == 11 or k == 12: print(m + 33 + 90 * l) if k == 13: print(m + 46 + 105 * l) if k == 14: print(m + 60 + 120 * l) if k == 0: print(m)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s574067893
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
N = int(input()) loop = N // 15 amari = N % 15 if loop == 0: oomaka = 0 tuide = 1 else: oomaka = 60 * loop + 135 * (loop - 1) tuide = 15 * loop if amari == 0: output = oomaka print(output) if amari == 1: output = oomaka + tuide + 1 print(output) if amari == 2 or amari == 3: output = oomaka + tuide * 2 + 3 print(output) if amari == 4 or amari == 5 or amari == 6: output = oomaka + 7 + tuide * 3 print(output) if amari == 7: output = oomaka + 14 + tuide * 4 print(output) if amari == 8 or amari == 9: output = oomaka + 22 + tuide * 5 print(output) if amari == 11 or amari == 12: output = oomaka + 33 + tuide * 6 print(output) if amari == 13: output = oomaka + 46 + tuide * 7 print(output) if amari == 14: output = oomaka + 60 + tuide * 8 print(output)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s818624131
Accepted
p02712
Input is given from Standard Input in the following format: N
n = int(input()) x = n // 3 y = n // 5 z = n // 15 ans = int(n * (n + 1) - 3 * x * (x + 1) - 5 * y * (y + 1) + 15 * z * (z + 1)) // 2 print(ans)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s140429058
Accepted
p02712
Input is given from Standard Input in the following format: N
print(sum(n for n in range(int(input()) + 1) if n % 3 and n % 5))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s170875465
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
n = int(input()) ret = n * (n + 1) // 2 ret -= 3 * (1 + n // 3) // 2 ret -= 5 * (1 + n // 5) // 2 ret += 15 * (1 + n // 15) // 2 print(ret)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s620646232
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
n = int(input()) list = [i for i in range(1, n) if i % 3 != 0] list_2 = [i for i in list if i % 5 != 0] print(sum(list_2))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s187782366
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
n = int(input()) l = list(range(1, n)) l_ans = [n for n in l if (n % 5 != 0) and (n % 3 != 0)] print(sum(l_ans))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s835781526
Accepted
p02712
Input is given from Standard Input in the following format: N
N = int(input()) FB = [i for i in range(1, N + 1)] f = [i for i in range(3, N + 1, 3)] b = [i for i in range(5, N + 1, 5)] fb = [i for i in range(15, N + 1, 15)] l = sum(FB) m = sum(f) n = sum(b) o = sum(fb) print(l - m - n + o)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s771858632
Accepted
p02712
Input is given from Standard Input in the following format: N
print(sum([i for i in range(1, int(input()) + 1) if i % 3 != 0 and i % 5 != 0]))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s105223909
Accepted
p02712
Input is given from Standard Input in the following format: N
print(sum([i if i % 3 != 0 and i % 5 != 0 else 0 for i in range(1, int(input()) + 1)]))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s743500821
Accepted
p02712
Input is given from Standard Input in the following format: N
n = list(range(1, int(input()) + 1)) print(sum([i for i in n if i % 3 != 0 and i % 5 != 0]))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s341864270
Accepted
p02712
Input is given from Standard Input in the following format: N
print( sum( [ i for i in range(1, int(input()) + 1) if not ((i % 3 == 0 and i % 5 == 0) or i % 3 == 0 or i % 5 == 0) ] ) )
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s871736282
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
i = int(input()) num = 0 num = [i for i in range(i) if (i % 3 != 0 and i % 5 != 0)] print(sum(num))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s218435998
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
print(sum([i for i in range(int(input())) if i % 5 != 0 and i % 3 != 0]))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s775682836
Accepted
p02712
Input is given from Standard Input in the following format: N
N = int(input()) sum0 = 0 p1 = N // 2 p2 = N % 2 if p2 == 1: sum0 = (N + 1) * p1 + (p1 + 1) else: sum0 = (N + 1) * p1 Fizz = N // 3 Buzz = N // 5 FizzBuzz = N // 15 sum1 = 0 sum2 = 0 sum3 = 0 if Fizz != 0: for i in range(Fizz): sum1 += 3 * (i + 1) if Buzz != 0: for j in range(Buzz): sum2 += 5 * (j + 1) if FizzBuzz != 0: for k in range(FizzBuzz): sum3 += 15 * (k + 1) ans = sum0 + sum3 - (sum1 + sum2) print(ans)
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s264264173
Accepted
p02712
Input is given from Standard Input in the following format: N
print(sum([i for i in range(1, int(input()) + 1) if i % 15 and i % 5 and i % 3]))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s695929168
Accepted
p02712
Input is given from Standard Input in the following format: N
print(sum([i for i in range(1, 1 + int(input())) if i % 3 * i % 5]))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s097308886
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
print(sum([n for n in range(1, int(input())) if (n % 3 != 0) and (n % 5 != 0)]))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s123811784
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
print(sum([i for i in range(int(input())) if (i % 3 != 0 and i % 5 != 0)]))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the sum of all numbers among the first N terms of the FizzBuzz sequence. * * *
s048408081
Wrong Answer
p02712
Input is given from Standard Input in the following format: N
print(sum(i for i in range(int(input())) if (i % 3 != 0) and (i % 5 != 0)))
Statement Let us define the **FizzBuzz sequence** a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
[{"input": "15", "output": "60\n \n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\n* * *"}, {"input": "1000000", "output": "266666333332\n \n\nWatch out for overflow."}]
Print the number of ways modulo $10^9+7$ in a line.
s555794505
Accepted
p02342
$n$ $k$ The first line will contain two integers $n$ and $k$.
N, K = map(int, input().split()) MOD = 10**9 + 7 D = [[0] * (K + 1) for i in range(N + 1)] for i in range(1, N + 1): D[i][1] = 1 for i in range(1, min(N, K) + 1): D[i][i] = 1 for n in range(1, N + 1): for k in range(2, min(n - 1, K) + 1): D[n][k] = (D[n - k][k] + D[n - 1][k - 1]) % MOD print(D[N][K] % MOD)
You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: * Each ball is **not** distinguished from the other. * Each box is **not** distinguished from the other. * Each ball can go into only one box and no one remains outside of the boxes. * Each box must contain at least one ball. Note that you must print this count modulo $10^9+7$.
[{"input": "10 5", "output": "7"}, {"input": "30 15", "output": "176"}, {"input": "100 30", "output": "3910071"}]
Print the minimum amount of money with which Takahashi can buy M cans of energy drinks. * * *
s157452833
Accepted
p03103
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
N, M, *L = map(int, open(0).read().split()) C = 0 for a, b in sorted(zip(*[iter(L)] * 2)): C += a * min(M, b) M = max(M - b, 0) print(C)
Statement Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks. There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each. What is the minimum amount of money with which he can buy M cans of energy drinks? It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.
[{"input": "2 5\n 4 9\n 2 4", "output": "12\n \n\nWith 12 yen, we can buy one drink at the first store and four drinks at the\nsecond store, for the total of five drinks. However, we cannot buy 5 drinks\nwith 11 yen or less.\n\n* * *"}, {"input": "4 30\n 6 18\n 2 5\n 3 10\n 7 9", "output": "130\n \n\n* * *"}, {"input": "1 100000\n 1000000000 100000", "output": "100000000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the minimum amount of money with which Takahashi can buy M cans of energy drinks. * * *
s494294595
Accepted
p03103
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
b = list(map(int, input().split())) LL = [] for i in range(b[0]): LL.append(list(map(int, input().split()))) LL.sort() x = 0 z = 0 y = b[1] i = -1 # 初めi=0で固定しリストの先頭削除をしていたが計算時間がそれなりにかかる # i+=1でiを増やしていく方向で行かないといけない while y >= 0 and not LL == []: i += 1 if y <= LL[i][1]: print(x + LL[i][0] * y) break else: y -= LL[i][1] x += LL[i][1] * LL[i][0]
Statement Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks. There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each. What is the minimum amount of money with which he can buy M cans of energy drinks? It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.
[{"input": "2 5\n 4 9\n 2 4", "output": "12\n \n\nWith 12 yen, we can buy one drink at the first store and four drinks at the\nsecond store, for the total of five drinks. However, we cannot buy 5 drinks\nwith 11 yen or less.\n\n* * *"}, {"input": "4 30\n 6 18\n 2 5\n 3 10\n 7 9", "output": "130\n \n\n* * *"}, {"input": "1 100000\n 1000000000 100000", "output": "100000000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the minimum amount of money with which Takahashi can buy M cans of energy drinks. * * *
s863447717
Accepted
p03103
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
n, m = map(int, input().split()) a = [0] * (n + 1) b = [0] * (n + 1) total = [0] * (n + 1) ans = 0 # 安い店から選ぶ方法が最適 shop = [tuple(map(int, input().split())) for _ in range(n)] shop.sort() for i in range(1, n + 1): a_i, b_i = shop[i - 1] # 累積和を作っておく # b[i]: i番目の店まで利用した際に購入できる栄養ドリンクの最大本数 # total[i]: i番目の店まで利用した際に支払うお金の最大値 b[i] = b[i - 1] total[i] = total[i - 1] b[i] += b_i total[i] += a_i * b_i # a[i]: i番目の店の栄養ドリンクの単価 a[i] = a_i for i in range(1, n + 1): if m <= b[i]: m = m - b[i - 1] # 足りない分を追加で計算 ans = total[i - 1] + a[i] * m break print(ans)
Statement Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks. There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each. What is the minimum amount of money with which he can buy M cans of energy drinks? It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.
[{"input": "2 5\n 4 9\n 2 4", "output": "12\n \n\nWith 12 yen, we can buy one drink at the first store and four drinks at the\nsecond store, for the total of five drinks. However, we cannot buy 5 drinks\nwith 11 yen or less.\n\n* * *"}, {"input": "4 30\n 6 18\n 2 5\n 3 10\n 7 9", "output": "130\n \n\n* * *"}, {"input": "1 100000\n 1000000000 100000", "output": "100000000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the minimum amount of money with which Takahashi can buy M cans of energy drinks. * * *
s439693229
Accepted
p03103
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2019/3/9 Solved on 2019/3/9 @author: shinjisu """ # ABC 121 # import math def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] def zeros(n): return [0] * n def getIntLines(n): return [int(input()) for i in range(n)] def getIntMat(n): mat = [] for i in range(n): mat.append(getIntList()) return mat def zeros2(n, m): return [zeros(m)] * n ALPHABET = [chr(i + ord("a")) for i in range(26)] DIGIT = [chr(i + ord("0")) for i in range(10)] N1097 = 10**9 + 7 INF = 10**12 def dmp(x, cmt=""): global debug if debug: if cmt != "": print(cmt, ": ", end="") print(x) return x def prob_C(): N, M = getIntList() dmp((N, M)) BA = zeros(N) for i in range(N): BA[i] = getIntList() dmp(BA, "BA") BA.sort() dmp(BA, "BA") count = 0 yen = 0 for i in range(N): buyCount = min(BA[i][1], M - count) yen += buyCount * BA[i][0] count += buyCount dmp((buyCount, count, yen), "buyCount, count, yen") if buyCount >= M: break dmp(yen, "yen") return yen debug = False # True False ans = prob_C() print(ans) # for row in ans: # print(row)
Statement Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks. There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each. What is the minimum amount of money with which he can buy M cans of energy drinks? It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.
[{"input": "2 5\n 4 9\n 2 4", "output": "12\n \n\nWith 12 yen, we can buy one drink at the first store and four drinks at the\nsecond store, for the total of five drinks. However, we cannot buy 5 drinks\nwith 11 yen or less.\n\n* * *"}, {"input": "4 30\n 6 18\n 2 5\n 3 10\n 7 9", "output": "130\n \n\n* * *"}, {"input": "1 100000\n 1000000000 100000", "output": "100000000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the minimum amount of money with which Takahashi can buy M cans of energy drinks. * * *
s526316306
Accepted
p03103
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
# a, b, c, d = (int(i) for i in input().split()) # W = [int(i) for i in input().split()] # N= (int(input())) N, M = (int(i) for i in input().split()) flag = 0 A_list = [] B_list = [] AB_list = [] for i in range(N): a, b = (int(j) for j in input().split()) A_list.append(a) B_list.append(b) AB_list.append([a, b]) pass AB_list = sorted(AB_list, key=lambda x: x[0]) # print(AB_list) now = 0 m_cnt = 0 n_cnt = 0 for ab in AB_list: # print(n_cnt + (ab[1])) if n_cnt + ab[1] >= M: a = M - n_cnt n_cnt += a m_cnt += a * ab[0] break else: n_cnt += ab[1] m_cnt += ab[1] * ab[0] pass print(m_cnt) # k_list = [] # s_list = [] # p_list = [] # for i in range(M): # for j in range(N): # a = [int(i) for i in input().split()] # k_list.append(a[0]) # s_list.append(a[1:]) # pass # pass # p_list = [int(i) for i in input().split()] # lamp_list = [] # #N = int(input()) # # A = [int(i) for i in input().split()] # #S_dict = {} # #P_dict = {} # # for i in range(N): # # tmp = input() # # S = tmp.split()[0] # # P = int(tmp.split()[1]) # # if S in S_dict.keys() and P < S_dict[S]: # # pass # # else: # # S_dict[S] = P # # pass # # pass # # S_dict = sorted(S_dict.items()) # # print(type(S_dict)) # # name_lisy = [] # # for k in S_dict: # # name_lisy.append(k) # # pass # # print(name_lisy) # S_list = [] # P_list = [] # for i in range(N): # tmp = input() # S = tmp.split()[0] # P = int(tmp.split()[1]) # #print(S,P) # S_list.append([S,P]) # #P_list.append(P) # pass # #S_list.sort() # #print(S_list) # sorted_S_list = sorted(S_list, key=lambda x:x[1], reverse=True) # sorted_S_list = sorted(sorted_S_list, key=lambda x:x[0]) # #print(sorted_S_list) # for i,k in enumerate(sorted_S_list): # for j,l in enumerate(S_list): # if sorted_S_list[i] == S_list[j]: # print(j+1) # break # pass # pass # #print(P_list) # for i in range(M): # # A.sort() # if min(A) < C_list[i]: # for j in range(B_list[i]): # if min(A) < C_list[i]: # A.append(C_list[i]) # pass # pass # A.sort(reverse=True) # A = A[:N] # pass # pass # #sum(A[:N-1]) # print(sum(A[:N])) # for i in range(M): # A.sort() # cnt = 0 # for j in range(N): # if cnt < B_list[i] and A[j] < C_list[i]: # A[j] = C_list[i] # cnt += 1 # pass # pass # #print(A) # pass # print(sum(A)) # L_max = max(L_list) # R_min = min(R_list) # for i in range(M): # pass # if R_min-L_max+1 < 0: # print("0") # else: # print(R_min-L_max+1) # if A <= 5: # print(0) # elif 5 < A and A <= 12: # print(int(B/2)) # else: # print(B)
Statement Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks. There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each. What is the minimum amount of money with which he can buy M cans of energy drinks? It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.
[{"input": "2 5\n 4 9\n 2 4", "output": "12\n \n\nWith 12 yen, we can buy one drink at the first store and four drinks at the\nsecond store, for the total of five drinks. However, we cannot buy 5 drinks\nwith 11 yen or less.\n\n* * *"}, {"input": "4 30\n 6 18\n 2 5\n 3 10\n 7 9", "output": "130\n \n\n* * *"}, {"input": "1 100000\n 1000000000 100000", "output": "100000000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the minimum amount of money with which Takahashi can buy M cans of energy drinks. * * *
s540360483
Accepted
p03103
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
a, b = map(int, input().split()) e = [] for i in range(a): c, d = map(int, input().split()) e += [[c, d]] e.sort() a = i = j = 0 while i < b: a += e[j][0] * e[j][1] i += e[j][1] j += 1 print(a - ((i - b) * e[j - 1][0]))
Statement Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks. There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each. What is the minimum amount of money with which he can buy M cans of energy drinks? It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.
[{"input": "2 5\n 4 9\n 2 4", "output": "12\n \n\nWith 12 yen, we can buy one drink at the first store and four drinks at the\nsecond store, for the total of five drinks. However, we cannot buy 5 drinks\nwith 11 yen or less.\n\n* * *"}, {"input": "4 30\n 6 18\n 2 5\n 3 10\n 7 9", "output": "130\n \n\n* * *"}, {"input": "1 100000\n 1000000000 100000", "output": "100000000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum amount of money that can be earned. * * *
s594007559
Accepted
p03553
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
def main(): import sys input = sys.stdin.readline # Dinic's algorithm from collections import deque class Dinic: def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap): forward = [to, cap, None] forward[2] = backward = [fr, 0, forward] self.G[fr].append(forward) self.G[to].append(backward) def add_multi_edge(self, v1, v2, cap1, cap2): edge1 = [v2, cap1, None] edge1[2] = edge2 = [v1, cap2, edge1] self.G[v1].append(edge1) self.G[v2].append(edge2) def bfs(self, s, t): self.level = level = [None] * self.N deq = deque([s]) level[s] = 0 G = self.G while deq: v = deq.popleft() lv = level[v] + 1 for w, cap, _ in G[v]: if cap and level[w] is None: level[w] = lv deq.append(w) return level[t] is not None def dfs(self, v, t, f): if v == t: return f level = self.level for e in self.it[v]: w, cap, rev = e if cap and level[v] < level[w]: d = self.dfs(w, t, min(f, cap)) if d: e[1] -= d rev[1] += d return d return 0 def flow(self, s, t): flow = 0 INF = 10**9 + 7 G = self.G while self.bfs(s, t): (*self.it,) = map(iter, self.G) f = INF while f: f = self.dfs(s, t, INF) flow += f return flow inf = 1 << 40 N = int(input()) A = list(map(int, input().split())) dinic = Dinic(N + 2) ans = 0 for i, a in enumerate(A): if a > 0: ans += a # dinic.add_edge(0, i+1, 0) dinic.add_edge(i + 1, N + 1, a) else: dinic.add_edge(0, i + 1, -a) # dinic.add_edge(i+1, N+1, 0) for i in range(1, N + 1): for k in range(1, N + 1): if i * k > N: break dinic.add_edge(i, i * k, inf) print(ans - dinic.flow(0, N + 1)) if __name__ == "__main__": main()
Statement We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
[{"input": "6\n 1 2 -6 4 5 3", "output": "12\n \n\nIt is optimal to smash Gem 3 and 6.\n\n* * *"}, {"input": "6\n 100 -100 -100 -100 100 -100", "output": "200\n \n\n* * *"}, {"input": "5\n -1 -2 -3 -4 -5", "output": "0\n \n\nIt is optimal to smash all the gems.\n\n* * *"}, {"input": "2\n -1000 100000", "output": "99000"}]
Print the maximum amount of money that can be earned. * * *
s715514972
Wrong Answer
p03553
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import itertools import copy # 最大公約数 def gcd(x, y): while y != 0: x, y = y, x % y return x # 宝石の数 N = int(input()) # 宝石の得点 a = list(map(int, input().split())) # 宝石の得点に負があるか否か if min(a) >= 0: # 全てを計算して出力 print(sum(a)) else: # 宝石の得点が負であるインデックスを取得 minus = [i for i, j in enumerate(a) if j < 0] # 宝石の得点が負であるインデックスの組み合わせ combination = [] for i in range(len(minus)): combination.extend(list(itertools.combinations(minus, (i + 1)))) # インデックスの組み合わせを全て計算 summation = [sum(a)] for i in combination: # 元のリストは保持 a_remove = copy.deepcopy(a) for index in i: # 削除する代わりに0で置換 for j in range((len(a) + 1) // (index + 1)): a_remove[(index + 1) * j - 1] = 0 summation.append(sum(a_remove)) print(max(summation))
Statement We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
[{"input": "6\n 1 2 -6 4 5 3", "output": "12\n \n\nIt is optimal to smash Gem 3 and 6.\n\n* * *"}, {"input": "6\n 100 -100 -100 -100 100 -100", "output": "200\n \n\n* * *"}, {"input": "5\n -1 -2 -3 -4 -5", "output": "0\n \n\nIt is optimal to smash all the gems.\n\n* * *"}, {"input": "2\n -1000 100000", "output": "99000"}]
Print the maximum amount of money that can be earned. * * *
s298725459
Runtime Error
p03553
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N=int(input()) A=list(map(int,input().split())) B=A[:] while True: B=A[:] for j in range(N): for i in range(N,N-j-1,-1): w=0 for k in range(N): if (k+1)%i==0:w+=B[k] if w=<0:#割ったほうがいい! for k in range(N): if (k+1)%i==0:B[k]=0 if A==B:break else: A=B[:] ans=0 for j in range(N): ans+=A[j] print(ans)
Statement We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
[{"input": "6\n 1 2 -6 4 5 3", "output": "12\n \n\nIt is optimal to smash Gem 3 and 6.\n\n* * *"}, {"input": "6\n 100 -100 -100 -100 100 -100", "output": "200\n \n\n* * *"}, {"input": "5\n -1 -2 -3 -4 -5", "output": "0\n \n\nIt is optimal to smash all the gems.\n\n* * *"}, {"input": "2\n -1000 100000", "output": "99000"}]
Print the maximum amount of money that can be earned. * * *
s180531973
Runtime Error
p03553
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
¥from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 class Dinic(): def __init__(self, source, sink): self.G = defaultdict(lambda:defaultdict(int)) self.sink = sink self.source = source def add_edge(self, u, v, cap): self.G[u][v] = cap self.G[v][u] = 0 def bfs(self): level = defaultdict(int) q = [self.source] level[self.source] = 1 d = 1 while q: if level[self.sink]: break qq = [] d += 1 for u in q: for v, cap in self.G[u].items(): if cap == 0: continue if level[v]: continue level[v] = d qq += [v] q = qq self.level = level def dfs(self, u, f): if u == self.sink: return f for v, cap in self.iter[u]: if cap == 0 or self.level[v] != self.level[u] + 1: continue d = self.dfs(v, min(f, cap)) if d: self.G[u][v] -= d self.G[v][u] += d return d return 0 def max_flow(self): flow = 0 while True: self.bfs() if self.level[self.sink] == 0: break self.iter = {u: iter(self.G[u].items()) for u in self.G} while True: f = self.dfs(self.source, INF) if f == 0: break flow += f return flow n = I() A = LI() score = 0 s = 0 t = n + 1 dinic = Dinic(s, t) for i in range(1, n + 1): if A[i - 1] > 0: score += A[i - 1] dinic.add_edge(s, i, 0) dinic.add_edge(i, t, A[i - 1]) else: dinic.add_edge(s, i, -A[i - 1]) dinic.add_edge(i, t, 0) ret = i * 2 while ret <= n: dinic.add_edge(i, ret, INF) ret += i print(score - dinic.max_flow())
Statement We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
[{"input": "6\n 1 2 -6 4 5 3", "output": "12\n \n\nIt is optimal to smash Gem 3 and 6.\n\n* * *"}, {"input": "6\n 100 -100 -100 -100 100 -100", "output": "200\n \n\n* * *"}, {"input": "5\n -1 -2 -3 -4 -5", "output": "0\n \n\nIt is optimal to smash all the gems.\n\n* * *"}, {"input": "2\n -1000 100000", "output": "99000"}]
Print the maximum amount of money that can be earned. * * *
s027363226
Wrong Answer
p03553
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) a = list(map(int, input().split())) flag = 1 for i in a: if i > 0: flag = 0 if flag: print(0) else: flag_ = 1 while flag_: ans = sum(a) prime = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ] b = [[] for i in range(100)] for i in prime: j = i while j <= n: b[i].append(a[j - 1]) j += i c = [] flag_ = 0 for i in b: if sum(i) < 0: flag_ = 1 c.append(sum(i)) dis = 0 mi = 0 for i in range(100): if c[i] < mi: mi = c[i] dis = i if mi >= 0: break for i in range(1, n + 1): if i % dis == 0: a[i - 1] = 0 ans += -mi print(ans)
Statement We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
[{"input": "6\n 1 2 -6 4 5 3", "output": "12\n \n\nIt is optimal to smash Gem 3 and 6.\n\n* * *"}, {"input": "6\n 100 -100 -100 -100 100 -100", "output": "200\n \n\n* * *"}, {"input": "5\n -1 -2 -3 -4 -5", "output": "0\n \n\nIt is optimal to smash all the gems.\n\n* * *"}, {"input": "2\n -1000 100000", "output": "99000"}]
Print the maximum amount of money that can be earned. * * *
s288847311
Runtime Error
p03553
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
#include <bits/stdc++.h> #include <cassert> typedef long long int ll; using namespace std; #if defined(DEBUG) #include <unistd.h> #include <sys/fcntl.h> #define DLOG(...) cerr << dbgFormat(__VA_ARGS__) << endl #define DCALL(func, ...) func(__VA_ARGS__) template <class... Args> string dbgFormat(const char* fmt, Args... args) { size_t len = snprintf(nullptr, 0, fmt, args...); char buf[len + 1]; snprintf(buf, len + 1, fmt, args...); return string(buf); } #else // defined(DEBUG) #define DLOG(...) #define DCALL(func, ...) #endif // defined(DEBUG) // ---------------------------------------------------------------------- struct Edge { int dst; ll cap; int rev; Edge(int d, ll c, int r) : dst(d), cap(c), rev(r) {} }; class Dinic { int vSize; int source; int sink; vector<int> level; // from sink rather than source vector<size_t> iter; vector<vector<Edge>> edges; ll dfs(int u, ll sCap) { if (u == sink) return sCap; ll f = 0; for (size_t& i = iter.at(u); i < edges.at(u).size(); i++) { Edge& e = edges.at(u).at(i); if (e.cap == 0 || level.at(e.dst) >= level.at(u)) continue; ll f0 = dfs(e.dst, min(sCap - f, e.cap)); e.cap -= f0; edges.at(e.dst).at(e.rev).cap += f0; f += f0; if (f == sCap) break; } return f; } void set_level() { level.assign(vSize, -1); deque<pair<int,int>> deq; deq.emplace_back(sink, 0); while (!deq.empty()) { pair<int,int> p = deq.front(); deq.pop_front(); int i = p.first; int lev = p.second; if (level.at(i) >= 0) continue; level.at(i) = lev; for (const Edge& erev : edges.at(i)) { const Edge& e = edges.at(erev.dst).at(erev.rev); if (e.cap == 0) continue; deq.emplace_back(erev.dst, lev + 1); } } } public: Dinic(int sz, int src, int snk) : vSize(sz), source(src), sink(snk), edges(sz) {} void add_edge(int u, int v, ll cap) { assert(0 <= u && u < vSize && 0 <= v && v < vSize); assert(cap > 0); int nu = edges.at(u).size(); int nv = edges.at(v).size(); edges.at(u).push_back(Edge(v, cap, nv)); edges.at(v).push_back(Edge(u, 0, nu)); } ll run() { ll flow = 0; while(1) { set_level(); if (level.at(source) == -1) break; iter.assign(vSize, 0); flow += dfs(source, LLONG_MAX); } return flow; } }; // ---------------------------------------------------------------------- int main(int argc, char *argv[]) { #if defined(DEBUG) // GDB on Cygwin ignores redirection at run command. if (argc == 2) dup2(open(argv[1], 0), 0); #else // For performance. We should not use C-style stdio functions ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif cout << setprecision(20); int N; cin >> N; ll myINF = (ll)1e16; ll pos = 0; Dinic g(N+2, 0, N+1); for (int i = 1; i <= N; i++) { ll a; cin >> a; if (a < 0) g.add_edge(0, i, -a); else { g.add_edge(i, N+1, a); pos += a; } } for (int i = 1; i <= N; i++) { for (int j = 2; j <= N && i*j <= N; j++) { g.add_edge(i, i*j, myINF); } } ll flow = g.run(); cout << pos - flow << endl; return 0; }
Statement We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
[{"input": "6\n 1 2 -6 4 5 3", "output": "12\n \n\nIt is optimal to smash Gem 3 and 6.\n\n* * *"}, {"input": "6\n 100 -100 -100 -100 100 -100", "output": "200\n \n\n* * *"}, {"input": "5\n -1 -2 -3 -4 -5", "output": "0\n \n\nIt is optimal to smash all the gems.\n\n* * *"}, {"input": "2\n -1000 100000", "output": "99000"}]
Print the maximum amount of money that can be earned. * * *
s731453208
Wrong Answer
p03553
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) a = [int(i) for i in input().split()] sum = 0 ans = 0 for i in range(n): x = n - i sum = 0 for j in range(n // x): sum += a[x * (j + 1) - 1] if sum < 0: for k in range(n // x): a[x * (k + 1) - 1] = 0 for j in range(n): ans += a[j] print(ans)
Statement We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
[{"input": "6\n 1 2 -6 4 5 3", "output": "12\n \n\nIt is optimal to smash Gem 3 and 6.\n\n* * *"}, {"input": "6\n 100 -100 -100 -100 100 -100", "output": "200\n \n\n* * *"}, {"input": "5\n -1 -2 -3 -4 -5", "output": "0\n \n\nIt is optimal to smash all the gems.\n\n* * *"}, {"input": "2\n -1000 100000", "output": "99000"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s169116056
Wrong Answer
p03416
Input is given from Standard Input in the following format: A B
f, t = [int(i) for i in input().split()] print(len([i for i in range(f, t) if str(i) == str(i)[::-1]]))
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s092757990
Accepted
p03416
Input is given from Standard Input in the following format: A B
A, B = (int(X) for X in input().split()) Count = 0 for T in range(A, B + 1): StrT = str(T) if StrT[0:2] == StrT[3:5][::-1]: Count += 1 print(Count)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s664581018
Accepted
p03416
Input is given from Standard Input in the following format: A B
range_min, range_max = map(int, input().split()) palindromic = 0 for i in range(range_min, range_max + 1): palindromic += 1 if str(i) == str(i)[::-1] else 0 print(palindromic)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s276253194
Accepted
p03416
Input is given from Standard Input in the following format: A B
A = input().split(" ") B = int(A[0]) C = int(A[1]) Blis = list(A[0]) Clis = list(A[1]) # print(B) # print(C) # print(Blis) # print(Clis) NUM = B kazu = 0 while NUM <= C: NUMlis = list(str(NUM)) if NUMlis[0] == NUMlis[4] and NUMlis[1] == NUMlis[3]: kazu += 1 NUM += 1 print(kazu)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s622777477
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Math; namespace ConsoleApp15 { class Class404 { static void Main() { var AB = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = AB[0], B = AB[1]; int count = 0; for (int i = A; i <= B; i++) { string n1 = i.ToString(); string n2 = string.Join("", n1.Reverse()); if (n1 == n2) count++; } Console.WriteLine(count); } } }
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s106382979
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
# # abc090 b # 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 = """11009 11332""" output = """4""" self.assertIO(input, output) def test_入力例_2(self): input = """31415 92653""" output = """612""" self.assertIO(input, output) def resolve(): A, B = map(int, input().split()) ans = 0 for i in range(A, B+1): s = str(i) for j in range((3): if s[j] != s[-1-j]: break else: ans += 1 print(ans) if __name__ == "__main__": # unittest.main() resolve()
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s345441699
Wrong Answer
p03416
Input is given from Standard Input in the following format: A B
A, B = map(str, input().split()) La = [int(A[:3]), int(A[3:])] Lb = [int(B[:3]), int(B[3:])] L = 900 - (La[0] - 100) - (999 - Lb[0]) ch1 = int(A[1] + A[0]) ch2 = int(B[1] + B[0]) if Lb[1] <= ch2: L -= 1 if ch1 <= La[1]: L -= 1 print(L)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s028319380
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
31415 92653
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s310753891
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a, b =map(str, input().split()) #複数数値入力 count = 0 c = [] if int(a[3:5]) < int(a[1]+a[]): count += 1 count += int(b[0:3]) - int(a[0:3]) print(count)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s184366235
Wrong Answer
p03416
Input is given from Standard Input in the following format: A B
a, b = map(int, input().split()) no_count = 0 if a // 1000 < a % 100: no_count -= 1 if b // 1000 > b % 100: no_count -= 1 print(b // 100 - a // 100 + 1 + no_count)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s580717430
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a, b = map(int, input().split()) ans = 0 for i in range(1,10): for j in range(0,10): for k in range(0,10): x = 10000*i + 1000*j + 100*k + 10*j + i if a <= x <= b: ans += 1 print(ans)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s383015700
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a,b=map(int,input().split()) cnt=0 for l in range(a,b+1): l_i=list(str()) if l_i[0]==l_i[-1] and l_i[1]=l_i[-2]: cnt+=1 print(cnt)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s076682158
Wrong Answer
p03416
Input is given from Standard Input in the following format: A B
a, b = input().split() af = int(int(a[0:2]) >= int(a[3:5])) bf = int(int(b[0:2]) <= int(b[3:5])) print(int(b[0:3]) - int(a[0:3]) - 1 + af + bf)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s975595199
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
# -*- coding:utf-8 -*- if __name__ == "__main__": A, B = list(map(int, input().split())) ans = 0 for i in range(A, B+1) c = str(i) if len(c)%2 == 0: continue J = len(c) for j in range(J): if c[j] == c[J-1-j]: if j == J-1-j: ans += 1 break else: break print(ans)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s814461716
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
A,B = map(int,input().split()) ...: ...: ...: def kaibun(m, n): ...: key = 0 ...: for i in range(m,n+1): ...: s = i//10000 ...: t = i%10 ...: u = i//1000 % 10 ...: v = i//10 % 10 ...: if (s==t)&(u==v): ...: key += 1 ...: return key ...: ...: print(kaibun(A,B))
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s296575688
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
fn main() { let a: i32 = read(); let b: i32 = read(); let mut ans = 0; for i in a..b+1 { let s: String = i.to_string(); let s: Vec<char> = s.chars().collect(); if s[0] == s[4] && s[1] == s[3] { ans += 1; } } println!("{}", ans); } // 以下関数 use std::io::*; use std::str::FromStr; pub fn read<T: FromStr>() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } pub const MOD: u64 = 10e9 as u64 + 7; pub fn is_prime(n: i32) -> bool { if n < 2 { return false; } else if n == 2 { return true; } let mut i = 2; while i * i < n { if n % i == 0 { return false; } else { i += 1; continue; } } true } pub fn lcm(mut n: i32, mut m: i32) -> i32 { n = if n > m { m } else { n }; m = if n > m { n } else { m }; let mut i = n; while i % m != 0 { i += n; } i } pub fn abs(n: i32) -> i32 { if n >= 0 { n } else { -n } } pub fn max(n: i32, m: i32) -> i32 { if n >= m { n } else { m } } pub fn min(n: i32, m: i32) -> i32 { if n <= m { n } else { m } }
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s952854675
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a, b = map(int, input().split()) count = 0 for i in range(a, b): s = str(i) if(len(s) == 1): break for j in range(len(s) // 2): if(s[j] != s[len(s)-1-j]): break else: count += 1 print(count)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s795312559
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
A,B = input().split(' ') num = 0 for i in range(int(A), int(B)+1): s = str(i) for j in range(len(s)//2): if s[j] != s[len(s)-1-j]: break if j == len(s)//2 - 1: num += 1 print(num
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s716812889
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
A, B = map(int input().split()) cou = B//100 - A//100 Astr = str(A) Aup = 10 * int(Astr[1]) + int(Astr[0]) Adown = A%100 Bstr =str(B) Bup = 10 * int(Bstr[1]) + int(Bstr[0]) Bdown = B%100 if Adown < Aup : cou += 1 if Bdown > Bup : cou += 1 print(cou)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s956509075
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
#include <bits/stdc++.h> using namespace std; typedef long long ll; int A, B; bool kaibun_5(int n) { bool ret = true; string str_n = to_string(n); for (int i = 0; i < 2; i++) { if (str_n[i] != str_n[4-i]) { ret = false; } } return ret; } int main() { cin >> A >> B; int ans = 0; for (int i = A; i <= B; i++) { if (kaibun_5(i)) { ans++; } } cout << ans << endl; return 0; }
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s871305541
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
# -*- coding:utf-8 -*- if __name__ == "__main__": A, B = list(map(int, input().split())) ans = 0 for i in range(A, B+1) c = str(i) length = len(c) if length%2 == 0: continue for j in range(length): if c[j] == c[length-1-j]: if j == length-1-j: ans += 1 break continue else: break print(ans)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s168232123
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
A, B = map(int, input().split(" ")) num = 0 for str(x) in range(A, B + 1): if str(x) == str(x)[::-1]: num += 1 print(num)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s454046934
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a,b =map(int,input().split()) print(sum(i==i[::-1] for i in map(str,range(a,b+1)))
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s582742959
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
A,B = map(int,input().split()) a = 0 for i in range(A,B+1): if i[1:2] = i[4:5]: a += 1 print("a")
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s128414838
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
31415 92653
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s011987019
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a,b=map(int,input().split()) count=0 for i in range(a,b+1): if str(i)==str(i)[::-1]: count+=1  #count++はダメ print(count)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s915708734
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a,b=map(int,input().split()) count=0 for i in range(a,b+1): if str(i) == str(i)[::-1]: count+=1  #count++はダメ print(count)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s328497117
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a,b=map(int,input().split()) cnt=0 for i in range(a,b+1): if str(i) == str(i)[::-1]: cnt +=1 #count++はダメ print(cnt)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s979530104
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a = input() b = input() a_12 = int(a[0:2]) a_3 = int(a[2]) a_45 = int(a[3:5]) b_12 = int(b[0:2]) b_3 = int(b[2]) b_45 = int(b[3:5]) a_21 = int(a[1] + a[0]) b_21 = int(b[1] + b[0]) ans = (b_12 - a_12 + 1) * 10 - a_3 - (10 - b_3 - 1) if a_21 < a_45: ans = ans - 1 if b_21 > b_45: ans = ans - 1 print(ans)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s504560249
Wrong Answer
p03416
Input is given from Standard Input in the following format: A B
A, B = map(int, input().split()) cou = B // 100 - A // 100 - 1 Astr = str(A) Aup = 10 * int(Astr[1]) + int(Astr[0]) Adown = A % 100 Bstr = str(B) Bup = 10 * int(Bstr[1]) + int(Bstr[0]) Bdown = B % 100 if Adown < Aup: cou += 1 if Bdown > Bup: cou += 1 print(cou)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s479862250
Runtime Error
p03416
Input is given from Standard Input in the following format: A B
a, b = map(input().split()) print(len([1 for i in range(a, b + 1) if i // 1000 == i % 100]))
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s829932602
Wrong Answer
p03416
Input is given from Standard Input in the following format: A B
for i in range(1, pow(10, 5)): b = int(i / 100000) c = int(i / 10000 % 10) d = int(i / 1000 % 10) e = int(i / 100 % 10) f = int(i / 10 % 10) g = int(i % 10) if (b**5 + c**5 + d**5 + e**5 + f**5 + g**5) == i: print(i)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the number of _palindromic numbers_ among the integers between A and B (inclusive). * * *
s307886373
Accepted
p03416
Input is given from Standard Input in the following format: A B
start, end = map(int, input().split()) num = len([i for i in range(start, end + 1) if list(str(i)) == list(str(i))[::-1]]) print(num)
Statement Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
[{"input": "11009 11332", "output": "4\n \n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and\n11311.\n\n* * *"}, {"input": "31415 92653", "output": "612"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s453805083
Accepted
p03945
The input is given from Standard Input in the following format: S
l = input() def runlength(S): ans = [] for s in S: if len(ans) == 0 or ans[-1][0] != s: ans.append([s, 1]) else: ans[-1][1] += 1 return ans print(len(runlength(l)) - 1)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s233257025
Accepted
p03945
The input is given from Standard Input in the following format: S
# https://atcoder.jp/contests/abc047/tasks/arc063_a # 連長圧縮すれば簡単 # 圧縮後の文字列長-1となる # def run_length_encoding(s): # '''連長圧縮を行う # s ... iterable object e.g. list, str # return # ---------- # s_composed,s_num,s_idx # それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx''' # s_composed, s_sum = [], [] # s_idx = [0] # pre = s[0] # cnt = 1 # for i, ss in enumerate(s[1:], start=1): # if pre == ss: # cnt += 1 # else: # s_sum.append(cnt) # s_composed.append(pre) # s_idx.append(i) # cnt = 1 # pre = ss # s_sum.append(cnt) # s_composed.append(pre) # # assert len(s_sum) == len(s_composed) # return s_composed, s_sum, s_idx def run_length_encoding(s): """連長圧縮を行う s ... iterable object e.g. list, str return ---------- s_composed,s_num,s_idx それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx""" from itertools import groupby s_composed, s_sum = [], [] s_idx = [0] for k, v in groupby(s): s_composed.append(k) n = len(list(v)) s_sum.append(n) s_idx.append(s_idx[-1] + n) # assert len(s_sum) == len(s_composed) return s_composed, s_sum, s_idx S_composed, _, _ = run_length_encoding(input()) print(len(S_composed) - 1)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s692576861
Accepted
p03945
The input is given from Standard Input in the following format: S
[print(len(list(i.groupby(input()))) - 1) for i in [__import__("itertools")]]
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s303584697
Runtime Error
p03945
The input is given from Standard Input in the following format: S
ans = 0 S = input() for i in range(1,len(S)): if S[i-1] != S[i]: ans += 1 print(ans)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s338162707
Wrong Answer
p03945
The input is given from Standard Input in the following format: S
a = input() b = a[::-1] flag = 1 count = 0 count_ = 0 while flag == 1: p = a.find("WB") q = a.find("BW") if p != -1 and q != -1 and p < q: a = a.replace("W", "B", p + 1) count += 1 elif p != -1 and q == -1: a = a.replace("W", "B", p + 1) count += 1 elif p != -1 and q != -1 and p > q: a = a.replace("B", "W", q + 1) count += 1 elif p == -1 and q == -1: a = a.replace("B", "W", q + 1) count += 1 if "BW" not in a and "WB" not in a: flag = 0 flag = 1 while flag == 1: p = b.find("WB") q = b.find("BW") if p != -1 and q != -1 and p < q: b = b.replace("W", "B", p + 1) count_ += 1 elif p != -1 and q == -1: b = b.replace("W", "B", p + 1) count_ += 1 elif p != -1 and q != -1 and p > q: b = b.replace("B", "W", q + 1) count_ += 1 elif p == -1 and q == -1: b = b.replace("B", "W", q + 1) count_ += 1 if "BW" not in a and "WB" not in b: flag = 0 print(min(count, count_))
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s095849417
Accepted
p03945
The input is given from Standard Input in the following format: S
import sys import math import collections import itertools import array import inspect # Set max recursion limit sys.setrecursionlimit(1000000) # Debug output def chkprint(*args): names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()} print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args)) # Binary converter def to_bin(x): return bin(x)[2:] def li_input(): return [int(_) for _ in input().split()] def gcd(n, m): if n % m == 0: return m else: return gcd(m, n % m) def gcd_list(L): v = L[0] for i in range(1, len(L)): v = gcd(v, L[i]) return v def lcm(n, m): return (n * m) // gcd(n, m) def lcm_list(L): v = L[0] for i in range(1, len(L)): v = lcm(v, L[i]) return v # Width First Search (+ Distance) def wfs_d(D, N, K): """ D: 隣接行列(距離付き) N: ノード数 K: 始点ノード """ dfk = [-1] * (N + 1) dfk[K] = 0 cps = [(K, 0)] r = [False] * (N + 1) r[K] = True while len(cps) != 0: n_cps = [] for cp, cd in cps: for i, dfcp in enumerate(D[cp]): if dfcp != -1 and not r[i]: dfk[i] = cd + dfcp n_cps.append((i, cd + dfcp)) r[i] = True cps = n_cps[:] return dfk # Depth First Search (+Distance) def dfs_d(v, pre, dist): """ v: 現在のノード pre: 1つ前のノード dist: 現在の距離 以下は別途用意する D: 隣接リスト(行列ではない) D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト """ global D global D_dfs_d D_dfs_d[v] = dist for next_v, d in D[v]: if next_v != pre: dfs_d(next_v, v, dist + d) return def sigma(N): ans = 0 for i in range(1, N + 1): ans += i return ans class Combination: def __init__(self, n, mod): g1 = [1, 1] g2 = [1, 1] inverse = [0, 1] for i in range(2, n + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) self.MOD = mod self.N = n self.g1 = g1 self.g2 = g2 self.inverse = inverse def __call__(self, n, r): if r < 0 or r > n: return 0 r = min(r, n - r) return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD # -------------------------------------------- dp = None def main(): S = input() pre_s = S[0] ans = 0 for i in range(1, len(S)): if S[i] != pre_s: ans += 1 pre_s = S[i] print(ans) main()
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s116026606
Accepted
p03945
The input is given from Standard Input in the following format: S
str = list(input()) out = 0 pro = str[0] for i in range(len(str)): if pro != str[i]: out += 1 pro = str[i] print(out)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s871740120
Accepted
p03945
The input is given from Standard Input in the following format: S
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def _I(): return int(sys.stdin.readline()) def _F(): return float(sys.stdin.readline()) def _pf(s): return print(s, flush=True) S = input() if len(set(S)) == 0: print(0) exit() """ WWBBBWBBBBW 右から行くと、4 左から行くと、4 どちらからいってもおなじか? WBWBWBWBWB 右から->9 左から->9 どちらからいってもかわらない? 右左両方から行く場合 WWBBBWBBBBW WWBBBBWBW WB, BWの数を数える? """ ans = 0 ans += S.count("WB") ans += S.count("BW") print(ans)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s767078811
Runtime Error
p03945
The input is given from Standard Input in the following format: S
#!/usr/bin/env python3 # from numba import njit # input = stdin.readline def calcGroup(s): whiteCount = 0 blackCount = 0 prev = "" for i in range(len(s)): if s[i] == prev: pass else: if s[i] = "W": whiteCount += 1 elif s[i] = "B": blackCount += 1 else: raise ValueError prev = s[i] return whiteCount,blackCount # @njit def solve(s): # white,black = calcGroup(s) return min(calcGroup(s)) def main(): s = input() print(solve(s)) return if __name__ == '__main__': main()
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s029403120
Runtime Error
p03945
The input is given from Standard Input in the following format: S
#include <iostream> #include <string> #define rep(i,n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; int ans = 0; cin >> s; rep(i,s.size()-1) { if (s[i] != s[i+1]) { ans++; } } cout << ans << "\n"; }
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s724785255
Accepted
p03945
The input is given from Standard Input in the following format: S
BW = input() BF = BW[0] LS = [BW[0]] for s in BW: if BF != s: LS.append(s) BF = s print(len(LS) - 1)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s972905401
Runtime Error
p03945
The input is given from Standard Input in the following format: S
a=input() b=0 for i in range(len(a)-1): a[i]!=a[i+1]: b=b+1 if a[-2]!=a[-1]: b=b+1 print(b)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s291389659
Accepted
p03945
The input is given from Standard Input in the following format: S
a = list(input()) s = -1 d = "" for i in a: if i != d: s += 1 d = i print(s)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s151983345
Runtime Error
p03945
The input is given from Standard Input in the following format: S
n = input() gr = itertools.groupby(n) print(len(gr) - 1)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s499272704
Runtime Error
p03945
The input is given from Standard Input in the following format: S
[print(len(list(i.groupby(input())))-1)for i in[__import__('itertools')]][print(len(list(i.groupby(input())))-1)for i in[__import__('itertools')]]
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s136685431
Wrong Answer
p03945
The input is given from Standard Input in the following format: S
s = input() if s[0] == "W": ans = s.count("WB") elif s[0] == "B": ans = s.count("BW") if s[0] == s[len(s) - 1]: a = 1 else: a = 0 print([0, ans * 2 - 1 + a][ans == 0])
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s409356298
Accepted
p03945
The input is given from Standard Input in the following format: S
#!/usr/bin/env python3 import sys # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, 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 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 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 datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # 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 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 operator import itemgetter # itemgetter(1), itemgetter('key') # 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()) board = input() n = len(board) cnt = 0 for i in range(n - 1): if board[i] != board[i + 1]: cnt += 1 print(cnt) if __name__ == "__main__": main()
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s334296702
Runtime Error
p03945
The input is given from Standard Input in the following format: S
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); char[] s = sc.next().toCharArray(); sc.close(); int ans = 0; char b = s[0]; for (char i:s){ if (b != i){ ans++; b = i; } } System.out.println(ans); } }
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s571539736
Runtime Error
p03945
The input is given from Standard Input in the following format: S
# coding: utf-8 # R: Right hand side # L: Left hand side def add_stone(stone, pos, searched_stones): sample = searched_stones[:: [1, -1][pos == "R"]] if sample[0] == stone: return None for n, s in enumerate(sample[1:]): if s == stone: return stone * (n + 2) + sample[1 + n :] def stones_bfs(searched_stones): queue = [searched_stones + "0"] patterns = [["B", "R"], ["B", "L"], ["W", "R"], ["W", "L"]] while queue: stones = queue.pop(0) if stones.count("W") == len(stones) - 1 | stones.count("B") == len(stones) - 1: return int(stones[-1]) for p in patterns: s = add_stone(*p, stones[:-1]) if s is not None: queue += [s + str(int(stones[-1]) + 1)] print(stones_bfs(input().strip()))
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s670938829
Accepted
p03945
The input is given from Standard Input in the following format: S
i0 = "" change = -1 stones = input() for i in stones: if i != i0: change += 1 i0 = i print(change)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s603621874
Accepted
p03945
The input is given from Standard Input in the following format: S
(lambda line: print(line.count("WB") + line.count("BW")))(input())
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s764024882
Accepted
p03945
The input is given from Standard Input in the following format: S
print(sum(map(input().count, ["WB", "BW"])))
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s199701656
Runtime Error
p03945
The input is given from Standard Input in the following format: S
s = str(input()) ans = 0 for i in range(len(s) - 1): if s[i] <> [i + 1]: ans += 1 print(ans)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s679657120
Runtime Error
p03945
The input is given from Standard Input in the following format: S
s=input() ans=0 for i in range(len(s):): if s[i]!=s[i+1]: ans+=1 print(ans)
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]
Print the minimum number of new stones that Jiro needs to place for his purpose. * * *
s322890981
Accepted
p03945
The input is given from Standard Input in the following format: S
string = input() print(string.count("WB") + string.count("BW"))
Statement Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
[{"input": "BBBWW", "output": "1\n \n\nBy placing a new black stone to the right end of the row of stones, all white\nstones will become black. Also, by placing a new white stone to the left end\nof the row of stones, all black stones will become white.\n\nIn either way, Jiro's purpose can be achieved by placing one stone.\n\n* * *"}, {"input": "WWWWWW", "output": "0\n \n\nIf all stones are already of the same color, no new stone is necessary.\n\n* * *"}, {"input": "WBWBWBWBWB", "output": "9"}]