user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u347640436
|
p02679
|
python
|
s719322819
|
s780719256
| 1,583 | 1,355 | 159,512 | 151,468 |
Accepted
|
Accepted
| 14.4 |
from math import gcd
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
t = []
d = {}
d[0] = {}
d[0][0] = 0
for a, b in AB:
i = gcd(a, b)
if i != 0:
a //= i
b //= i
t.append((a, b))
d.setdefault(a, {})
d[a].setdefault(b, 0)
d[a][b] += 1
t = set(t)
if (0, 0) in t:
t.remove((0, 0))
used = set()
result = 1
for a, b in t:
if (a, b) in used:
continue
used.add((a, b))
i = d[a][b]
j, k, l = 0, 0, 0
if -a in d and -b in d[-a]:
j = d[-a][-b]
used.add((-a, -b))
if -b in d and a in d[-b]:
k = d[-b][a]
used.add((-b, a))
if b in d and -a in d[b]:
l = d[b][-a]
used.add((b, -a))
result *= pow(2, i + j, 1000000007) + pow(2, k + l, 1000000007) - 1
result %= 1000000007
result += d[0][0] - 1
result %= 1000000007
print(result)
|
from math import gcd
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
m = 1000000007
t = []
d = {}
d[0] = {}
d[0][0] = 0
for a, b in AB:
i = gcd(a, b)
if i != 0:
a //= i
b //= i
t.append((a, b))
d.setdefault(a, {})
d[a].setdefault(b, 0)
d[a][b] += 1
used = set()
result = 1
for a, b in t:
if (a, b) in used:
continue
used.add((a, b))
if a == 0 and b == 0:
continue
i = d[a][b]
j, k, l = 0, 0, 0
if -a in d and -b in d[-a]:
j = d[-a][-b]
used.add((-a, -b))
if -b in d and a in d[-b]:
k = d[-b][a]
used.add((-b, a))
if b in d and -a in d[b]:
l = d[b][-a]
used.add((b, -a))
result *= pow(2, i + j, m) + pow(2, k + l, m) - 1
result %= m
result += d[0][0] - 1
result %= m
print(result)
| 44 | 45 | 916 | 892 |
from math import gcd
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
t = []
d = {}
d[0] = {}
d[0][0] = 0
for a, b in AB:
i = gcd(a, b)
if i != 0:
a //= i
b //= i
t.append((a, b))
d.setdefault(a, {})
d[a].setdefault(b, 0)
d[a][b] += 1
t = set(t)
if (0, 0) in t:
t.remove((0, 0))
used = set()
result = 1
for a, b in t:
if (a, b) in used:
continue
used.add((a, b))
i = d[a][b]
j, k, l = 0, 0, 0
if -a in d and -b in d[-a]:
j = d[-a][-b]
used.add((-a, -b))
if -b in d and a in d[-b]:
k = d[-b][a]
used.add((-b, a))
if b in d and -a in d[b]:
l = d[b][-a]
used.add((b, -a))
result *= pow(2, i + j, 1000000007) + pow(2, k + l, 1000000007) - 1
result %= 1000000007
result += d[0][0] - 1
result %= 1000000007
print(result)
|
from math import gcd
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
m = 1000000007
t = []
d = {}
d[0] = {}
d[0][0] = 0
for a, b in AB:
i = gcd(a, b)
if i != 0:
a //= i
b //= i
t.append((a, b))
d.setdefault(a, {})
d[a].setdefault(b, 0)
d[a][b] += 1
used = set()
result = 1
for a, b in t:
if (a, b) in used:
continue
used.add((a, b))
if a == 0 and b == 0:
continue
i = d[a][b]
j, k, l = 0, 0, 0
if -a in d and -b in d[-a]:
j = d[-a][-b]
used.add((-a, -b))
if -b in d and a in d[-b]:
k = d[-b][a]
used.add((-b, a))
if b in d and -a in d[b]:
l = d[b][-a]
used.add((b, -a))
result *= pow(2, i + j, m) + pow(2, k + l, m) - 1
result %= m
result += d[0][0] - 1
result %= m
print(result)
| false | 2.222222 |
[
"+m = 1000000007",
"-t = set(t)",
"-if (0, 0) in t:",
"- t.remove((0, 0))",
"+ if a == 0 and b == 0:",
"+ continue",
"- result *= pow(2, i + j, 1000000007) + pow(2, k + l, 1000000007) - 1",
"- result %= 1000000007",
"+ result *= pow(2, i + j, m) + pow(2, k + l, m) - 1",
"+ result %= m",
"-result %= 1000000007",
"+result %= m"
] | false | 0.068147 | 0.103915 | 0.655802 |
[
"s719322819",
"s780719256"
] |
u339199690
|
p02959
|
python
|
s568022552
|
s746759753
| 163 | 144 | 20,680 | 19,228 |
Accepted
|
Accepted
| 11.66 |
import sys, heapq, bisect, math, fractions
from collections import deque
N = int(eval(input()))
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))
res = 0
for i, b in enumerate(B):
a = A[i]
a1 = A[i + 1]
if a >= b:
res += b
else:
res += a
if a1 >= b - a:
A[i + 1] = a1 - (b - a)
res += b - a
else:
A[i + 1] = 0
res += a1
print(res)
|
import sys
N = int(eval(input()))
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))
res = 0
for i, b in enumerate(B):
a = A[i]
a1 = A[i + 1]
if a >= b:
res += b
else:
res += a
if a1 >= b - a:
A[i + 1] = a1 - (b - a)
res += b - a
else:
A[i + 1] = 0
res += a1
print(res)
| 23 | 22 | 495 | 432 |
import sys, heapq, bisect, math, fractions
from collections import deque
N = int(eval(input()))
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))
res = 0
for i, b in enumerate(B):
a = A[i]
a1 = A[i + 1]
if a >= b:
res += b
else:
res += a
if a1 >= b - a:
A[i + 1] = a1 - (b - a)
res += b - a
else:
A[i + 1] = 0
res += a1
print(res)
|
import sys
N = int(eval(input()))
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))
res = 0
for i, b in enumerate(B):
a = A[i]
a1 = A[i + 1]
if a >= b:
res += b
else:
res += a
if a1 >= b - a:
A[i + 1] = a1 - (b - a)
res += b - a
else:
A[i + 1] = 0
res += a1
print(res)
| false | 4.347826 |
[
"-import sys, heapq, bisect, math, fractions",
"-from collections import deque",
"+import sys"
] | false | 0.041927 | 0.040759 | 1.028674 |
[
"s568022552",
"s746759753"
] |
u729535891
|
p03160
|
python
|
s457687030
|
s090442205
| 166 | 140 | 13,980 | 13,928 |
Accepted
|
Accepted
| 15.66 |
n = int(eval(input()))
h = list(map(int, input().split()))
def chmin(a, b):
if a > b:
return b
else:
return a
dp = [float('inf')] * n
dp[0] = 0
for i in range(0, n - 1):
dp[i + 1] = chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
if i < n - 2:
dp[i + 2] = chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print((dp[n - 1]))
|
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float('inf')] * (n + 10)
dp[0] = 0
def chmin(a, b):
if a < b:
return a
else:
return b
for i in range(n):
if i == 0:
dp[i + 1] = dp[i] + abs(h[i + 1] - h[i])
if i < n - 2:
dp[i + 2] = chmin(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i]))
print((dp[n - 1]))
| 16 | 17 | 369 | 398 |
n = int(eval(input()))
h = list(map(int, input().split()))
def chmin(a, b):
if a > b:
return b
else:
return a
dp = [float("inf")] * n
dp[0] = 0
for i in range(0, n - 1):
dp[i + 1] = chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
if i < n - 2:
dp[i + 2] = chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print((dp[n - 1]))
|
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf")] * (n + 10)
dp[0] = 0
def chmin(a, b):
if a < b:
return a
else:
return b
for i in range(n):
if i == 0:
dp[i + 1] = dp[i] + abs(h[i + 1] - h[i])
if i < n - 2:
dp[i + 2] = chmin(
dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i])
)
print((dp[n - 1]))
| false | 5.882353 |
[
"+dp = [float(\"inf\")] * (n + 10)",
"+dp[0] = 0",
"- if a > b:",
"+ if a < b:",
"+ return a",
"+ else:",
"- else:",
"- return a",
"-dp = [float(\"inf\")] * n",
"-dp[0] = 0",
"-for i in range(0, n - 1):",
"- dp[i + 1] = chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))",
"+for i in range(n):",
"+ if i == 0:",
"+ dp[i + 1] = dp[i] + abs(h[i + 1] - h[i])",
"- dp[i + 2] = chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))",
"+ dp[i + 2] = chmin(",
"+ dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i])",
"+ )"
] | false | 0.047354 | 0.047261 | 1.001966 |
[
"s457687030",
"s090442205"
] |
u347600233
|
p02911
|
python
|
s941332137
|
s533617903
| 252 | 175 | 10,980 | 15,976 |
Accepted
|
Accepted
| 30.56 |
n, k, q = map(int, input().split())
aq = [int(input()) for i in range(q)]
point = [k for i in range(n)]
correct_ans = [0] * n
for i in range(q):
correct_ans[aq[i] - 1] += 1
point = ['Yes' if p - (q - ca) > 0 else 'No' for (p, ca) in zip(point, correct_ans)]
print(*point, sep='\n')
|
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]
c = [0] * n
for ai in a:
c[ai - 1] += 1
ans = ['Yes' if k - q + ci > 0 else 'No' for ci in c]
print(*ans, sep='\n')
| 10 | 7 | 301 | 198 |
n, k, q = map(int, input().split())
aq = [int(input()) for i in range(q)]
point = [k for i in range(n)]
correct_ans = [0] * n
for i in range(q):
correct_ans[aq[i] - 1] += 1
point = ["Yes" if p - (q - ca) > 0 else "No" for (p, ca) in zip(point, correct_ans)]
print(*point, sep="\n")
|
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]
c = [0] * n
for ai in a:
c[ai - 1] += 1
ans = ["Yes" if k - q + ci > 0 else "No" for ci in c]
print(*ans, sep="\n")
| false | 30 |
[
"-aq = [int(input()) for i in range(q)]",
"-point = [k for i in range(n)]",
"-correct_ans = [0] * n",
"-for i in range(q):",
"- correct_ans[aq[i] - 1] += 1",
"-point = [\"Yes\" if p - (q - ca) > 0 else \"No\" for (p, ca) in zip(point, correct_ans)]",
"-print(*point, sep=\"\\n\")",
"+a = [int(input()) for i in range(q)]",
"+c = [0] * n",
"+for ai in a:",
"+ c[ai - 1] += 1",
"+ans = [\"Yes\" if k - q + ci > 0 else \"No\" for ci in c]",
"+print(*ans, sep=\"\\n\")"
] | false | 0.039489 | 0.04014 | 0.983779 |
[
"s941332137",
"s533617903"
] |
u844646164
|
p03111
|
python
|
s404641985
|
s962804916
| 797 | 269 | 82,192 | 46,812 |
Accepted
|
Accepted
| 66.25 |
N, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
used = [0]*N
global pattern
pattern = []
global ans
ans = float('inf')
def dfs(A):
global pattern
global ans
if len(A) == N:
pattern.append(A)
ans = min(ans, MP(A))
return
for i in range(4):
A.append(i)
dfs(A)
A.pop()
return
def MP(A):
group1 = []
group2 = []
group3 = []
for i in range(N):
if A[i] == 1:
group1 += [l[i]]
elif A[i] == 2:
group2 += [l[i]]
elif A[i] == 3:
group3 += [l[i]]
if len(group1) == 0 or len(group2) == 0 or len(group3) == 0:
return float('inf')
return calc(group1, a)+calc(group2, b)+calc(group3, c)
def calc(group, length):
res = float('inf')
for i in range(2**len(group)):
bag = []
for j in range(len(group)):
if (i>>j) & 1:
bag += [group[j]]
if len(bag) == 0:
continue
elif len(bag) == 1:
res = min(res, abs(length - bag[0]))
else:
res = min(res, abs(length - sum(group)) + 10*(len(group)-1))
return res
dfs([])
print(ans)
|
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
def dfs(cur, a, b, c):
if cur == N:
return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else float('inf')
ret0 = dfs(cur+1, a, b, c)
ret1 = dfs(cur+1, a+l[cur], b, c) + 10
ret2 = dfs(cur+1, a, b+l[cur], c) + 10
ret3 = dfs(cur+1, a, b, c+l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print((dfs(0, 0, 0, 0)))
| 58 | 15 | 1,293 | 448 |
N, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
used = [0] * N
global pattern
pattern = []
global ans
ans = float("inf")
def dfs(A):
global pattern
global ans
if len(A) == N:
pattern.append(A)
ans = min(ans, MP(A))
return
for i in range(4):
A.append(i)
dfs(A)
A.pop()
return
def MP(A):
group1 = []
group2 = []
group3 = []
for i in range(N):
if A[i] == 1:
group1 += [l[i]]
elif A[i] == 2:
group2 += [l[i]]
elif A[i] == 3:
group3 += [l[i]]
if len(group1) == 0 or len(group2) == 0 or len(group3) == 0:
return float("inf")
return calc(group1, a) + calc(group2, b) + calc(group3, c)
def calc(group, length):
res = float("inf")
for i in range(2 ** len(group)):
bag = []
for j in range(len(group)):
if (i >> j) & 1:
bag += [group[j]]
if len(bag) == 0:
continue
elif len(bag) == 1:
res = min(res, abs(length - bag[0]))
else:
res = min(res, abs(length - sum(group)) + 10 * (len(group) - 1))
return res
dfs([])
print(ans)
|
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
def dfs(cur, a, b, c):
if cur == N:
return (
abs(a - A) + abs(b - B) + abs(c - C) - 30
if min(a, b, c) > 0
else float("inf")
)
ret0 = dfs(cur + 1, a, b, c)
ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print((dfs(0, 0, 0, 0)))
| false | 74.137931 |
[
"-N, a, b, c = list(map(int, input().split()))",
"+N, A, B, C = list(map(int, input().split()))",
"-used = [0] * N",
"-global pattern",
"-pattern = []",
"-global ans",
"-ans = float(\"inf\")",
"-def dfs(A):",
"- global pattern",
"- global ans",
"- if len(A) == N:",
"- pattern.append(A)",
"- ans = min(ans, MP(A))",
"- return",
"- for i in range(4):",
"- A.append(i)",
"- dfs(A)",
"- A.pop()",
"- return",
"+def dfs(cur, a, b, c):",
"+ if cur == N:",
"+ return (",
"+ abs(a - A) + abs(b - B) + abs(c - C) - 30",
"+ if min(a, b, c) > 0",
"+ else float(\"inf\")",
"+ )",
"+ ret0 = dfs(cur + 1, a, b, c)",
"+ ret1 = dfs(cur + 1, a + l[cur], b, c) + 10",
"+ ret2 = dfs(cur + 1, a, b + l[cur], c) + 10",
"+ ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10",
"+ return min(ret0, ret1, ret2, ret3)",
"-def MP(A):",
"- group1 = []",
"- group2 = []",
"- group3 = []",
"- for i in range(N):",
"- if A[i] == 1:",
"- group1 += [l[i]]",
"- elif A[i] == 2:",
"- group2 += [l[i]]",
"- elif A[i] == 3:",
"- group3 += [l[i]]",
"- if len(group1) == 0 or len(group2) == 0 or len(group3) == 0:",
"- return float(\"inf\")",
"- return calc(group1, a) + calc(group2, b) + calc(group3, c)",
"-",
"-",
"-def calc(group, length):",
"- res = float(\"inf\")",
"- for i in range(2 ** len(group)):",
"- bag = []",
"- for j in range(len(group)):",
"- if (i >> j) & 1:",
"- bag += [group[j]]",
"- if len(bag) == 0:",
"- continue",
"- elif len(bag) == 1:",
"- res = min(res, abs(length - bag[0]))",
"- else:",
"- res = min(res, abs(length - sum(group)) + 10 * (len(group) - 1))",
"- return res",
"-",
"-",
"-dfs([])",
"-print(ans)",
"+print((dfs(0, 0, 0, 0)))"
] | false | 0.984001 | 0.083977 | 11.717519 |
[
"s404641985",
"s962804916"
] |
u811733736
|
p02389
|
python
|
s821361769
|
s688367121
| 40 | 30 | 7,552 | 7,664 |
Accepted
|
Accepted
| 25 |
if __name__ == '__main__':
key_in = eval(input())
data = key_in.split(' ')
height = int(data[0])
width = int(data[1])
area = height * width
perimeter = 2 * height + 2 * width
print(('{0} {1}'.format(area, perimeter)))
|
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_C&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
a, b = list(map(int, input().split()))
print((a*b, (a*2 + b*2)))
if __name__ == '__main__':
main(sys.argv[1:])
| 9 | 17 | 246 | 313 |
if __name__ == "__main__":
key_in = eval(input())
data = key_in.split(" ")
height = int(data[0])
width = int(data[1])
area = height * width
perimeter = 2 * height + 2 * width
print(("{0} {1}".format(area, perimeter)))
|
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_C&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
a, b = list(map(int, input().split()))
print((a * b, (a * 2 + b * 2)))
if __name__ == "__main__":
main(sys.argv[1:])
| false | 47.058824 |
[
"+# -*- coding: utf-8 -*-",
"+\"\"\"",
"+http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_C&lang=jp",
"+\"\"\"",
"+import sys",
"+from sys import stdin",
"+",
"+input = stdin.readline",
"+",
"+",
"+def main(args):",
"+ a, b = list(map(int, input().split()))",
"+ print((a * b, (a * 2 + b * 2)))",
"+",
"+",
"- key_in = eval(input())",
"- data = key_in.split(\" \")",
"- height = int(data[0])",
"- width = int(data[1])",
"- area = height * width",
"- perimeter = 2 * height + 2 * width",
"- print((\"{0} {1}\".format(area, perimeter)))",
"+ main(sys.argv[1:])"
] | false | 0.041999 | 0.086057 | 0.488037 |
[
"s821361769",
"s688367121"
] |
u588341295
|
p03290
|
python
|
s168781118
|
s521554407
| 55 | 47 | 3,444 | 3,444 |
Accepted
|
Accepted
| 14.55 |
# -*- coding: utf-8 -*-
""" ビット全検索をちゃんと使ってみる版 """
D, G = list(map(int, input().split()))
# 各点数問題毎の、全問解いた場合の回答数と得点を保持
class ScoreSet:
def __init__(self, times, score):
self.times = times
self.score = score
# 各パターン毎の、合計回答数と合計得点と、どの点数問題を全問解いたのかを保持
class ScoreSetSum:
def __init__(self, times, score, bool_list):
self.times = times
self.score = score
self.bool_list = bool_list
# 入力内容から、ScoreSetのリストを作成
scoreSetList = []
for i in range(D):
p, c = list(map(int, input().split()))
scoreSetList.append(ScoreSet(p, p*100*(i+1) + c))
# どの点数問題を全問解いたのかの各パターンの全網羅
# bool_lists = list(itertools.product([True, False], repeat=D))
# ビット数に応じた全パターン数のループ
bool_lists = []
for i in range(1<<D):
# あるパターンでの各ビットの0or1を見ていくループ
bool_lists.append([])
for j in range(D):
# 右ビットシフトした時の1桁目が1か0かで処理を分ける
if 1 & i>>j == 1:
bool_lists[i].append(True)
else:
bool_lists[i].append(False)
# パターン全網羅とScoreSetのリストから、ScoreSetSumのリストを作成
scoreSetSumList = []
for bool_list in bool_lists:
times_tmp = 0
score_tmp = 0
for i in range(len(bool_list)):
if bool_list[i]:
times_tmp += scoreSetList[i].times
score_tmp += scoreSetList[i].score
scoreSetSumList.append(ScoreSetSum(times_tmp, score_tmp, bool_list))
# ScoreSetSumのリストを元に、適切なパターンを探していく
ans = float("inf")
for scoreSetSum in scoreSetSumList:
tmp = float("inf")
# 得点が既にG以上であれば、そのままその回答数が候補
if scoreSetSum.score >= G:
tmp = scoreSetSum.times
else:
# 足りなかったら、全問解いていない点数問題から最も高いもの選ぶ
for i in range(D-1, -1, -1):
if scoreSetSum.bool_list[i] == False:
score = scoreSetSum.score
times = scoreSetSum.times
# 選んだ点数問題を1問ずつ解いていく
for j in range(scoreSetList[i].times):
score += 100*(i+1)
times += 1
# G以上に達した時点で、その時の回答数が候補
if score >= G:
tmp = times
break
# 最後まで解いてもG以上にならなければ、このパターンは候補外
break
# 今までの最小と今回の候補を比較
ans = min(ans, tmp)
print(ans)
|
# -*- coding: utf-8 -*-
""" ビット全検索をちゃんと使ってみる版2 """
D, G = list(map(int, input().split()))
# 各点数問題毎の、全問解いた場合の回答数と得点を保持
class ScoreSet:
def __init__(self, times, score):
self.times = times
self.score = score
# 各パターン毎の、合計回答数と合計得点と、どの点数問題を全問解いたのかを保持
class ScoreSetSum:
def __init__(self, times, score, bool_list):
self.times = times
self.score = score
self.bool_list = bool_list
# 入力内容から、ScoreSetのリストを作成
scoreSetList = []
for i in range(D):
p, c = list(map(int, input().split()))
scoreSetList.append(ScoreSet(p, p*100*(i+1) + c))
# ビット全検索のループとScoreSetのリストから、ScoreSetSumのリストを作成
scoreSetSumList = []
for i in range(1<<D):
times_tmp = 0
score_tmp = 0
bool_list = []
for j in range(D):
if 1 & i>>j == 1:
times_tmp += scoreSetList[j].times
score_tmp += scoreSetList[j].score
bool_list.append(True)
else:
bool_list.append(False)
scoreSetSumList.append(ScoreSetSum(times_tmp, score_tmp, bool_list))
# ScoreSetSumのリストを元に、適切なパターンを探していく
ans = float("inf")
for scoreSetSum in scoreSetSumList:
tmp = float("inf")
# 得点が既にG以上であれば、そのままその回答数が候補
if scoreSetSum.score >= G:
tmp = scoreSetSum.times
else:
# 足りなかったら、全問解いていない点数問題から最も高いもの選ぶ
for i in range(D-1, -1, -1):
if scoreSetSum.bool_list[i] == False:
score = scoreSetSum.score
times = scoreSetSum.times
# 選んだ点数問題を1問ずつ解いていく
for j in range(scoreSetList[i].times):
score += 100*(i+1)
times += 1
# G以上に達した時点で、その時の回答数が候補
if score >= G:
tmp = times
break
# 最後まで解いてもG以上にならなければ、このパターンは候補外
break
# 今までの最小と今回の候補を比較
ans = min(ans, tmp)
print(ans)
| 78 | 67 | 2,267 | 1,956 |
# -*- coding: utf-8 -*-
""" ビット全検索をちゃんと使ってみる版 """
D, G = list(map(int, input().split()))
# 各点数問題毎の、全問解いた場合の回答数と得点を保持
class ScoreSet:
def __init__(self, times, score):
self.times = times
self.score = score
# 各パターン毎の、合計回答数と合計得点と、どの点数問題を全問解いたのかを保持
class ScoreSetSum:
def __init__(self, times, score, bool_list):
self.times = times
self.score = score
self.bool_list = bool_list
# 入力内容から、ScoreSetのリストを作成
scoreSetList = []
for i in range(D):
p, c = list(map(int, input().split()))
scoreSetList.append(ScoreSet(p, p * 100 * (i + 1) + c))
# どの点数問題を全問解いたのかの各パターンの全網羅
# bool_lists = list(itertools.product([True, False], repeat=D))
# ビット数に応じた全パターン数のループ
bool_lists = []
for i in range(1 << D):
# あるパターンでの各ビットの0or1を見ていくループ
bool_lists.append([])
for j in range(D):
# 右ビットシフトした時の1桁目が1か0かで処理を分ける
if 1 & i >> j == 1:
bool_lists[i].append(True)
else:
bool_lists[i].append(False)
# パターン全網羅とScoreSetのリストから、ScoreSetSumのリストを作成
scoreSetSumList = []
for bool_list in bool_lists:
times_tmp = 0
score_tmp = 0
for i in range(len(bool_list)):
if bool_list[i]:
times_tmp += scoreSetList[i].times
score_tmp += scoreSetList[i].score
scoreSetSumList.append(ScoreSetSum(times_tmp, score_tmp, bool_list))
# ScoreSetSumのリストを元に、適切なパターンを探していく
ans = float("inf")
for scoreSetSum in scoreSetSumList:
tmp = float("inf")
# 得点が既にG以上であれば、そのままその回答数が候補
if scoreSetSum.score >= G:
tmp = scoreSetSum.times
else:
# 足りなかったら、全問解いていない点数問題から最も高いもの選ぶ
for i in range(D - 1, -1, -1):
if scoreSetSum.bool_list[i] == False:
score = scoreSetSum.score
times = scoreSetSum.times
# 選んだ点数問題を1問ずつ解いていく
for j in range(scoreSetList[i].times):
score += 100 * (i + 1)
times += 1
# G以上に達した時点で、その時の回答数が候補
if score >= G:
tmp = times
break
# 最後まで解いてもG以上にならなければ、このパターンは候補外
break
# 今までの最小と今回の候補を比較
ans = min(ans, tmp)
print(ans)
|
# -*- coding: utf-8 -*-
""" ビット全検索をちゃんと使ってみる版2 """
D, G = list(map(int, input().split()))
# 各点数問題毎の、全問解いた場合の回答数と得点を保持
class ScoreSet:
def __init__(self, times, score):
self.times = times
self.score = score
# 各パターン毎の、合計回答数と合計得点と、どの点数問題を全問解いたのかを保持
class ScoreSetSum:
def __init__(self, times, score, bool_list):
self.times = times
self.score = score
self.bool_list = bool_list
# 入力内容から、ScoreSetのリストを作成
scoreSetList = []
for i in range(D):
p, c = list(map(int, input().split()))
scoreSetList.append(ScoreSet(p, p * 100 * (i + 1) + c))
# ビット全検索のループとScoreSetのリストから、ScoreSetSumのリストを作成
scoreSetSumList = []
for i in range(1 << D):
times_tmp = 0
score_tmp = 0
bool_list = []
for j in range(D):
if 1 & i >> j == 1:
times_tmp += scoreSetList[j].times
score_tmp += scoreSetList[j].score
bool_list.append(True)
else:
bool_list.append(False)
scoreSetSumList.append(ScoreSetSum(times_tmp, score_tmp, bool_list))
# ScoreSetSumのリストを元に、適切なパターンを探していく
ans = float("inf")
for scoreSetSum in scoreSetSumList:
tmp = float("inf")
# 得点が既にG以上であれば、そのままその回答数が候補
if scoreSetSum.score >= G:
tmp = scoreSetSum.times
else:
# 足りなかったら、全問解いていない点数問題から最も高いもの選ぶ
for i in range(D - 1, -1, -1):
if scoreSetSum.bool_list[i] == False:
score = scoreSetSum.score
times = scoreSetSum.times
# 選んだ点数問題を1問ずつ解いていく
for j in range(scoreSetList[i].times):
score += 100 * (i + 1)
times += 1
# G以上に達した時点で、その時の回答数が候補
if score >= G:
tmp = times
break
# 最後まで解いてもG以上にならなければ、このパターンは候補外
break
# 今までの最小と今回の候補を比較
ans = min(ans, tmp)
print(ans)
| false | 14.102564 |
[
"-\"\"\" ビット全検索をちゃんと使ってみる版 \"\"\"",
"+\"\"\" ビット全検索をちゃんと使ってみる版2 \"\"\"",
"-# どの点数問題を全問解いたのかの各パターンの全網羅",
"-# bool_lists = list(itertools.product([True, False], repeat=D))",
"-# ビット数に応じた全パターン数のループ",
"-bool_lists = []",
"+# ビット全検索のループとScoreSetのリストから、ScoreSetSumのリストを作成",
"+scoreSetSumList = []",
"- # あるパターンでの各ビットの0or1を見ていくループ",
"- bool_lists.append([])",
"- for j in range(D):",
"- # 右ビットシフトした時の1桁目が1か0かで処理を分ける",
"- if 1 & i >> j == 1:",
"- bool_lists[i].append(True)",
"- else:",
"- bool_lists[i].append(False)",
"-# パターン全網羅とScoreSetのリストから、ScoreSetSumのリストを作成",
"-scoreSetSumList = []",
"-for bool_list in bool_lists:",
"- for i in range(len(bool_list)):",
"- if bool_list[i]:",
"- times_tmp += scoreSetList[i].times",
"- score_tmp += scoreSetList[i].score",
"+ bool_list = []",
"+ for j in range(D):",
"+ if 1 & i >> j == 1:",
"+ times_tmp += scoreSetList[j].times",
"+ score_tmp += scoreSetList[j].score",
"+ bool_list.append(True)",
"+ else:",
"+ bool_list.append(False)"
] | false | 0.037497 | 0.037338 | 1.004252 |
[
"s168781118",
"s521554407"
] |
u077852398
|
p03814
|
python
|
s715760282
|
s509474565
| 53 | 30 | 10,548 | 9,316 |
Accepted
|
Accepted
| 43.4 |
s = list(eval(input()))
for i,j in enumerate(s):
if j == 'A':
a = i
break
for i,j in enumerate(s):
if j == 'Z':
z = i
print((z-a+1))
|
s = eval(input())
first = s.index('A')
end = s.rindex('Z')
ans = end - first + 1
print(ans)
| 10 | 7 | 166 | 93 |
s = list(eval(input()))
for i, j in enumerate(s):
if j == "A":
a = i
break
for i, j in enumerate(s):
if j == "Z":
z = i
print((z - a + 1))
|
s = eval(input())
first = s.index("A")
end = s.rindex("Z")
ans = end - first + 1
print(ans)
| false | 30 |
[
"-s = list(eval(input()))",
"-for i, j in enumerate(s):",
"- if j == \"A\":",
"- a = i",
"- break",
"-for i, j in enumerate(s):",
"- if j == \"Z\":",
"- z = i",
"-print((z - a + 1))",
"+s = eval(input())",
"+first = s.index(\"A\")",
"+end = s.rindex(\"Z\")",
"+ans = end - first + 1",
"+print(ans)"
] | false | 0.04134 | 0.038961 | 1.061079 |
[
"s715760282",
"s509474565"
] |
u835924161
|
p02780
|
python
|
s463764884
|
s511342994
| 175 | 152 | 25,060 | 25,060 |
Accepted
|
Accepted
| 13.14 |
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
for i in range(n):
A[i]+=1
for i in range(n-1):
A[i+1]+=A[i]
ans=0.0
A.reverse()
A.append(0)
A.reverse()
for i in range(n-k+1):
now=A[i+k]-A[i]
if now>ans:
ans=now
print((ans/2))
|
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
for i in range(n-1):
A[i+1]+=A[i]
ans=0.0
A.reverse()
A.append(0)
A.reverse()
for i in range(n-k+1):
now=A[i+k]-A[i]
if now>ans:
ans=now
print(((ans+k)/2))
| 19 | 17 | 284 | 255 |
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(n):
A[i] += 1
for i in range(n - 1):
A[i + 1] += A[i]
ans = 0.0
A.reverse()
A.append(0)
A.reverse()
for i in range(n - k + 1):
now = A[i + k] - A[i]
if now > ans:
ans = now
print((ans / 2))
|
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(n - 1):
A[i + 1] += A[i]
ans = 0.0
A.reverse()
A.append(0)
A.reverse()
for i in range(n - k + 1):
now = A[i + k] - A[i]
if now > ans:
ans = now
print(((ans + k) / 2))
| false | 10.526316 |
[
"-for i in range(n):",
"- A[i] += 1",
"-print((ans / 2))",
"+print(((ans + k) / 2))"
] | false | 0.046975 | 0.046635 | 1.007284 |
[
"s463764884",
"s511342994"
] |
u996952235
|
p03243
|
python
|
s658701052
|
s724592144
| 19 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10.53 |
for i in range(int(eval(input())), 1000):
if(str(i)[0] == str(i)[1] and str(i)[1] == str(i)[2]):
print(i)
break
|
n = int(eval(input()))
for i in range(n,1000):
if i % 111 == 0:
print(i)
break
| 4 | 6 | 118 | 84 |
for i in range(int(eval(input())), 1000):
if str(i)[0] == str(i)[1] and str(i)[1] == str(i)[2]:
print(i)
break
|
n = int(eval(input()))
for i in range(n, 1000):
if i % 111 == 0:
print(i)
break
| false | 33.333333 |
[
"-for i in range(int(eval(input())), 1000):",
"- if str(i)[0] == str(i)[1] and str(i)[1] == str(i)[2]:",
"+n = int(eval(input()))",
"+for i in range(n, 1000):",
"+ if i % 111 == 0:"
] | false | 0.040332 | 0.038883 | 1.037244 |
[
"s658701052",
"s724592144"
] |
u083960235
|
p03574
|
python
|
s345863165
|
s933682712
| 55 | 45 | 5,524 | 10,668 |
Accepted
|
Accepted
| 18.18 |
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
h, w = MAP()
# a = [[0] * (w + 2)] * (h + 2)
s = [list(eval(input())) for _ in range(h)]
dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
# スルー
num = 0
for d in range(8):
ni = i + dy[d]
nj = j + dx[d]
# niとnjで有効なのはsの定義域.
# ni w 0 <= ni <= w - 1
# nj h 0 <= nj <= h - 1
if ni < 0 or h <= ni:
continue
# スルー
if nj < 0 or w <= nj:
continue
# スールー
if s[ni][nj] == "#":
num += 1
s[i][j] = str(num)
# (num + "0")
for i in range(h):
print(("".join(s[i])))
|
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
H, W = MAP()
C = [input() for i in range(H)]
C = ["0"*(W+2)] + ["0"+C[i]+"0" for i in range(H)] + ["0"*(W+2)]
Z = [[0] * (W + 2) for i in range(H + 2)]
def surround_plus(i, j, Z):
dx = [0, 1, 1, 1, 0,-1,-1,-1]
dy = [1, 1, 0,-1,-1,-1, 0, 1]
for idx in range(8):
Z[i + dx[idx]][j + dy[idx]] += 1
return Z
for i in range(H + 2):
for j in range(W + 2):
if C[i][j] == "#":
Z = surround_plus(i, j, Z)
A = [[""] * W for i in range(H)]
for i in range(1, H + 1):
for j in range(1, W + 1):
if C[i][j] != "#":
A[i-1][j-1] = str(Z[i][j])
else:
A[i-1][j-1] = "#"
print(*["".join(a) for a in A], sep="\n")
| 54 | 48 | 1,551 | 1,494 |
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
h, w = MAP()
# a = [[0] * (w + 2)] * (h + 2)
s = [list(eval(input())) for _ in range(h)]
dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
# スルー
num = 0
for d in range(8):
ni = i + dy[d]
nj = j + dx[d]
# niとnjで有効なのはsの定義域.
# ni w 0 <= ni <= w - 1
# nj h 0 <= nj <= h - 1
if ni < 0 or h <= ni:
continue
# スルー
if nj < 0 or w <= nj:
continue
# スールー
if s[ni][nj] == "#":
num += 1
s[i][j] = str(num)
# (num + "0")
for i in range(h):
print(("".join(s[i])))
|
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right
def input():
return sys.stdin.readline().strip()
def INT():
return int(input())
def MAP():
return map(int, input().split())
def S_MAP():
return map(str, input().split())
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
H, W = MAP()
C = [input() for i in range(H)]
C = ["0" * (W + 2)] + ["0" + C[i] + "0" for i in range(H)] + ["0" * (W + 2)]
Z = [[0] * (W + 2) for i in range(H + 2)]
def surround_plus(i, j, Z):
dx = [0, 1, 1, 1, 0, -1, -1, -1]
dy = [1, 1, 0, -1, -1, -1, 0, 1]
for idx in range(8):
Z[i + dx[idx]][j + dy[idx]] += 1
return Z
for i in range(H + 2):
for j in range(W + 2):
if C[i][j] == "#":
Z = surround_plus(i, j, Z)
A = [[""] * W for i in range(H)]
for i in range(1, H + 1):
for j in range(1, W + 1):
if C[i][j] != "#":
A[i - 1][j - 1] = str(Z[i][j])
else:
A[i - 1][j - 1] = "#"
print(*["".join(a) for a in A], sep="\n")
| false | 11.111111 |
[
"+from bisect import bisect, bisect_left, bisect_right",
"- return int(eval(input()))",
"+ return int(input())",
"- return list(map(int, input().split()))",
"+ return map(int, input().split())",
"- return list(map(str, input().split()))",
"+ return map(str, input().split())",
"-h, w = MAP()",
"-# a = [[0] * (w + 2)] * (h + 2)",
"-s = [list(eval(input())) for _ in range(h)]",
"-dx = [1, 0, -1, 0, 1, -1, -1, 1]",
"-dy = [0, 1, 0, -1, 1, 1, -1, -1]",
"-for i in range(h):",
"- for j in range(w):",
"- if s[i][j] == \"#\":",
"- continue",
"- # スルー",
"- num = 0",
"- for d in range(8):",
"- ni = i + dy[d]",
"- nj = j + dx[d]",
"- # niとnjで有効なのはsの定義域.",
"- # ni w 0 <= ni <= w - 1",
"- # nj h 0 <= nj <= h - 1",
"- if ni < 0 or h <= ni:",
"- continue",
"- # スルー",
"- if nj < 0 or w <= nj:",
"- continue",
"- # スールー",
"- if s[ni][nj] == \"#\":",
"- num += 1",
"- s[i][j] = str(num)",
"- # (num + \"0\")",
"-for i in range(h):",
"- print((\"\".join(s[i])))",
"+H, W = MAP()",
"+C = [input() for i in range(H)]",
"+C = [\"0\" * (W + 2)] + [\"0\" + C[i] + \"0\" for i in range(H)] + [\"0\" * (W + 2)]",
"+Z = [[0] * (W + 2) for i in range(H + 2)]",
"+",
"+",
"+def surround_plus(i, j, Z):",
"+ dx = [0, 1, 1, 1, 0, -1, -1, -1]",
"+ dy = [1, 1, 0, -1, -1, -1, 0, 1]",
"+ for idx in range(8):",
"+ Z[i + dx[idx]][j + dy[idx]] += 1",
"+ return Z",
"+",
"+",
"+for i in range(H + 2):",
"+ for j in range(W + 2):",
"+ if C[i][j] == \"#\":",
"+ Z = surround_plus(i, j, Z)",
"+A = [[\"\"] * W for i in range(H)]",
"+for i in range(1, H + 1):",
"+ for j in range(1, W + 1):",
"+ if C[i][j] != \"#\":",
"+ A[i - 1][j - 1] = str(Z[i][j])",
"+ else:",
"+ A[i - 1][j - 1] = \"#\"",
"+print(*[\"\".join(a) for a in A], sep=\"\\n\")"
] | false | 0.041768 | 0.100335 | 0.416284 |
[
"s345863165",
"s933682712"
] |
u219417113
|
p02757
|
python
|
s292700359
|
s911195019
| 228 | 142 | 44,364 | 4,580 |
Accepted
|
Accepted
| 37.72 |
n, p = list(map(int, input().split()))
s = eval(input())
if 10 % p == 0:
ans = sum(i + 1 for i, x in enumerate(s) if int(x) % p == 0)
print(ans)
else:
counter = [0] * p
counter[0] = 1
cur = 0
p10 = 1
ans = 0
for x in s[::-1]:
cur = (cur + int(x) * p10) % p
ans += counter[cur]
counter[cur] += 1
p10 *= 10
p10 %= p
print(ans)
|
def main():
import sys
input = sys.stdin.readline
from collections import defaultdict
N, P = list(map(int, input().split()))
S = input().rstrip()
if P in (2, 5):
ans = 0
for i, c in enumerate(S):
if int(c) % P == 0:
ans += i + 1
print(ans)
sys.exit()
num = 0
d = 1
counter = defaultdict(int)
counter[0] += 1
for c in S[::-1]:
num += int(c) * d
num %= P
counter[num] += 1
d *= 10
d %= P
ans = 0
for v in list(counter.values()):
ans += (v * (v-1)) // 2
print(ans)
if __name__ == '__main__':
main()
| 20 | 30 | 410 | 681 |
n, p = list(map(int, input().split()))
s = eval(input())
if 10 % p == 0:
ans = sum(i + 1 for i, x in enumerate(s) if int(x) % p == 0)
print(ans)
else:
counter = [0] * p
counter[0] = 1
cur = 0
p10 = 1
ans = 0
for x in s[::-1]:
cur = (cur + int(x) * p10) % p
ans += counter[cur]
counter[cur] += 1
p10 *= 10
p10 %= p
print(ans)
|
def main():
import sys
input = sys.stdin.readline
from collections import defaultdict
N, P = list(map(int, input().split()))
S = input().rstrip()
if P in (2, 5):
ans = 0
for i, c in enumerate(S):
if int(c) % P == 0:
ans += i + 1
print(ans)
sys.exit()
num = 0
d = 1
counter = defaultdict(int)
counter[0] += 1
for c in S[::-1]:
num += int(c) * d
num %= P
counter[num] += 1
d *= 10
d %= P
ans = 0
for v in list(counter.values()):
ans += (v * (v - 1)) // 2
print(ans)
if __name__ == "__main__":
main()
| false | 33.333333 |
[
"-n, p = list(map(int, input().split()))",
"-s = eval(input())",
"-if 10 % p == 0:",
"- ans = sum(i + 1 for i, x in enumerate(s) if int(x) % p == 0)",
"+def main():",
"+ import sys",
"+",
"+ input = sys.stdin.readline",
"+ from collections import defaultdict",
"+",
"+ N, P = list(map(int, input().split()))",
"+ S = input().rstrip()",
"+ if P in (2, 5):",
"+ ans = 0",
"+ for i, c in enumerate(S):",
"+ if int(c) % P == 0:",
"+ ans += i + 1",
"+ print(ans)",
"+ sys.exit()",
"+ num = 0",
"+ d = 1",
"+ counter = defaultdict(int)",
"+ counter[0] += 1",
"+ for c in S[::-1]:",
"+ num += int(c) * d",
"+ num %= P",
"+ counter[num] += 1",
"+ d *= 10",
"+ d %= P",
"+ ans = 0",
"+ for v in list(counter.values()):",
"+ ans += (v * (v - 1)) // 2",
"-else:",
"- counter = [0] * p",
"- counter[0] = 1",
"- cur = 0",
"- p10 = 1",
"- ans = 0",
"- for x in s[::-1]:",
"- cur = (cur + int(x) * p10) % p",
"- ans += counter[cur]",
"- counter[cur] += 1",
"- p10 *= 10",
"- p10 %= p",
"- print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.153636 | 0.037874 | 4.056513 |
[
"s292700359",
"s911195019"
] |
u021019433
|
p03053
|
python
|
s908343605
|
s199907487
| 569 | 525 | 132,688 | 132,688 |
Accepted
|
Accepted
| 7.73 |
h, w = list(map(int, input().split()))
rb = [['#'] * (w + 2)]
a = rb + [list('#' + eval(input()) + '#') for _ in range(h)] + rb
p = [(i, j) for i in range(1, h + 1) for j in range(1, w + 1) if a[i][j] == '#']
d = (-1, 0), (1, 0), (0, -1), (0, 1)
r = -1
while p:
r += 1
s = []
for di, dj in d:
for i, j in p:
i += di
j += dj
if a[i][j] == '.':
a[i][j] = '#'
s.append((i, j))
p = s
print(r)
|
h, w = list(map(int, input().split()))
rb = [['#'] * (w + 2)]
a = rb + [list('#' + eval(input()) + '#') for _ in range(h)] + rb
p = [(i, j) for i in range(1, h + 1) for j in range(1, w + 1) if a[i][j] == '#']
d = (-1, 0), (1, 0), (0, -1), (0, 1)
r = -1
while p:
r += 1
s = []
for i, j in p:
for di, dj in d:
di += i
dj += j
if a[di][dj] == '.':
a[di][dj] = '#'
s.append((di, dj))
p = s
print(r)
| 18 | 18 | 485 | 491 |
h, w = list(map(int, input().split()))
rb = [["#"] * (w + 2)]
a = rb + [list("#" + eval(input()) + "#") for _ in range(h)] + rb
p = [(i, j) for i in range(1, h + 1) for j in range(1, w + 1) if a[i][j] == "#"]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
r = -1
while p:
r += 1
s = []
for di, dj in d:
for i, j in p:
i += di
j += dj
if a[i][j] == ".":
a[i][j] = "#"
s.append((i, j))
p = s
print(r)
|
h, w = list(map(int, input().split()))
rb = [["#"] * (w + 2)]
a = rb + [list("#" + eval(input()) + "#") for _ in range(h)] + rb
p = [(i, j) for i in range(1, h + 1) for j in range(1, w + 1) if a[i][j] == "#"]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
r = -1
while p:
r += 1
s = []
for i, j in p:
for di, dj in d:
di += i
dj += j
if a[di][dj] == ".":
a[di][dj] = "#"
s.append((di, dj))
p = s
print(r)
| false | 0 |
[
"- for di, dj in d:",
"- for i, j in p:",
"- i += di",
"- j += dj",
"- if a[i][j] == \".\":",
"- a[i][j] = \"#\"",
"- s.append((i, j))",
"+ for i, j in p:",
"+ for di, dj in d:",
"+ di += i",
"+ dj += j",
"+ if a[di][dj] == \".\":",
"+ a[di][dj] = \"#\"",
"+ s.append((di, dj))"
] | false | 0.03882 | 0.098075 | 0.395824 |
[
"s908343605",
"s199907487"
] |
u600402037
|
p02813
|
python
|
s413709201
|
s967455626
| 55 | 29 | 10,356 | 3,064 |
Accepted
|
Accepted
| 47.27 |
import sys
import itertools
import math
#import numpy as np
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
N = ri()
P = rl()
Q = rl()
L = []
for x in itertools.permutations(list(range(1, N+1))):
L.append(list(x))
a = 0
b = 0
for i in range(math.factorial(N)):
if L[i] == P:
a = i
if L[i] == Q:
b = i
print((abs(a-b)))
|
import sys
import itertools
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
P = tuple(lr())
Q = tuple(lr())
a = -1; b = -1
for i, x in enumerate(itertools.permutations(list(range(1, N+1)), N)):
if x == P:
a = i
if x == Q:
b = i
answer = abs(a-b)
print(answer)
| 26 | 19 | 506 | 368 |
import sys
import itertools
import math
# import numpy as np
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
N = ri()
P = rl()
Q = rl()
L = []
for x in itertools.permutations(list(range(1, N + 1))):
L.append(list(x))
a = 0
b = 0
for i in range(math.factorial(N)):
if L[i] == P:
a = i
if L[i] == Q:
b = i
print((abs(a - b)))
|
import sys
import itertools
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
P = tuple(lr())
Q = tuple(lr())
a = -1
b = -1
for i, x in enumerate(itertools.permutations(list(range(1, N + 1)), N)):
if x == P:
a = i
if x == Q:
b = i
answer = abs(a - b)
print(answer)
| false | 26.923077 |
[
"-import math",
"-# import numpy as np",
"-stdin = sys.stdin",
"-ri = lambda: int(rs())",
"-rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only",
"-rs = lambda: stdin.readline().rstrip() # ignore trailing spaces",
"-N = ri()",
"-P = rl()",
"-Q = rl()",
"-L = []",
"-for x in itertools.permutations(list(range(1, N + 1))):",
"- L.append(list(x))",
"-a = 0",
"-b = 0",
"-for i in range(math.factorial(N)):",
"- if L[i] == P:",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lambda: int(sr())",
"+lr = lambda: list(map(int, sr().split()))",
"+N = ir()",
"+P = tuple(lr())",
"+Q = tuple(lr())",
"+a = -1",
"+b = -1",
"+for i, x in enumerate(itertools.permutations(list(range(1, N + 1)), N)):",
"+ if x == P:",
"- if L[i] == Q:",
"+ if x == Q:",
"-print((abs(a - b)))",
"+answer = abs(a - b)",
"+print(answer)"
] | false | 0.133352 | 0.04045 | 3.296689 |
[
"s413709201",
"s967455626"
] |
u695811449
|
p03287
|
python
|
s924293235
|
s067681372
| 113 | 91 | 14,696 | 16,556 |
Accepted
|
Accepted
| 19.47 |
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(N):
S[i+1]=(A[i]+S[i])%M
def tr(k):
return k*(k-1)//2
S.sort()
S=[-1]+S+[-1]
count=0
ANS=0
for i in range(1,N+3):
if S[i]==S[i-1]:
count+=1
else:
ANS+=tr(count)
count=1
print(ANS)
|
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
SUM=[0]
for a in A:
SUM.append((SUM[-1]+a)%M)
from collections import Counter
counter=Counter(SUM)
ANS=0
for i in list(counter.values()):
ANS+=i*(i-1)//2
print(ANS)
| 28 | 15 | 346 | 246 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = (A[i] + S[i]) % M
def tr(k):
return k * (k - 1) // 2
S.sort()
S = [-1] + S + [-1]
count = 0
ANS = 0
for i in range(1, N + 3):
if S[i] == S[i - 1]:
count += 1
else:
ANS += tr(count)
count = 1
print(ANS)
|
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
SUM = [0]
for a in A:
SUM.append((SUM[-1] + a) % M)
from collections import Counter
counter = Counter(SUM)
ANS = 0
for i in list(counter.values()):
ANS += i * (i - 1) // 2
print(ANS)
| false | 46.428571 |
[
"-S = [0] * (N + 1)",
"-for i in range(N):",
"- S[i + 1] = (A[i] + S[i]) % M",
"+SUM = [0]",
"+for a in A:",
"+ SUM.append((SUM[-1] + a) % M)",
"+from collections import Counter",
"-",
"-def tr(k):",
"- return k * (k - 1) // 2",
"-",
"-",
"-S.sort()",
"-S = [-1] + S + [-1]",
"-count = 0",
"+counter = Counter(SUM)",
"-for i in range(1, N + 3):",
"- if S[i] == S[i - 1]:",
"- count += 1",
"- else:",
"- ANS += tr(count)",
"- count = 1",
"+for i in list(counter.values()):",
"+ ANS += i * (i - 1) // 2"
] | false | 0.09292 | 0.034071 | 2.727221 |
[
"s924293235",
"s067681372"
] |
u726615467
|
p03078
|
python
|
s480954743
|
s214308030
| 379 | 45 | 57,308 | 4,712 |
Accepted
|
Accepted
| 88.13 |
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]
import bisect, heapq
def myidx(x, y, z, X, Y, Z): return(x * (Y * X) + y * Z + z)
ans = 0
cnt = 0
score = A[0] + B[0] + C[0]
history = []
q = [(0, 0, 0, 0)]
while len(q) > 0:
penalty, x, y, z = heapq.heappop(q)
# print("#", penalty, x, y, z, history)
if x < X - 1:
idx_tmp = myidx(x + 1, y, z, X, Y, Z)
if idx_tmp not in history:
# print("##", x + 1, y, z)
heapq.heappush(history, idx_tmp)
#
penalty_tmp = penalty + (A[x] - A[x + 1])
heapq.heappush(q, (penalty_tmp, x + 1, y, z))
if y < Y - 1:
idx_tmp = myidx(x, y + 1, z, X, Y, Z)
if idx_tmp not in history:
# print("##", x, y + 1, z)
heapq.heappush(history, idx_tmp)
#
penalty_tmp = penalty + (B[y] - B[y + 1])
heapq.heappush(q, (penalty_tmp, x, y + 1, z))
if z < Z - 1:
idx_tmp = myidx(x, y, z + 1, X, Y, Z)
if idx_tmp not in history:
# print("##", x, y, z + 1)
heapq.heappush(history, idx_tmp)
#
penalty_tmp = penalty + (C[z] - C[z + 1])
heapq.heappush(q, (penalty_tmp, x, y, z + 1))
#
cnt += 1
print((score - penalty))
if cnt == K:
break
|
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]
import bisect, heapq
def myidx(x, y, z, X, Y, Z): return(x * (Y * X) + y * Z + z)
ans = 0
cnt = 0
score = A[0] + B[0] + C[0]
history = {}
q = [(0, 0, 0, 0)]
while len(q) > 0:
penalty, x, y, z = heapq.heappop(q)
# print("#", penalty, x, y, z, history)
if x < X - 1:
idx_tmp = myidx(x + 1, y, z, X, Y, Z)
if history.setdefault(str(idx_tmp), 0) == 0:
# print("##", x + 1, y, z)
history[str(idx_tmp)] = 1
#
penalty_tmp = penalty + (A[x] - A[x + 1])
heapq.heappush(q, (penalty_tmp, x + 1, y, z))
if y < Y - 1:
idx_tmp = myidx(x, y + 1, z, X, Y, Z)
if history.setdefault(str(idx_tmp), 0) == 0:
# print("##", x, y + 1, z)
history[str(idx_tmp)] = 1
#
penalty_tmp = penalty + (B[y] - B[y + 1])
heapq.heappush(q, (penalty_tmp, x, y + 1, z))
if z < Z - 1:
idx_tmp = myidx(x, y, z + 1, X, Y, Z)
if history.setdefault(str(idx_tmp), 0) == 0:
# print("##", x, y, z + 1)
history[str(idx_tmp)] = 1
#
penalty_tmp = penalty + (C[z] - C[z + 1])
heapq.heappush(q, (penalty_tmp, x, y, z + 1))
#
cnt += 1
print((score - penalty))
if cnt == K:
break
| 50 | 50 | 1,522 | 1,555 |
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]
import bisect, heapq
def myidx(x, y, z, X, Y, Z):
return x * (Y * X) + y * Z + z
ans = 0
cnt = 0
score = A[0] + B[0] + C[0]
history = []
q = [(0, 0, 0, 0)]
while len(q) > 0:
penalty, x, y, z = heapq.heappop(q)
# print("#", penalty, x, y, z, history)
if x < X - 1:
idx_tmp = myidx(x + 1, y, z, X, Y, Z)
if idx_tmp not in history:
# print("##", x + 1, y, z)
heapq.heappush(history, idx_tmp)
#
penalty_tmp = penalty + (A[x] - A[x + 1])
heapq.heappush(q, (penalty_tmp, x + 1, y, z))
if y < Y - 1:
idx_tmp = myidx(x, y + 1, z, X, Y, Z)
if idx_tmp not in history:
# print("##", x, y + 1, z)
heapq.heappush(history, idx_tmp)
#
penalty_tmp = penalty + (B[y] - B[y + 1])
heapq.heappush(q, (penalty_tmp, x, y + 1, z))
if z < Z - 1:
idx_tmp = myidx(x, y, z + 1, X, Y, Z)
if idx_tmp not in history:
# print("##", x, y, z + 1)
heapq.heappush(history, idx_tmp)
#
penalty_tmp = penalty + (C[z] - C[z + 1])
heapq.heappush(q, (penalty_tmp, x, y, z + 1))
#
cnt += 1
print((score - penalty))
if cnt == K:
break
|
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]
import bisect, heapq
def myidx(x, y, z, X, Y, Z):
return x * (Y * X) + y * Z + z
ans = 0
cnt = 0
score = A[0] + B[0] + C[0]
history = {}
q = [(0, 0, 0, 0)]
while len(q) > 0:
penalty, x, y, z = heapq.heappop(q)
# print("#", penalty, x, y, z, history)
if x < X - 1:
idx_tmp = myidx(x + 1, y, z, X, Y, Z)
if history.setdefault(str(idx_tmp), 0) == 0:
# print("##", x + 1, y, z)
history[str(idx_tmp)] = 1
#
penalty_tmp = penalty + (A[x] - A[x + 1])
heapq.heappush(q, (penalty_tmp, x + 1, y, z))
if y < Y - 1:
idx_tmp = myidx(x, y + 1, z, X, Y, Z)
if history.setdefault(str(idx_tmp), 0) == 0:
# print("##", x, y + 1, z)
history[str(idx_tmp)] = 1
#
penalty_tmp = penalty + (B[y] - B[y + 1])
heapq.heappush(q, (penalty_tmp, x, y + 1, z))
if z < Z - 1:
idx_tmp = myidx(x, y, z + 1, X, Y, Z)
if history.setdefault(str(idx_tmp), 0) == 0:
# print("##", x, y, z + 1)
history[str(idx_tmp)] = 1
#
penalty_tmp = penalty + (C[z] - C[z + 1])
heapq.heappush(q, (penalty_tmp, x, y, z + 1))
#
cnt += 1
print((score - penalty))
if cnt == K:
break
| false | 0 |
[
"-history = []",
"+history = {}",
"- if idx_tmp not in history:",
"+ if history.setdefault(str(idx_tmp), 0) == 0:",
"- heapq.heappush(history, idx_tmp)",
"+ history[str(idx_tmp)] = 1",
"- if idx_tmp not in history:",
"+ if history.setdefault(str(idx_tmp), 0) == 0:",
"- heapq.heappush(history, idx_tmp)",
"+ history[str(idx_tmp)] = 1",
"- if idx_tmp not in history:",
"+ if history.setdefault(str(idx_tmp), 0) == 0:",
"- heapq.heappush(history, idx_tmp)",
"+ history[str(idx_tmp)] = 1"
] | false | 0.036027 | 0.033872 | 1.063631 |
[
"s480954743",
"s214308030"
] |
u814986259
|
p02761
|
python
|
s232894644
|
s096484106
| 21 | 18 | 3,316 | 3,064 |
Accepted
|
Accepted
| 14.29 |
import collections
N, M = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for i in range(M)]
t = collections.defaultdict(int)
flag = True
for s, c in sc:
if s in t and t[s] != c:
flag = False
break
else:
t[s] = c
if flag:
ans = []
for i in range(1, N+1):
if i in t:
if i == 1 and t[i] == 0 and N > 1:
print((-1))
exit(0)
else:
ans.append(t[i])
else:
if i != 1:
ans.append(0)
else:
if N == 1:
ans.append(0)
else:
ans.append(1)
print(("".join(map(str, ans))))
else:
print((-1))
|
N,M=list(map(int,input().split()))
d = dict()
for i in range(M):
a,b=list(map(int,input().split()))
if a not in d:
d[a]=b
else:
if d[a]!=b:
print((-1))
exit(0)
tmp=0
for i in range(10):
if 3 in d and d[3] != i:
continue
for j in range(10):
if 2 in d and d[2] != j:
continue
for k in range(10):
if N!=1 and k ==0:
continue
if 1 in d and d[1]!= k:
continue
print(((str(k)+str(j)+str(i))[:N]))
exit(0)
print((-1))
| 33 | 25 | 769 | 504 |
import collections
N, M = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for i in range(M)]
t = collections.defaultdict(int)
flag = True
for s, c in sc:
if s in t and t[s] != c:
flag = False
break
else:
t[s] = c
if flag:
ans = []
for i in range(1, N + 1):
if i in t:
if i == 1 and t[i] == 0 and N > 1:
print((-1))
exit(0)
else:
ans.append(t[i])
else:
if i != 1:
ans.append(0)
else:
if N == 1:
ans.append(0)
else:
ans.append(1)
print(("".join(map(str, ans))))
else:
print((-1))
|
N, M = list(map(int, input().split()))
d = dict()
for i in range(M):
a, b = list(map(int, input().split()))
if a not in d:
d[a] = b
else:
if d[a] != b:
print((-1))
exit(0)
tmp = 0
for i in range(10):
if 3 in d and d[3] != i:
continue
for j in range(10):
if 2 in d and d[2] != j:
continue
for k in range(10):
if N != 1 and k == 0:
continue
if 1 in d and d[1] != k:
continue
print(((str(k) + str(j) + str(i))[:N]))
exit(0)
print((-1))
| false | 24.242424 |
[
"-import collections",
"-",
"-sc = [tuple(map(int, input().split())) for i in range(M)]",
"-t = collections.defaultdict(int)",
"-flag = True",
"-for s, c in sc:",
"- if s in t and t[s] != c:",
"- flag = False",
"- break",
"+d = dict()",
"+for i in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ if a not in d:",
"+ d[a] = b",
"- t[s] = c",
"-if flag:",
"- ans = []",
"- for i in range(1, N + 1):",
"- if i in t:",
"- if i == 1 and t[i] == 0 and N > 1:",
"- print((-1))",
"- exit(0)",
"- else:",
"- ans.append(t[i])",
"- else:",
"- if i != 1:",
"- ans.append(0)",
"- else:",
"- if N == 1:",
"- ans.append(0)",
"- else:",
"- ans.append(1)",
"- print((\"\".join(map(str, ans))))",
"-else:",
"- print((-1))",
"+ if d[a] != b:",
"+ print((-1))",
"+ exit(0)",
"+tmp = 0",
"+for i in range(10):",
"+ if 3 in d and d[3] != i:",
"+ continue",
"+ for j in range(10):",
"+ if 2 in d and d[2] != j:",
"+ continue",
"+ for k in range(10):",
"+ if N != 1 and k == 0:",
"+ continue",
"+ if 1 in d and d[1] != k:",
"+ continue",
"+ print(((str(k) + str(j) + str(i))[:N]))",
"+ exit(0)",
"+print((-1))"
] | false | 0.045531 | 0.044181 | 1.030547 |
[
"s232894644",
"s096484106"
] |
u504836877
|
p03450
|
python
|
s328494373
|
s529955868
| 1,958 | 1,410 | 104,424 | 66,284 |
Accepted
|
Accepted
| 27.99 |
N,M = list(map(int, input().split()))
L = [0]*M
R = [0]*M
D = [0]*M
for i in range(M):
L[i], R[i], D[i] = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(M):
G[L[i]-1].append([R[i]-1, D[i]])
G[R[i]-1].append([L[i]-1, -D[i]])
ans = "Yes"
visited = ["?"]*N
for i in range(N):
if visited[i] == "?":
q = [[i, 0]]
visited[i] = 0
while len(q) > 0:
temp = q.pop(-1)
pos = temp[0]
d = temp[1]
for j in range(len(G[pos])):
if visited[G[pos][j][0]] == "?":
q.append([G[pos][j][0], d+G[pos][j][1]])
visited[G[pos][j][0]] = d+G[pos][j][1]
elif visited[G[pos][j][0]] != d+G[pos][j][1]:
ans = "No"
break
print(ans)
|
N,M = list(map(int, input().split()))
E = [[] for _ in range(N)]
for _ in range(M):
l,r,d = list(map(int, input().split()))
E[l-1].append((r-1, d))
E[r-1].append((l-1, -d))
from collections import deque
human = ["0"]*N
ans = "Yes"
for i in range(N):
if ans == "No":
break
if len(E[i]) == 0:
continue
if human[i] == "0":
human[i] = 0
q = deque([i])
while q:
temp = q.popleft()
for e in E[temp]:
if human[e[0]] == "0":
human[e[0]] = human[temp]+e[1]
q.append(e[0])
elif human[e[0]] != human[temp]+e[1]:
ans = "No"
break
else:
for e in E[i]:
if human[e[0]] != human[i]+e[1]:
ans = "No"
break
print(ans)
| 31 | 34 | 855 | 878 |
N, M = list(map(int, input().split()))
L = [0] * M
R = [0] * M
D = [0] * M
for i in range(M):
L[i], R[i], D[i] = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(M):
G[L[i] - 1].append([R[i] - 1, D[i]])
G[R[i] - 1].append([L[i] - 1, -D[i]])
ans = "Yes"
visited = ["?"] * N
for i in range(N):
if visited[i] == "?":
q = [[i, 0]]
visited[i] = 0
while len(q) > 0:
temp = q.pop(-1)
pos = temp[0]
d = temp[1]
for j in range(len(G[pos])):
if visited[G[pos][j][0]] == "?":
q.append([G[pos][j][0], d + G[pos][j][1]])
visited[G[pos][j][0]] = d + G[pos][j][1]
elif visited[G[pos][j][0]] != d + G[pos][j][1]:
ans = "No"
break
print(ans)
|
N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
for _ in range(M):
l, r, d = list(map(int, input().split()))
E[l - 1].append((r - 1, d))
E[r - 1].append((l - 1, -d))
from collections import deque
human = ["0"] * N
ans = "Yes"
for i in range(N):
if ans == "No":
break
if len(E[i]) == 0:
continue
if human[i] == "0":
human[i] = 0
q = deque([i])
while q:
temp = q.popleft()
for e in E[temp]:
if human[e[0]] == "0":
human[e[0]] = human[temp] + e[1]
q.append(e[0])
elif human[e[0]] != human[temp] + e[1]:
ans = "No"
break
else:
for e in E[i]:
if human[e[0]] != human[i] + e[1]:
ans = "No"
break
print(ans)
| false | 8.823529 |
[
"-L = [0] * M",
"-R = [0] * M",
"-D = [0] * M",
"-for i in range(M):",
"- L[i], R[i], D[i] = list(map(int, input().split()))",
"-G = [[] for _ in range(N)]",
"-for i in range(M):",
"- G[L[i] - 1].append([R[i] - 1, D[i]])",
"- G[R[i] - 1].append([L[i] - 1, -D[i]])",
"+E = [[] for _ in range(N)]",
"+for _ in range(M):",
"+ l, r, d = list(map(int, input().split()))",
"+ E[l - 1].append((r - 1, d))",
"+ E[r - 1].append((l - 1, -d))",
"+from collections import deque",
"+",
"+human = [\"0\"] * N",
"-visited = [\"?\"] * N",
"- if visited[i] == \"?\":",
"- q = [[i, 0]]",
"- visited[i] = 0",
"- while len(q) > 0:",
"- temp = q.pop(-1)",
"- pos = temp[0]",
"- d = temp[1]",
"- for j in range(len(G[pos])):",
"- if visited[G[pos][j][0]] == \"?\":",
"- q.append([G[pos][j][0], d + G[pos][j][1]])",
"- visited[G[pos][j][0]] = d + G[pos][j][1]",
"- elif visited[G[pos][j][0]] != d + G[pos][j][1]:",
"+ if ans == \"No\":",
"+ break",
"+ if len(E[i]) == 0:",
"+ continue",
"+ if human[i] == \"0\":",
"+ human[i] = 0",
"+ q = deque([i])",
"+ while q:",
"+ temp = q.popleft()",
"+ for e in E[temp]:",
"+ if human[e[0]] == \"0\":",
"+ human[e[0]] = human[temp] + e[1]",
"+ q.append(e[0])",
"+ elif human[e[0]] != human[temp] + e[1]:",
"+ else:",
"+ for e in E[i]:",
"+ if human[e[0]] != human[i] + e[1]:",
"+ ans = \"No\"",
"+ break"
] | false | 0.039331 | 0.03919 | 1.0036 |
[
"s328494373",
"s529955868"
] |
u738898077
|
p02678
|
python
|
s707751130
|
s947926032
| 841 | 755 | 38,408 | 36,044 |
Accepted
|
Accepted
| 10.23 |
from collections import deque
n,m, = list(map(int,input().split()))
# ab =[list(map(int,input().split())) for i in range(m)]
v = [[i,-1] for i in range(n+1)]
v[1][1] = 0
for i in range(m):
a,b = list(map(int,input().split()))
v[a].append(b)
v[b].append(a)
dq = deque([])
dq.append(v[1])
# print(v)
while dq:
t = list(deque.popleft(dq))
# print(t)
for i in t[1:]:
if v[i][1] == -1:
v[i][1] = t[0]
dq.append(v[i])
print("Yes")
for i in range(n-1):
print((v[i+2][1]))
|
from collections import deque
n,m = list(map(int,input().split()))
# ab = [list(map(int,input().split())) for i in range(m)]
v = [[0]]*2 + [[10**9] for i in range(n-1)]
# print(v)
for i in range(m):
a,b = list(map(int,input().split()))
v[a].append(b)
v[b].append(a)
q = deque([1])
# print(v)
while q:
temp = q.popleft()
for i in v[temp][1:]:
if v[i][0] == 10**9:
v[i][0] = temp
q.append(i)
print("Yes")
for i in v[2:]:
print((i[0]))
| 23 | 20 | 533 | 493 |
from collections import deque
(
n,
m,
) = list(map(int, input().split()))
# ab =[list(map(int,input().split())) for i in range(m)]
v = [[i, -1] for i in range(n + 1)]
v[1][1] = 0
for i in range(m):
a, b = list(map(int, input().split()))
v[a].append(b)
v[b].append(a)
dq = deque([])
dq.append(v[1])
# print(v)
while dq:
t = list(deque.popleft(dq))
# print(t)
for i in t[1:]:
if v[i][1] == -1:
v[i][1] = t[0]
dq.append(v[i])
print("Yes")
for i in range(n - 1):
print((v[i + 2][1]))
|
from collections import deque
n, m = list(map(int, input().split()))
# ab = [list(map(int,input().split())) for i in range(m)]
v = [[0]] * 2 + [[10**9] for i in range(n - 1)]
# print(v)
for i in range(m):
a, b = list(map(int, input().split()))
v[a].append(b)
v[b].append(a)
q = deque([1])
# print(v)
while q:
temp = q.popleft()
for i in v[temp][1:]:
if v[i][0] == 10**9:
v[i][0] = temp
q.append(i)
print("Yes")
for i in v[2:]:
print((i[0]))
| false | 13.043478 |
[
"-(",
"- n,",
"- m,",
"-) = list(map(int, input().split()))",
"-# ab =[list(map(int,input().split())) for i in range(m)]",
"-v = [[i, -1] for i in range(n + 1)]",
"-v[1][1] = 0",
"+n, m = list(map(int, input().split()))",
"+# ab = [list(map(int,input().split())) for i in range(m)]",
"+v = [[0]] * 2 + [[10**9] for i in range(n - 1)]",
"+# print(v)",
"-dq = deque([])",
"-dq.append(v[1])",
"+q = deque([1])",
"-while dq:",
"- t = list(deque.popleft(dq))",
"- # print(t)",
"- for i in t[1:]:",
"- if v[i][1] == -1:",
"- v[i][1] = t[0]",
"- dq.append(v[i])",
"+while q:",
"+ temp = q.popleft()",
"+ for i in v[temp][1:]:",
"+ if v[i][0] == 10**9:",
"+ v[i][0] = temp",
"+ q.append(i)",
"-for i in range(n - 1):",
"- print((v[i + 2][1]))",
"+for i in v[2:]:",
"+ print((i[0]))"
] | false | 0.035799 | 0.036183 | 0.989399 |
[
"s707751130",
"s947926032"
] |
u612721349
|
p03610
|
python
|
s536871274
|
s395822252
| 19 | 17 | 4,268 | 3,192 |
Accepted
|
Accepted
| 10.53 |
print(("".join(list(eval(input()))[::2])))
|
print((input()[::2]))
| 1 | 1 | 34 | 19 |
print(("".join(list(eval(input()))[::2])))
|
print((input()[::2]))
| false | 0 |
[
"-print((\"\".join(list(eval(input()))[::2])))",
"+print((input()[::2]))"
] | false | 0.039539 | 0.038525 | 1.026328 |
[
"s536871274",
"s395822252"
] |
u111365362
|
p03103
|
python
|
s491304440
|
s927416763
| 1,974 | 500 | 27,756 | 27,760 |
Accepted
|
Accepted
| 74.67 |
N,M = list(map(int,input().split()))
ab = []
for i in range(N):
ab += [list(map(int,input().split()))]
ab.sort()
rest = M
cost = 0
while True:
if rest - ab[0][1] <= 0:
cost += rest * ab[0][0]
break
else:
rest -= ab[0][1]
cost += ab[0][0] * ab[0][1]
del ab[0]
print(cost)
|
n,m = list(map(int,input().split()))
ab = []
for _ in range(n):
ab.append(list(map(int,input().split())))
ab.sort()
ans = 0
for i in range(n):
a,b = ab[i]
if m > b:
m -= b
ans += a * b
else:
ans += a * m
break
#print(m,ans)
print(ans)
| 16 | 16 | 305 | 269 |
N, M = list(map(int, input().split()))
ab = []
for i in range(N):
ab += [list(map(int, input().split()))]
ab.sort()
rest = M
cost = 0
while True:
if rest - ab[0][1] <= 0:
cost += rest * ab[0][0]
break
else:
rest -= ab[0][1]
cost += ab[0][0] * ab[0][1]
del ab[0]
print(cost)
|
n, m = list(map(int, input().split()))
ab = []
for _ in range(n):
ab.append(list(map(int, input().split())))
ab.sort()
ans = 0
for i in range(n):
a, b = ab[i]
if m > b:
m -= b
ans += a * b
else:
ans += a * m
break
# print(m,ans)
print(ans)
| false | 0 |
[
"-N, M = list(map(int, input().split()))",
"+n, m = list(map(int, input().split()))",
"-for i in range(N):",
"- ab += [list(map(int, input().split()))]",
"+for _ in range(n):",
"+ ab.append(list(map(int, input().split())))",
"-rest = M",
"-cost = 0",
"-while True:",
"- if rest - ab[0][1] <= 0:",
"- cost += rest * ab[0][0]",
"+ans = 0",
"+for i in range(n):",
"+ a, b = ab[i]",
"+ if m > b:",
"+ m -= b",
"+ ans += a * b",
"+ else:",
"+ ans += a * m",
"- else:",
"- rest -= ab[0][1]",
"- cost += ab[0][0] * ab[0][1]",
"- del ab[0]",
"-print(cost)",
"+ # print(m,ans)",
"+print(ans)"
] | false | 0.047761 | 0.075796 | 0.630134 |
[
"s491304440",
"s927416763"
] |
u546285759
|
p00025
|
python
|
s694480294
|
s709924697
| 30 | 20 | 7,636 | 7,712 |
Accepted
|
Accepted
| 33.33 |
while True:
try:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
hit = sum(1 for x, y in zip(a, b) if x == y)
hits = [x for x, y in zip(a, b) if x == y]
blow = sum(1 for x in a if x in b and x not in hits)
print((hit, blow))
except:
break
|
while True:
try:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
except:
break
print((sum(x == y for x, y in zip(a, b)), sum(a[i] != b[i] and a[i] in b for i in range(4))))
| 10 | 7 | 333 | 237 |
while True:
try:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
hit = sum(1 for x, y in zip(a, b) if x == y)
hits = [x for x, y in zip(a, b) if x == y]
blow = sum(1 for x in a if x in b and x not in hits)
print((hit, blow))
except:
break
|
while True:
try:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
except:
break
print(
(
sum(x == y for x, y in zip(a, b)),
sum(a[i] != b[i] and a[i] in b for i in range(4)),
)
)
| false | 30 |
[
"- hit = sum(1 for x, y in zip(a, b) if x == y)",
"- hits = [x for x, y in zip(a, b) if x == y]",
"- blow = sum(1 for x in a if x in b and x not in hits)",
"- print((hit, blow))",
"+ print(",
"+ (",
"+ sum(x == y for x, y in zip(a, b)),",
"+ sum(a[i] != b[i] and a[i] in b for i in range(4)),",
"+ )",
"+ )"
] | false | 0.042878 | 0.04223 | 1.015339 |
[
"s694480294",
"s709924697"
] |
u141786930
|
p02918
|
python
|
s482511472
|
s973857605
| 43 | 32 | 3,956 | 3,316 |
Accepted
|
Accepted
| 25.58 |
n, k = list(map(int, input().split()))
s = list(eval(input()))
h = 0
for i in range(1, len(s)):
if s[i-1] == s[i]:
h += 1
print((min(n-1, h+k*2)))
|
def main():
N, K = list(map(int,input().split()))
S = eval(input())
#幸せな人の数
h = 0
s1 = 'S'
for s in S:
if s == s1:
h += 1
s1 = s
print((min(h+(K*2) ,N-1)))
if __name__ == '__main__':
main()
| 9 | 16 | 163 | 254 |
n, k = list(map(int, input().split()))
s = list(eval(input()))
h = 0
for i in range(1, len(s)):
if s[i - 1] == s[i]:
h += 1
print((min(n - 1, h + k * 2)))
|
def main():
N, K = list(map(int, input().split()))
S = eval(input())
# 幸せな人の数
h = 0
s1 = "S"
for s in S:
if s == s1:
h += 1
s1 = s
print((min(h + (K * 2), N - 1)))
if __name__ == "__main__":
main()
| false | 43.75 |
[
"-n, k = list(map(int, input().split()))",
"-s = list(eval(input()))",
"-h = 0",
"-for i in range(1, len(s)):",
"- if s[i - 1] == s[i]:",
"- h += 1",
"-print((min(n - 1, h + k * 2)))",
"+def main():",
"+ N, K = list(map(int, input().split()))",
"+ S = eval(input())",
"+ # 幸せな人の数",
"+ h = 0",
"+ s1 = \"S\"",
"+ for s in S:",
"+ if s == s1:",
"+ h += 1",
"+ s1 = s",
"+ print((min(h + (K * 2), N - 1)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.037544 | 0.038785 | 0.968005 |
[
"s482511472",
"s973857605"
] |
u112364985
|
p02548
|
python
|
s647261574
|
s567676753
| 151 | 30 | 9,172 | 9,176 |
Accepted
|
Accepted
| 80.13 |
n=int(eval(input()))
cnt=0
for a in range(1,n):
cnt+=(n-1)//a
print(cnt)
|
n=int(eval(input()))
cnt=0
a=1
while(a*a<n):
cnt+=1
a+=1
a=1
while(a*a<n):
cnt+=max((n-1)//a-a,0)*2
a+=1
print(cnt)
| 5 | 11 | 74 | 135 |
n = int(eval(input()))
cnt = 0
for a in range(1, n):
cnt += (n - 1) // a
print(cnt)
|
n = int(eval(input()))
cnt = 0
a = 1
while a * a < n:
cnt += 1
a += 1
a = 1
while a * a < n:
cnt += max((n - 1) // a - a, 0) * 2
a += 1
print(cnt)
| false | 54.545455 |
[
"-for a in range(1, n):",
"- cnt += (n - 1) // a",
"+a = 1",
"+while a * a < n:",
"+ cnt += 1",
"+ a += 1",
"+a = 1",
"+while a * a < n:",
"+ cnt += max((n - 1) // a - a, 0) * 2",
"+ a += 1"
] | false | 0.067108 | 0.034334 | 1.954561 |
[
"s647261574",
"s567676753"
] |
u821624310
|
p02422
|
python
|
s403285930
|
s119088302
| 40 | 30 | 7,860 | 7,836 |
Accepted
|
Accepted
| 25 |
s = list(input())
q = int(input())
for i in range(q):
cmd = [s for s in input().split()]
cmd[1] = int(cmd[1])
cmd[2] = int(cmd[2])
if cmd[0] == "replace":
c = list(cmd[3])
h = 0
for j in range(cmd[1], cmd[2]+1):
s[j] = c[h]
h+=1
elif cmd[0] == "reverse":
k = cmd[1]
l = cmd[2]
while k < l:
t = s[k]
s[k] = s[l]
s[l] = t
k+=1
l-=1
else:
for m in range(cmd[1], cmd[2]+1):
print("{}".format(s[m]), end = "")
print()
|
str = [w for w in input()]
q = int(input())
for i in range(q):
command = [w for w in input().split()]
command[1] = int(command[1])
command[2] = int(command[2])
if command[0] == "print":
for i in range(command[1], command[2]+1):
print(str[i], end="")
print()
if command[0] == "replace":
j = command[1]
for i in range(len(command[3])):
str[j] = command[3][i]
j += 1
if command[0] == "reverse":
r = []
for i in range(command[2], command[1]-1, -1):
r.append(str[i])
i = command[1]
for w in r:
str[i] = w
i += 1
| 27 | 23 | 632 | 688 |
s = list(input())
q = int(input())
for i in range(q):
cmd = [s for s in input().split()]
cmd[1] = int(cmd[1])
cmd[2] = int(cmd[2])
if cmd[0] == "replace":
c = list(cmd[3])
h = 0
for j in range(cmd[1], cmd[2] + 1):
s[j] = c[h]
h += 1
elif cmd[0] == "reverse":
k = cmd[1]
l = cmd[2]
while k < l:
t = s[k]
s[k] = s[l]
s[l] = t
k += 1
l -= 1
else:
for m in range(cmd[1], cmd[2] + 1):
print("{}".format(s[m]), end="")
print()
|
str = [w for w in input()]
q = int(input())
for i in range(q):
command = [w for w in input().split()]
command[1] = int(command[1])
command[2] = int(command[2])
if command[0] == "print":
for i in range(command[1], command[2] + 1):
print(str[i], end="")
print()
if command[0] == "replace":
j = command[1]
for i in range(len(command[3])):
str[j] = command[3][i]
j += 1
if command[0] == "reverse":
r = []
for i in range(command[2], command[1] - 1, -1):
r.append(str[i])
i = command[1]
for w in r:
str[i] = w
i += 1
| false | 14.814815 |
[
"-s = list(input())",
"+str = [w for w in input()]",
"- cmd = [s for s in input().split()]",
"- cmd[1] = int(cmd[1])",
"- cmd[2] = int(cmd[2])",
"- if cmd[0] == \"replace\":",
"- c = list(cmd[3])",
"- h = 0",
"- for j in range(cmd[1], cmd[2] + 1):",
"- s[j] = c[h]",
"- h += 1",
"- elif cmd[0] == \"reverse\":",
"- k = cmd[1]",
"- l = cmd[2]",
"- while k < l:",
"- t = s[k]",
"- s[k] = s[l]",
"- s[l] = t",
"- k += 1",
"- l -= 1",
"- else:",
"- for m in range(cmd[1], cmd[2] + 1):",
"- print(\"{}\".format(s[m]), end=\"\")",
"+ command = [w for w in input().split()]",
"+ command[1] = int(command[1])",
"+ command[2] = int(command[2])",
"+ if command[0] == \"print\":",
"+ for i in range(command[1], command[2] + 1):",
"+ print(str[i], end=\"\")",
"+ if command[0] == \"replace\":",
"+ j = command[1]",
"+ for i in range(len(command[3])):",
"+ str[j] = command[3][i]",
"+ j += 1",
"+ if command[0] == \"reverse\":",
"+ r = []",
"+ for i in range(command[2], command[1] - 1, -1):",
"+ r.append(str[i])",
"+ i = command[1]",
"+ for w in r:",
"+ str[i] = w",
"+ i += 1"
] | false | 0.187467 | 0.041453 | 4.52236 |
[
"s403285930",
"s119088302"
] |
u125545880
|
p03575
|
python
|
s189442229
|
s229989027
| 31 | 23 | 3,564 | 3,064 |
Accepted
|
Accepted
| 25.81 |
import sys
import copy
readline = sys.stdin.readline
def dfs(p, x):
global graphtmp, check
to = graphtmp[x]
check[x] = 1
for t in to:
if p == t or check[t] == 1:
continue
dfs(x, t)
def main():
global graphtmp, check
N, M = list(map(int, readline().split()))
graph = [[] for _ in range(N)]
nodelist = []
for _ in range(M):
a, b = list(map(int, readline().split()))
a -= 1; b-= 1
nodelist.append([a, b])
graph[a].append(b)
graph[b].append(a)
ans = 0
for nodetmp in nodelist:
check = [0]*N
graphtmp = copy.deepcopy(graph)
graphtmp[nodetmp[0]].remove(nodetmp[1])
graphtmp[nodetmp[1]].remove(nodetmp[0])
dfs(-1, 0)
if 0 in check:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
import sys
readline = sys.stdin.readline
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
self.rank = [0] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.parents[x] = y
else:
self.parents[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
N, M = list(map(int, readline().split()))
nodelist = []
for _ in range(M):
a, b = list(map(int, readline().split()))
a -= 1; b -= 1
nodelist.append([a, b])
ans = 0
for i in range(M):
uf = UnionFind(N)
for j, node in enumerate(nodelist):
if j == i:
continue
uf.union(node[0], node[1])
parent = []
for k in range(N):
parent.append(uf.find(k))
if len(set(parent)) > 1:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 40 | 56 | 896 | 1,317 |
import sys
import copy
readline = sys.stdin.readline
def dfs(p, x):
global graphtmp, check
to = graphtmp[x]
check[x] = 1
for t in to:
if p == t or check[t] == 1:
continue
dfs(x, t)
def main():
global graphtmp, check
N, M = list(map(int, readline().split()))
graph = [[] for _ in range(N)]
nodelist = []
for _ in range(M):
a, b = list(map(int, readline().split()))
a -= 1
b -= 1
nodelist.append([a, b])
graph[a].append(b)
graph[b].append(a)
ans = 0
for nodetmp in nodelist:
check = [0] * N
graphtmp = copy.deepcopy(graph)
graphtmp[nodetmp[0]].remove(nodetmp[1])
graphtmp[nodetmp[1]].remove(nodetmp[0])
dfs(-1, 0)
if 0 in check:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
import sys
readline = sys.stdin.readline
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
self.rank = [0] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.parents[x] = y
else:
self.parents[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
N, M = list(map(int, readline().split()))
nodelist = []
for _ in range(M):
a, b = list(map(int, readline().split()))
a -= 1
b -= 1
nodelist.append([a, b])
ans = 0
for i in range(M):
uf = UnionFind(N)
for j, node in enumerate(nodelist):
if j == i:
continue
uf.union(node[0], node[1])
parent = []
for k in range(N):
parent.append(uf.find(k))
if len(set(parent)) > 1:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 28.571429 |
[
"-import copy",
"-def dfs(p, x):",
"- global graphtmp, check",
"- to = graphtmp[x]",
"- check[x] = 1",
"- for t in to:",
"- if p == t or check[t] == 1:",
"- continue",
"- dfs(x, t)",
"+class UnionFind:",
"+ def __init__(self, n):",
"+ self.n = n",
"+ self.parents = [-1] * n",
"+ self.rank = [0] * n",
"+",
"+ def find(self, x):",
"+ if self.parents[x] < 0:",
"+ return x",
"+ else:",
"+ self.parents[x] = self.find(self.parents[x])",
"+ return self.parents[x]",
"+",
"+ def union(self, x, y):",
"+ x = self.find(x)",
"+ y = self.find(y)",
"+ if x == y:",
"+ return",
"+ if self.rank[x] < self.rank[y]:",
"+ self.parents[x] = y",
"+ else:",
"+ self.parents[y] = x",
"+ if self.rank[x] == self.rank[y]:",
"+ self.rank[x] += 1",
"- global graphtmp, check",
"- graph = [[] for _ in range(N)]",
"- graph[a].append(b)",
"- graph[b].append(a)",
"- for nodetmp in nodelist:",
"- check = [0] * N",
"- graphtmp = copy.deepcopy(graph)",
"- graphtmp[nodetmp[0]].remove(nodetmp[1])",
"- graphtmp[nodetmp[1]].remove(nodetmp[0])",
"- dfs(-1, 0)",
"- if 0 in check:",
"+ for i in range(M):",
"+ uf = UnionFind(N)",
"+ for j, node in enumerate(nodelist):",
"+ if j == i:",
"+ continue",
"+ uf.union(node[0], node[1])",
"+ parent = []",
"+ for k in range(N):",
"+ parent.append(uf.find(k))",
"+ if len(set(parent)) > 1:"
] | false | 0.072041 | 0.031851 | 2.261816 |
[
"s189442229",
"s229989027"
] |
u727148417
|
p02773
|
python
|
s902795975
|
s144207538
| 835 | 529 | 53,476 | 35,952 |
Accepted
|
Accepted
| 36.65 |
N = int(eval(input()))
S = {}
A = [""]*N
for i in range(0, N):
A[i] = A[i] + eval(input())
for i in range(0, N):
if not (A[i] in list(S.keys())):
S[A[i]] = 1
else:
S[A[i]] = S[A[i]] + 1
max = 0
for value in list(S.values()):
if value > max:
max = value
S0 = {}
n = 0
for key, value in list(S.items()):
if value == max:
S0[key] = 0
n += 1
T = [""]*n
i = 0
for key in list(S0.keys()):
T[i] = key
i += 1
T.sort()
for p in range(0, n):
print((T[p]))
|
from collections import Counter
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
C = Counter(S)
dekai = max(C.values())
M = [kv[0] for kv in list(C.items()) if kv[1] == dekai]
M.sort()
A = '\n'.join(M)
print(A)
| 35 | 9 | 521 | 212 |
N = int(eval(input()))
S = {}
A = [""] * N
for i in range(0, N):
A[i] = A[i] + eval(input())
for i in range(0, N):
if not (A[i] in list(S.keys())):
S[A[i]] = 1
else:
S[A[i]] = S[A[i]] + 1
max = 0
for value in list(S.values()):
if value > max:
max = value
S0 = {}
n = 0
for key, value in list(S.items()):
if value == max:
S0[key] = 0
n += 1
T = [""] * n
i = 0
for key in list(S0.keys()):
T[i] = key
i += 1
T.sort()
for p in range(0, n):
print((T[p]))
|
from collections import Counter
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
C = Counter(S)
dekai = max(C.values())
M = [kv[0] for kv in list(C.items()) if kv[1] == dekai]
M.sort()
A = "\n".join(M)
print(A)
| false | 74.285714 |
[
"+from collections import Counter",
"+",
"-S = {}",
"-A = [\"\"] * N",
"-for i in range(0, N):",
"- A[i] = A[i] + eval(input())",
"-for i in range(0, N):",
"- if not (A[i] in list(S.keys())):",
"- S[A[i]] = 1",
"- else:",
"- S[A[i]] = S[A[i]] + 1",
"-max = 0",
"-for value in list(S.values()):",
"- if value > max:",
"- max = value",
"-S0 = {}",
"-n = 0",
"-for key, value in list(S.items()):",
"- if value == max:",
"- S0[key] = 0",
"- n += 1",
"-T = [\"\"] * n",
"-i = 0",
"-for key in list(S0.keys()):",
"- T[i] = key",
"- i += 1",
"-T.sort()",
"-for p in range(0, n):",
"- print((T[p]))",
"+S = [eval(input()) for i in range(N)]",
"+C = Counter(S)",
"+dekai = max(C.values())",
"+M = [kv[0] for kv in list(C.items()) if kv[1] == dekai]",
"+M.sort()",
"+A = \"\\n\".join(M)",
"+print(A)"
] | false | 0.036487 | 0.035404 | 1.030596 |
[
"s902795975",
"s144207538"
] |
u230621983
|
p02891
|
python
|
s513381997
|
s880758461
| 20 | 18 | 3,188 | 3,064 |
Accepted
|
Accepted
| 10 |
s = eval(input())
k = int(eval(input()))
if len(set(s)) == 1:
print(((len(s))*k//2))
exit()
first, last = s[0], s[-1]
first_flag = 1
a, b = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0
for i in range(len(s)):
c = s[i]
if c == first and first_flag:
a += 1
elif c != first:
first_flag = 0
if c == tmp:
tmp_cnt += 1
else:
cnt += (tmp_cnt // 2)
tmp_cnt = 1
tmp = c
if i == len(s) -1:
b = tmp_cnt
cnt += (tmp_cnt // 2)
if first != last:
ans = cnt * k
else:
ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1)
print(ans)
|
s = eval(input())
k = int(eval(input()))
if len(set(s)) == 1:
print(((len(s))*k//2))
exit()
first, last = s[0], s[-1]
first_flag = 1
a, b = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0
for i in range(len(s)):
c = s[i]
if c == first and first_flag: # 最初に続く文字数をカウント (a)
a += 1
elif c != first:
first_flag = 0
if c == tmp: # s単体のとき必要な操作回数を求める (cnt)
tmp_cnt += 1
else:
cnt += (tmp_cnt // 2)
tmp_cnt = 1
tmp = c
if i == len(s) -1: # 最後に続く文字数を取得 (b)
b = tmp_cnt
cnt += (tmp_cnt // 2)
if first != last: # sの最初の文字と最後の文字が違う場合
ans = cnt * k
else: # sの最初の文字と最後の文字が同じ場合
ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1)
print(ans)
| 37 | 38 | 637 | 758 |
s = eval(input())
k = int(eval(input()))
if len(set(s)) == 1:
print(((len(s)) * k // 2))
exit()
first, last = s[0], s[-1]
first_flag = 1
a, b = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0
for i in range(len(s)):
c = s[i]
if c == first and first_flag:
a += 1
elif c != first:
first_flag = 0
if c == tmp:
tmp_cnt += 1
else:
cnt += tmp_cnt // 2
tmp_cnt = 1
tmp = c
if i == len(s) - 1:
b = tmp_cnt
cnt += tmp_cnt // 2
if first != last:
ans = cnt * k
else:
ans = cnt * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1)
print(ans)
|
s = eval(input())
k = int(eval(input()))
if len(set(s)) == 1:
print(((len(s)) * k // 2))
exit()
first, last = s[0], s[-1]
first_flag = 1
a, b = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0
for i in range(len(s)):
c = s[i]
if c == first and first_flag: # 最初に続く文字数をカウント (a)
a += 1
elif c != first:
first_flag = 0
if c == tmp: # s単体のとき必要な操作回数を求める (cnt)
tmp_cnt += 1
else:
cnt += tmp_cnt // 2
tmp_cnt = 1
tmp = c
if i == len(s) - 1: # 最後に続く文字数を取得 (b)
b = tmp_cnt
cnt += tmp_cnt // 2
if first != last: # sの最初の文字と最後の文字が違う場合
ans = cnt * k
else: # sの最初の文字と最後の文字が同じ場合
ans = cnt * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1)
print(ans)
| false | 2.631579 |
[
"- if c == first and first_flag:",
"+ if c == first and first_flag: # 最初に続く文字数をカウント (a)",
"- if c == tmp:",
"+ if c == tmp: # s単体のとき必要な操作回数を求める (cnt)",
"- if i == len(s) - 1:",
"+ if i == len(s) - 1: # 最後に続く文字数を取得 (b)",
"-if first != last:",
"+if first != last: # sの最初の文字と最後の文字が違う場合",
"-else:",
"+else: # sの最初の文字と最後の文字が同じ場合"
] | false | 0.048304 | 0.048513 | 0.995695 |
[
"s513381997",
"s880758461"
] |
u969850098
|
p03457
|
python
|
s083408983
|
s350997741
| 373 | 332 | 3,064 | 3,060 |
Accepted
|
Accepted
| 10.99 |
import sys
N = int(eval(input()))
t, x, y = 0, 0, 0
for i in range(N):
in_t, in_x, in_y = list(map(int, input().split()))
t = in_t - t
x = abs(in_x - x)
y = abs(in_y - y)
if (t >= x + y) & ((t - (x + y)) % 2 == 0):
continue
print('No')
sys.exit()
print('Yes')
|
import sys
N = int(eval(input()))
for _ in range(N):
t, x, y = list(map(int, input().split()))
if (t >= x + y) & ((t - (x + y)) % 2 == 0):
continue
print('No')
sys.exit()
print('Yes')
| 13 | 9 | 295 | 204 |
import sys
N = int(eval(input()))
t, x, y = 0, 0, 0
for i in range(N):
in_t, in_x, in_y = list(map(int, input().split()))
t = in_t - t
x = abs(in_x - x)
y = abs(in_y - y)
if (t >= x + y) & ((t - (x + y)) % 2 == 0):
continue
print("No")
sys.exit()
print("Yes")
|
import sys
N = int(eval(input()))
for _ in range(N):
t, x, y = list(map(int, input().split()))
if (t >= x + y) & ((t - (x + y)) % 2 == 0):
continue
print("No")
sys.exit()
print("Yes")
| false | 30.769231 |
[
"-t, x, y = 0, 0, 0",
"-for i in range(N):",
"- in_t, in_x, in_y = list(map(int, input().split()))",
"- t = in_t - t",
"- x = abs(in_x - x)",
"- y = abs(in_y - y)",
"+for _ in range(N):",
"+ t, x, y = list(map(int, input().split()))"
] | false | 0.0479 | 0.047338 | 1.01187 |
[
"s083408983",
"s350997741"
] |
u860002137
|
p02983
|
python
|
s091378295
|
s796124585
| 724 | 58 | 75,412 | 6,808 |
Accepted
|
Accepted
| 91.99 |
import sys
L, R = list(map(int, input().split()))
ans = []
def calc_mod(x, y):
return x * y % 2019
left = L % 2019
right = R % 2019
if R-L > 2019:
print((0))
sys.exit(0)
elif left > right:
print((0))
sys.exit(0)
elif left==0 or right==0:
print((0))
sys.exit(0)
for i in range(left, right):
for j in range(i+1, right+1):
ans.append(calc_mod(i, j))
print((min(ans)))
|
import sys
L, R = list(map(int, input().split()))
ans = []
def calc_mod(x, y):
return x * y % 2019
left = L % 2019
right = R % 2019
if R-L > 2019:
print((0))
sys.exit(0)
elif left > right:
print((0))
sys.exit(0)
elif left==0 or right==0:
print((0))
sys.exit(0)
for i in range(left, right):
for j in range(i+1, right+1):
x = calc_mod(i, j)
if x==0:
print((0))
sys.exit(0)
ans.append(x)
print((min(ans)))
| 27 | 31 | 423 | 503 |
import sys
L, R = list(map(int, input().split()))
ans = []
def calc_mod(x, y):
return x * y % 2019
left = L % 2019
right = R % 2019
if R - L > 2019:
print((0))
sys.exit(0)
elif left > right:
print((0))
sys.exit(0)
elif left == 0 or right == 0:
print((0))
sys.exit(0)
for i in range(left, right):
for j in range(i + 1, right + 1):
ans.append(calc_mod(i, j))
print((min(ans)))
|
import sys
L, R = list(map(int, input().split()))
ans = []
def calc_mod(x, y):
return x * y % 2019
left = L % 2019
right = R % 2019
if R - L > 2019:
print((0))
sys.exit(0)
elif left > right:
print((0))
sys.exit(0)
elif left == 0 or right == 0:
print((0))
sys.exit(0)
for i in range(left, right):
for j in range(i + 1, right + 1):
x = calc_mod(i, j)
if x == 0:
print((0))
sys.exit(0)
ans.append(x)
print((min(ans)))
| false | 12.903226 |
[
"- ans.append(calc_mod(i, j))",
"+ x = calc_mod(i, j)",
"+ if x == 0:",
"+ print((0))",
"+ sys.exit(0)",
"+ ans.append(x)"
] | false | 0.036138 | 0.036625 | 0.986701 |
[
"s091378295",
"s796124585"
] |
u883048396
|
p04013
|
python
|
s672642393
|
s115983268
| 30 | 25 | 3,572 | 3,444 |
Accepted
|
Accepted
| 16.67 |
#人のすなるCounterなるものを我も書いてみんとてするなり
from collections import Counter
#方針 マイナスとプラスでDPを分割
iN,iA =[int(x) for x in input().split()]
aX = [int(x) - iA for x in input().split()]
aPlus = [x for x in aX if 0 < x ]
aMinus = [-1 * x for x in aX if x < 0 ]
iLenPlus = len(aPlus)
iLenMinus = len(aMinus)
iLen0 = iN - iLenPlus - iLenMinus
#0の場合はnCkの累積和なので別に計算する
#知ってたわけではなく解析しててみつけた
iCZero = 2**iLen0 - 1 #sum(k=1..N){nCk} = 2^n -1
iRet = 0
iRet += iCZero
iCZero += 1 #0の場合を追加
iUlim = min(sum(aPlus) , sum(aMinus))
if 0 < iUlim:
dp1 = Counter([0,aPlus[0]])
for i in range(1,iLenPlus):
iThisX = aPlus[i]
tmp = {}
for k, v in list(dp1.items()):
tmp[iThisX + k] = v
dp1 += tmp
dp2 = Counter([0,aMinus[0]])
for i in range(1,iLenMinus):
iThisX = aMinus[i]
tmp = {}
for k, v in list(dp2.items()):
tmp[iThisX + k] = v
dp2 += tmp
for i in range(1,iUlim+1):
iRet += iCZero * dp1[i] * dp2[i]
print(iRet)
|
def 解():
iN,iA =[int(x) for x in input().split()]
aX = [int(x) - iA for x in input().split()]
aPlus = [x for x in aX if 0 < x ]
aMinus = [-1 * x for x in aX if x < 0 ]
iLenPlus = len(aPlus)
iLenMinus = len(aMinus)
iLen0 = iN - iLenPlus - iLenMinus
iCZero = 2**iLen0 - 1 #sum(k=1..N){nCk} = 2^n -1
iRet = 0
iRet += iCZero
iCZero += 1 #0の場合を追加
iSumPlus = sum(aPlus)
iSumMinus = sum(aMinus)
iUlim = min(iSumPlus , iSumMinus)
iOlim = max(iSumPlus , iSumMinus)
if 0 < iUlim:
dp1 = [[0]*(iOlim +1) for _ in range(iLenPlus)]
dp1[0][0] = 1
dp1[0][aPlus[0]]=1
for j in range(1,iLenPlus):
for k in range(iUlim + 1):
if k < aPlus[j] :
dp1[j][k] = dp1[j-1][k]
else:
dp1[j][k] = dp1[j-1][k] + dp1[j-1][k-aPlus[j]]
dp2 = [[0]*(iOlim +1) for _ in range(iLenMinus)]
dp2[0][0] = 1
dp2[0][aMinus[0]]=1
for j in range(1,iLenMinus):
for k in range(iUlim + 1):
if k < aMinus[j] :
dp2[j][k] = dp2[j-1][k]
else:
dp2[j][k] = dp2[j-1][k] + dp2[j-1][k-aMinus[j]]
for i in range(1,iUlim+1):
iRet += iCZero * dp1[-1][i] * dp2[-1][i]
print(iRet)
解()
| 39 | 44 | 1,024 | 1,390 |
# 人のすなるCounterなるものを我も書いてみんとてするなり
from collections import Counter
# 方針 マイナスとプラスでDPを分割
iN, iA = [int(x) for x in input().split()]
aX = [int(x) - iA for x in input().split()]
aPlus = [x for x in aX if 0 < x]
aMinus = [-1 * x for x in aX if x < 0]
iLenPlus = len(aPlus)
iLenMinus = len(aMinus)
iLen0 = iN - iLenPlus - iLenMinus
# 0の場合はnCkの累積和なので別に計算する
# 知ってたわけではなく解析しててみつけた
iCZero = 2**iLen0 - 1 # sum(k=1..N){nCk} = 2^n -1
iRet = 0
iRet += iCZero
iCZero += 1 # 0の場合を追加
iUlim = min(sum(aPlus), sum(aMinus))
if 0 < iUlim:
dp1 = Counter([0, aPlus[0]])
for i in range(1, iLenPlus):
iThisX = aPlus[i]
tmp = {}
for k, v in list(dp1.items()):
tmp[iThisX + k] = v
dp1 += tmp
dp2 = Counter([0, aMinus[0]])
for i in range(1, iLenMinus):
iThisX = aMinus[i]
tmp = {}
for k, v in list(dp2.items()):
tmp[iThisX + k] = v
dp2 += tmp
for i in range(1, iUlim + 1):
iRet += iCZero * dp1[i] * dp2[i]
print(iRet)
|
def 解():
iN, iA = [int(x) for x in input().split()]
aX = [int(x) - iA for x in input().split()]
aPlus = [x for x in aX if 0 < x]
aMinus = [-1 * x for x in aX if x < 0]
iLenPlus = len(aPlus)
iLenMinus = len(aMinus)
iLen0 = iN - iLenPlus - iLenMinus
iCZero = 2**iLen0 - 1 # sum(k=1..N){nCk} = 2^n -1
iRet = 0
iRet += iCZero
iCZero += 1 # 0の場合を追加
iSumPlus = sum(aPlus)
iSumMinus = sum(aMinus)
iUlim = min(iSumPlus, iSumMinus)
iOlim = max(iSumPlus, iSumMinus)
if 0 < iUlim:
dp1 = [[0] * (iOlim + 1) for _ in range(iLenPlus)]
dp1[0][0] = 1
dp1[0][aPlus[0]] = 1
for j in range(1, iLenPlus):
for k in range(iUlim + 1):
if k < aPlus[j]:
dp1[j][k] = dp1[j - 1][k]
else:
dp1[j][k] = dp1[j - 1][k] + dp1[j - 1][k - aPlus[j]]
dp2 = [[0] * (iOlim + 1) for _ in range(iLenMinus)]
dp2[0][0] = 1
dp2[0][aMinus[0]] = 1
for j in range(1, iLenMinus):
for k in range(iUlim + 1):
if k < aMinus[j]:
dp2[j][k] = dp2[j - 1][k]
else:
dp2[j][k] = dp2[j - 1][k] + dp2[j - 1][k - aMinus[j]]
for i in range(1, iUlim + 1):
iRet += iCZero * dp1[-1][i] * dp2[-1][i]
print(iRet)
解()
| false | 11.363636 |
[
"-# 人のすなるCounterなるものを我も書いてみんとてするなり",
"-from collections import Counter",
"+def 解():",
"+ iN, iA = [int(x) for x in input().split()]",
"+ aX = [int(x) - iA for x in input().split()]",
"+ aPlus = [x for x in aX if 0 < x]",
"+ aMinus = [-1 * x for x in aX if x < 0]",
"+ iLenPlus = len(aPlus)",
"+ iLenMinus = len(aMinus)",
"+ iLen0 = iN - iLenPlus - iLenMinus",
"+ iCZero = 2**iLen0 - 1 # sum(k=1..N){nCk} = 2^n -1",
"+ iRet = 0",
"+ iRet += iCZero",
"+ iCZero += 1 # 0の場合を追加",
"+ iSumPlus = sum(aPlus)",
"+ iSumMinus = sum(aMinus)",
"+ iUlim = min(iSumPlus, iSumMinus)",
"+ iOlim = max(iSumPlus, iSumMinus)",
"+ if 0 < iUlim:",
"+ dp1 = [[0] * (iOlim + 1) for _ in range(iLenPlus)]",
"+ dp1[0][0] = 1",
"+ dp1[0][aPlus[0]] = 1",
"+ for j in range(1, iLenPlus):",
"+ for k in range(iUlim + 1):",
"+ if k < aPlus[j]:",
"+ dp1[j][k] = dp1[j - 1][k]",
"+ else:",
"+ dp1[j][k] = dp1[j - 1][k] + dp1[j - 1][k - aPlus[j]]",
"+ dp2 = [[0] * (iOlim + 1) for _ in range(iLenMinus)]",
"+ dp2[0][0] = 1",
"+ dp2[0][aMinus[0]] = 1",
"+ for j in range(1, iLenMinus):",
"+ for k in range(iUlim + 1):",
"+ if k < aMinus[j]:",
"+ dp2[j][k] = dp2[j - 1][k]",
"+ else:",
"+ dp2[j][k] = dp2[j - 1][k] + dp2[j - 1][k - aMinus[j]]",
"+ for i in range(1, iUlim + 1):",
"+ iRet += iCZero * dp1[-1][i] * dp2[-1][i]",
"+ print(iRet)",
"-# 方針 マイナスとプラスでDPを分割",
"-iN, iA = [int(x) for x in input().split()]",
"-aX = [int(x) - iA for x in input().split()]",
"-aPlus = [x for x in aX if 0 < x]",
"-aMinus = [-1 * x for x in aX if x < 0]",
"-iLenPlus = len(aPlus)",
"-iLenMinus = len(aMinus)",
"-iLen0 = iN - iLenPlus - iLenMinus",
"-# 0の場合はnCkの累積和なので別に計算する",
"-# 知ってたわけではなく解析しててみつけた",
"-iCZero = 2**iLen0 - 1 # sum(k=1..N){nCk} = 2^n -1",
"-iRet = 0",
"-iRet += iCZero",
"-iCZero += 1 # 0の場合を追加",
"-iUlim = min(sum(aPlus), sum(aMinus))",
"-if 0 < iUlim:",
"- dp1 = Counter([0, aPlus[0]])",
"- for i in range(1, iLenPlus):",
"- iThisX = aPlus[i]",
"- tmp = {}",
"- for k, v in list(dp1.items()):",
"- tmp[iThisX + k] = v",
"- dp1 += tmp",
"- dp2 = Counter([0, aMinus[0]])",
"- for i in range(1, iLenMinus):",
"- iThisX = aMinus[i]",
"- tmp = {}",
"- for k, v in list(dp2.items()):",
"- tmp[iThisX + k] = v",
"- dp2 += tmp",
"- for i in range(1, iUlim + 1):",
"- iRet += iCZero * dp1[i] * dp2[i]",
"-print(iRet)",
"+",
"+解()"
] | false | 0.05033 | 0.255532 | 0.196962 |
[
"s672642393",
"s115983268"
] |
u380524497
|
p02814
|
python
|
s762942340
|
s348353397
| 278 | 51 | 21,180 | 18,208 |
Accepted
|
Accepted
| 81.65 |
from math import gcd
from functools import reduce
import sys
input = sys.stdin.readline
def lcm(a, b):
return a*b // gcd(a, b)
def count_factor_2(num):
count = 0
while num % 2 == 0:
num //= 2
count += 1
return count
def main():
n, m = list(map(int, input().split()))
A = list([int(x)//2 for x in input().split()])
check = len(set(map(count_factor_2, A)))
if check != 1:
print((0))
return
lcm_a = reduce(lcm, A)
step = lcm_a * 2
ans = (m + lcm_a) // step
print(ans)
if __name__ == "__main__":
main()
|
from math import gcd
from functools import reduce
import sys
input = sys.stdin.readline
def lcm(a, b):
return a*b // gcd(a, b)
def count_factor_2(num):
count = 0
while num % 2 == 0:
num //= 2
count += 1
return count
def main():
n, m = list(map(int, input().split()))
A = list([x//2 for x in set(map(int, input().split()))])
check = len(set(map(count_factor_2, A)))
if check != 1:
print((0))
return
lcm_a = reduce(lcm, A)
step = lcm_a * 2
ans = (m + lcm_a) // step
print(ans)
if __name__ == "__main__":
main()
| 35 | 35 | 624 | 634 |
from math import gcd
from functools import reduce
import sys
input = sys.stdin.readline
def lcm(a, b):
return a * b // gcd(a, b)
def count_factor_2(num):
count = 0
while num % 2 == 0:
num //= 2
count += 1
return count
def main():
n, m = list(map(int, input().split()))
A = list([int(x) // 2 for x in input().split()])
check = len(set(map(count_factor_2, A)))
if check != 1:
print((0))
return
lcm_a = reduce(lcm, A)
step = lcm_a * 2
ans = (m + lcm_a) // step
print(ans)
if __name__ == "__main__":
main()
|
from math import gcd
from functools import reduce
import sys
input = sys.stdin.readline
def lcm(a, b):
return a * b // gcd(a, b)
def count_factor_2(num):
count = 0
while num % 2 == 0:
num //= 2
count += 1
return count
def main():
n, m = list(map(int, input().split()))
A = list([x // 2 for x in set(map(int, input().split()))])
check = len(set(map(count_factor_2, A)))
if check != 1:
print((0))
return
lcm_a = reduce(lcm, A)
step = lcm_a * 2
ans = (m + lcm_a) // step
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"- A = list([int(x) // 2 for x in input().split()])",
"+ A = list([x // 2 for x in set(map(int, input().split()))])"
] | false | 0.067457 | 0.047408 | 1.422915 |
[
"s762942340",
"s348353397"
] |
u050428930
|
p03310
|
python
|
s858236056
|
s471059396
| 859 | 673 | 25,972 | 25,972 |
Accepted
|
Accepted
| 21.65 |
from itertools import accumulate
N=int(eval(input()))
s=list(accumulate(list(map(int,input().split()))))
ans=s[-1]
p=0
q=2
for i in range(2,N-1):
while abs(s[i-1]-2*s[p])>abs(s[i-1]-2*s[p+1]):
p+=1
while abs(s[q]*2-s[i-1]-s[-1])>abs(s[q+1]*2-s[i-1]-s[-1]):
q+=1
t=[s[i-1]-s[p],s[p],s[q]-s[i-1],s[-1]-s[q]]
ans=min(ans,max(t)-min(t))
print(ans)
|
from itertools import accumulate
N=int(eval(input()))
s=list(accumulate(list(map(int,input().split()))))
def f(N,s):
ans=s[-1]
p=0
q=2
for i in range(2,N-1):
while abs(s[i-1]-2*s[p])>abs(s[i-1]-2*s[p+1]):
p+=1
while abs(s[q]*2-s[i-1]-s[-1])>abs(s[q+1]*2-s[i-1]-s[-1]):
q+=1
t=[s[i-1]-s[p],s[p],s[q]-s[i-1],s[-1]-s[q]]
ans=min(ans,max(t)-min(t))
print(ans)
return
f(N,s)
| 14 | 17 | 380 | 454 |
from itertools import accumulate
N = int(eval(input()))
s = list(accumulate(list(map(int, input().split()))))
ans = s[-1]
p = 0
q = 2
for i in range(2, N - 1):
while abs(s[i - 1] - 2 * s[p]) > abs(s[i - 1] - 2 * s[p + 1]):
p += 1
while abs(s[q] * 2 - s[i - 1] - s[-1]) > abs(s[q + 1] * 2 - s[i - 1] - s[-1]):
q += 1
t = [s[i - 1] - s[p], s[p], s[q] - s[i - 1], s[-1] - s[q]]
ans = min(ans, max(t) - min(t))
print(ans)
|
from itertools import accumulate
N = int(eval(input()))
s = list(accumulate(list(map(int, input().split()))))
def f(N, s):
ans = s[-1]
p = 0
q = 2
for i in range(2, N - 1):
while abs(s[i - 1] - 2 * s[p]) > abs(s[i - 1] - 2 * s[p + 1]):
p += 1
while abs(s[q] * 2 - s[i - 1] - s[-1]) > abs(s[q + 1] * 2 - s[i - 1] - s[-1]):
q += 1
t = [s[i - 1] - s[p], s[p], s[q] - s[i - 1], s[-1] - s[q]]
ans = min(ans, max(t) - min(t))
print(ans)
return
f(N, s)
| false | 17.647059 |
[
"-ans = s[-1]",
"-p = 0",
"-q = 2",
"-for i in range(2, N - 1):",
"- while abs(s[i - 1] - 2 * s[p]) > abs(s[i - 1] - 2 * s[p + 1]):",
"- p += 1",
"- while abs(s[q] * 2 - s[i - 1] - s[-1]) > abs(s[q + 1] * 2 - s[i - 1] - s[-1]):",
"- q += 1",
"- t = [s[i - 1] - s[p], s[p], s[q] - s[i - 1], s[-1] - s[q]]",
"- ans = min(ans, max(t) - min(t))",
"-print(ans)",
"+",
"+",
"+def f(N, s):",
"+ ans = s[-1]",
"+ p = 0",
"+ q = 2",
"+ for i in range(2, N - 1):",
"+ while abs(s[i - 1] - 2 * s[p]) > abs(s[i - 1] - 2 * s[p + 1]):",
"+ p += 1",
"+ while abs(s[q] * 2 - s[i - 1] - s[-1]) > abs(s[q + 1] * 2 - s[i - 1] - s[-1]):",
"+ q += 1",
"+ t = [s[i - 1] - s[p], s[p], s[q] - s[i - 1], s[-1] - s[q]]",
"+ ans = min(ans, max(t) - min(t))",
"+ print(ans)",
"+ return",
"+",
"+",
"+f(N, s)"
] | false | 0.095976 | 0.076017 | 1.262558 |
[
"s858236056",
"s471059396"
] |
u994521204
|
p02703
|
python
|
s707912703
|
s465861428
| 648 | 521 | 128,004 | 24,364 |
Accepted
|
Accepted
| 19.6 |
from heapq import heappush, heappop
infi = 10 ** 20
n, m, s = map(int, input().split())
s = min(s, 2500)
edges = [[] for _ in range(51 * 2501 + 1)]
# edge:1-50, max silver=0-2500
for _ in range(m):
u, v, a, b = map(int, input().split())
for i in range(a, 2501):
edges[v + 50 * i].append((b, u + 50 * (i - a)))
edges[u + 50 * i].append((b, v + 50 * (i - a)))
for edge_num in range(1, n + 1):
c, d = map(int, input().split())
# c枚, d分
for i in range(2501):
# 点edge_num+ i * 50のところに
if edge_num + (i + c) * 50 <= 51 * 2501:
edges[edge_num + i * 50].append((d, edge_num + min((i + c), 2500) * 50))
start = 1 + 50 * s
def dijkstra(edges, start):
time = [infi] * (51 * 2501 + 1)
used = [False] * (51 * 2501 + 1)
time[start] = 0
edgelist = []
heappush(edgelist, (0, start))
while edgelist:
nowtime, nowedge = heappop(edgelist)
if used[nowedge] is True:
continue
used[nowedge] = True
time[nowedge] = nowtime
for vt, v in edges[nowedge]:
if used[v] is True:
continue
newtime = nowtime + vt
heappush(edgelist, (newtime, v))
return time
time = dijkstra(edges, start)
ans = [infi] * (51)
for i in range(1, 51 * 2501 + 1):
temp = time[i]
a = i % 50
if a == 0:
a += 50
ans[a] = min(temp, ans[a])
print(*ans[2 : (n + 1)], sep="\n")
|
# snuke解説板
from heapq import heappush, heappop
infi = 10 ** 20
n, m, s = map(int, input().split())
s = min(s, n * 50)
edges = [[] for _ in range(n + 1)]
# edge:1-50, max silver=0-2500
for _ in range(m): # a円, b分
u, v, a, b = map(int, input().split())
edges[v].append((u, a, b))
edges[u].append((v, a, b))
exchange = [(0, 0)] * (n + 1)
for edge_num in range(1, n + 1): # c円, d分
c, d = map(int, input().split())
exchange[edge_num] = (c, d)
start = 1
# dp[i][j], 頂点iにお金jを持って到達する最低時間→時間に関してDAG
dp = [[infi] * (n * 50 + 1) for _ in range(n + 1)]
def dijkstra(edges, start, s, dp):
dp[start][s] = 0
edgelist = []
heappush(edgelist, (0, s, start)) # 時間, お金, 頂点
while edgelist:
nowtime, nowmoney, nowedge = heappop(edgelist)
# 遷移させる条件はedge,moneyの組み合わせに対してその時の最小値が出てきたときのみ→最小値以外は飛ばす。
if dp[nowedge][nowmoney] != nowtime:
continue
# 両替
deltamoney, deltatime = exchange[nowedge]
nextmoney = min(nowmoney + deltamoney, n * 50)
nexttime = nowtime + deltatime
if dp[nowedge][nextmoney] > nexttime:
dp[nowedge][nextmoney] = nexttime
heappush(edgelist, (nexttime, nextmoney, nowedge))
# 移動
for v, vmoney, vtime in edges[nowedge]:
nexttime = nowtime + vtime
nextmoney = nowmoney - vmoney
if nextmoney < 0:
continue
if dp[v][nextmoney] > nexttime:
dp[v][nextmoney] = nexttime
heappush(edgelist, (nexttime, nextmoney, v))
return dp
time = dijkstra(edges, start, s, dp)
ans = [infi] * (n + 1)
for i in range(1, n + 1):
for j in range(n * 50 + 1):
ans[i] = min(ans[i], dp[i][j])
print(*ans[2 : (n + 1)], sep="\n")
| 58 | 63 | 1,506 | 1,835 |
from heapq import heappush, heappop
infi = 10**20
n, m, s = map(int, input().split())
s = min(s, 2500)
edges = [[] for _ in range(51 * 2501 + 1)]
# edge:1-50, max silver=0-2500
for _ in range(m):
u, v, a, b = map(int, input().split())
for i in range(a, 2501):
edges[v + 50 * i].append((b, u + 50 * (i - a)))
edges[u + 50 * i].append((b, v + 50 * (i - a)))
for edge_num in range(1, n + 1):
c, d = map(int, input().split())
# c枚, d分
for i in range(2501):
# 点edge_num+ i * 50のところに
if edge_num + (i + c) * 50 <= 51 * 2501:
edges[edge_num + i * 50].append((d, edge_num + min((i + c), 2500) * 50))
start = 1 + 50 * s
def dijkstra(edges, start):
time = [infi] * (51 * 2501 + 1)
used = [False] * (51 * 2501 + 1)
time[start] = 0
edgelist = []
heappush(edgelist, (0, start))
while edgelist:
nowtime, nowedge = heappop(edgelist)
if used[nowedge] is True:
continue
used[nowedge] = True
time[nowedge] = nowtime
for vt, v in edges[nowedge]:
if used[v] is True:
continue
newtime = nowtime + vt
heappush(edgelist, (newtime, v))
return time
time = dijkstra(edges, start)
ans = [infi] * (51)
for i in range(1, 51 * 2501 + 1):
temp = time[i]
a = i % 50
if a == 0:
a += 50
ans[a] = min(temp, ans[a])
print(*ans[2 : (n + 1)], sep="\n")
|
# snuke解説板
from heapq import heappush, heappop
infi = 10**20
n, m, s = map(int, input().split())
s = min(s, n * 50)
edges = [[] for _ in range(n + 1)]
# edge:1-50, max silver=0-2500
for _ in range(m): # a円, b分
u, v, a, b = map(int, input().split())
edges[v].append((u, a, b))
edges[u].append((v, a, b))
exchange = [(0, 0)] * (n + 1)
for edge_num in range(1, n + 1): # c円, d分
c, d = map(int, input().split())
exchange[edge_num] = (c, d)
start = 1
# dp[i][j], 頂点iにお金jを持って到達する最低時間→時間に関してDAG
dp = [[infi] * (n * 50 + 1) for _ in range(n + 1)]
def dijkstra(edges, start, s, dp):
dp[start][s] = 0
edgelist = []
heappush(edgelist, (0, s, start)) # 時間, お金, 頂点
while edgelist:
nowtime, nowmoney, nowedge = heappop(edgelist)
# 遷移させる条件はedge,moneyの組み合わせに対してその時の最小値が出てきたときのみ→最小値以外は飛ばす。
if dp[nowedge][nowmoney] != nowtime:
continue
# 両替
deltamoney, deltatime = exchange[nowedge]
nextmoney = min(nowmoney + deltamoney, n * 50)
nexttime = nowtime + deltatime
if dp[nowedge][nextmoney] > nexttime:
dp[nowedge][nextmoney] = nexttime
heappush(edgelist, (nexttime, nextmoney, nowedge))
# 移動
for v, vmoney, vtime in edges[nowedge]:
nexttime = nowtime + vtime
nextmoney = nowmoney - vmoney
if nextmoney < 0:
continue
if dp[v][nextmoney] > nexttime:
dp[v][nextmoney] = nexttime
heappush(edgelist, (nexttime, nextmoney, v))
return dp
time = dijkstra(edges, start, s, dp)
ans = [infi] * (n + 1)
for i in range(1, n + 1):
for j in range(n * 50 + 1):
ans[i] = min(ans[i], dp[i][j])
print(*ans[2 : (n + 1)], sep="\n")
| false | 7.936508 |
[
"+# snuke解説板",
"-s = min(s, 2500)",
"-edges = [[] for _ in range(51 * 2501 + 1)]",
"+s = min(s, n * 50)",
"+edges = [[] for _ in range(n + 1)]",
"-for _ in range(m):",
"+for _ in range(m): # a円, b分",
"- for i in range(a, 2501):",
"- edges[v + 50 * i].append((b, u + 50 * (i - a)))",
"- edges[u + 50 * i].append((b, v + 50 * (i - a)))",
"-for edge_num in range(1, n + 1):",
"+ edges[v].append((u, a, b))",
"+ edges[u].append((v, a, b))",
"+exchange = [(0, 0)] * (n + 1)",
"+for edge_num in range(1, n + 1): # c円, d分",
"- # c枚, d分",
"- for i in range(2501):",
"- # 点edge_num+ i * 50のところに",
"- if edge_num + (i + c) * 50 <= 51 * 2501:",
"- edges[edge_num + i * 50].append((d, edge_num + min((i + c), 2500) * 50))",
"-start = 1 + 50 * s",
"+ exchange[edge_num] = (c, d)",
"+start = 1",
"+# dp[i][j], 頂点iにお金jを持って到達する最低時間→時間に関してDAG",
"+dp = [[infi] * (n * 50 + 1) for _ in range(n + 1)]",
"-def dijkstra(edges, start):",
"- time = [infi] * (51 * 2501 + 1)",
"- used = [False] * (51 * 2501 + 1)",
"- time[start] = 0",
"+def dijkstra(edges, start, s, dp):",
"+ dp[start][s] = 0",
"- heappush(edgelist, (0, start))",
"+ heappush(edgelist, (0, s, start)) # 時間, お金, 頂点",
"- nowtime, nowedge = heappop(edgelist)",
"- if used[nowedge] is True:",
"+ nowtime, nowmoney, nowedge = heappop(edgelist)",
"+ # 遷移させる条件はedge,moneyの組み合わせに対してその時の最小値が出てきたときのみ→最小値以外は飛ばす。",
"+ if dp[nowedge][nowmoney] != nowtime:",
"- used[nowedge] = True",
"- time[nowedge] = nowtime",
"- for vt, v in edges[nowedge]:",
"- if used[v] is True:",
"+ # 両替",
"+ deltamoney, deltatime = exchange[nowedge]",
"+ nextmoney = min(nowmoney + deltamoney, n * 50)",
"+ nexttime = nowtime + deltatime",
"+ if dp[nowedge][nextmoney] > nexttime:",
"+ dp[nowedge][nextmoney] = nexttime",
"+ heappush(edgelist, (nexttime, nextmoney, nowedge))",
"+ # 移動",
"+ for v, vmoney, vtime in edges[nowedge]:",
"+ nexttime = nowtime + vtime",
"+ nextmoney = nowmoney - vmoney",
"+ if nextmoney < 0:",
"- newtime = nowtime + vt",
"- heappush(edgelist, (newtime, v))",
"- return time",
"+ if dp[v][nextmoney] > nexttime:",
"+ dp[v][nextmoney] = nexttime",
"+ heappush(edgelist, (nexttime, nextmoney, v))",
"+ return dp",
"-time = dijkstra(edges, start)",
"-ans = [infi] * (51)",
"-for i in range(1, 51 * 2501 + 1):",
"- temp = time[i]",
"- a = i % 50",
"- if a == 0:",
"- a += 50",
"- ans[a] = min(temp, ans[a])",
"+time = dijkstra(edges, start, s, dp)",
"+ans = [infi] * (n + 1)",
"+for i in range(1, n + 1):",
"+ for j in range(n * 50 + 1):",
"+ ans[i] = min(ans[i], dp[i][j])"
] | false | 0.234021 | 0.062591 | 3.738924 |
[
"s707912703",
"s465861428"
] |
u953110527
|
p03487
|
python
|
s095320556
|
s950112816
| 125 | 101 | 14,244 | 85,400 |
Accepted
|
Accepted
| 19.2 |
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
count = 1
ans = 0
for i in range(1,n):
if a[i] != a[i-1]:
if a[i-1] < count:
ans += count - a[i-1]
elif a[i-1] > count:
ans += count
count = 1
else:
count+=1
if a[n-1] < count:
ans += count - a[n-1]
elif a[n-1] > count:
ans += count
print(ans)
|
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
count = 1
ans = 0
for i in range(n-1):
if a[i+1] != a[i]:
if count >= a[i]:
ans += count-a[i]
else:
ans += count
count = 1
else:
count+=1
if count >= a[-1]:
ans += count-a[-1]
else:
ans += count
print(ans)
| 19 | 19 | 394 | 356 |
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
count = 1
ans = 0
for i in range(1, n):
if a[i] != a[i - 1]:
if a[i - 1] < count:
ans += count - a[i - 1]
elif a[i - 1] > count:
ans += count
count = 1
else:
count += 1
if a[n - 1] < count:
ans += count - a[n - 1]
elif a[n - 1] > count:
ans += count
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
count = 1
ans = 0
for i in range(n - 1):
if a[i + 1] != a[i]:
if count >= a[i]:
ans += count - a[i]
else:
ans += count
count = 1
else:
count += 1
if count >= a[-1]:
ans += count - a[-1]
else:
ans += count
print(ans)
| false | 0 |
[
"-for i in range(1, n):",
"- if a[i] != a[i - 1]:",
"- if a[i - 1] < count:",
"- ans += count - a[i - 1]",
"- elif a[i - 1] > count:",
"+for i in range(n - 1):",
"+ if a[i + 1] != a[i]:",
"+ if count >= a[i]:",
"+ ans += count - a[i]",
"+ else:",
"-if a[n - 1] < count:",
"- ans += count - a[n - 1]",
"-elif a[n - 1] > count:",
"+if count >= a[-1]:",
"+ ans += count - a[-1]",
"+else:"
] | false | 0.037914 | 0.03991 | 0.949997 |
[
"s095320556",
"s950112816"
] |
u314050667
|
p03557
|
python
|
s293615964
|
s709353019
| 1,154 | 950 | 23,348 | 24,836 |
Accepted
|
Accepted
| 17.68 |
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))
def BinaryIndexSearch_floor(p, SL):
"""
search the minimum number among the larger numbers than the ginven nymber "n".
return the index of it under the list sorted.
"""
#SL = sorted(L)
l = 0
r = len(SL) - 1
while True:
if l == r:
if SL[l] > p:
return l
else:
return -1
elif r-l == 1:
if SL[l] > p:
return l
elif SL[r] > p:
return r
else:
return -1
center = l + ((r-l) // 2)
if SL[center] <= p:
l = center + 1
continue
else:
r = center
continue
def BinaryIndexSearch_ceil(p, SL):
#SL = sorted(L)
l = 0
r = len(SL) - 1
while True:
if l == r:
if SL[l] < p:
return l
else:
return -1
elif r-l == 1:
if SL[r] < p:
return r
elif SL[l] < p:
return l
else:
return -1
center = l + ((r-l) // 2)
if SL[center] < p:
l = center
continue
else:
r = center - 1
continue
min_A = A[0]
max_C = C[-1]
ans = 0
for b in B:
if not (min_A < b < max_C):
continue
a = BinaryIndexSearch_ceil(b,A)
c = BinaryIndexSearch_floor(b,C)
ans += (a+1) * (N-c)
print(ans)
|
import numpy as np
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
A = np.array(A)
B = list(map(int, input().split()))
B.sort()
B = np.array(B)
C = list(map(int, input().split()))
C.sort()
C = np.array(C)
ans = 0
for i in range(N):
b = B[i]
a_ind = np.searchsorted(A,b,side='left')
c_ind = np.searchsorted(C,b,side='right')
ans += a_ind * (N-c_ind)
print(ans)
| 79 | 20 | 1,299 | 398 |
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))
def BinaryIndexSearch_floor(p, SL):
"""
search the minimum number among the larger numbers than the ginven nymber "n".
return the index of it under the list sorted.
"""
# SL = sorted(L)
l = 0
r = len(SL) - 1
while True:
if l == r:
if SL[l] > p:
return l
else:
return -1
elif r - l == 1:
if SL[l] > p:
return l
elif SL[r] > p:
return r
else:
return -1
center = l + ((r - l) // 2)
if SL[center] <= p:
l = center + 1
continue
else:
r = center
continue
def BinaryIndexSearch_ceil(p, SL):
# SL = sorted(L)
l = 0
r = len(SL) - 1
while True:
if l == r:
if SL[l] < p:
return l
else:
return -1
elif r - l == 1:
if SL[r] < p:
return r
elif SL[l] < p:
return l
else:
return -1
center = l + ((r - l) // 2)
if SL[center] < p:
l = center
continue
else:
r = center - 1
continue
min_A = A[0]
max_C = C[-1]
ans = 0
for b in B:
if not (min_A < b < max_C):
continue
a = BinaryIndexSearch_ceil(b, A)
c = BinaryIndexSearch_floor(b, C)
ans += (a + 1) * (N - c)
print(ans)
|
import numpy as np
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
A = np.array(A)
B = list(map(int, input().split()))
B.sort()
B = np.array(B)
C = list(map(int, input().split()))
C.sort()
C = np.array(C)
ans = 0
for i in range(N):
b = B[i]
a_ind = np.searchsorted(A, b, side="left")
c_ind = np.searchsorted(C, b, side="right")
ans += a_ind * (N - c_ind)
print(ans)
| false | 74.683544 |
[
"+import numpy as np",
"+",
"-A = sorted(list(map(int, input().split())))",
"+A = list(map(int, input().split()))",
"+A.sort()",
"+A = np.array(A)",
"-C = sorted(list(map(int, input().split())))",
"-",
"-",
"-def BinaryIndexSearch_floor(p, SL):",
"- \"\"\"",
"- search the minimum number among the larger numbers than the ginven nymber \"n\".",
"- return the index of it under the list sorted.",
"- \"\"\"",
"- # SL = sorted(L)",
"- l = 0",
"- r = len(SL) - 1",
"- while True:",
"- if l == r:",
"- if SL[l] > p:",
"- return l",
"- else:",
"- return -1",
"- elif r - l == 1:",
"- if SL[l] > p:",
"- return l",
"- elif SL[r] > p:",
"- return r",
"- else:",
"- return -1",
"- center = l + ((r - l) // 2)",
"- if SL[center] <= p:",
"- l = center + 1",
"- continue",
"- else:",
"- r = center",
"- continue",
"-",
"-",
"-def BinaryIndexSearch_ceil(p, SL):",
"- # SL = sorted(L)",
"- l = 0",
"- r = len(SL) - 1",
"- while True:",
"- if l == r:",
"- if SL[l] < p:",
"- return l",
"- else:",
"- return -1",
"- elif r - l == 1:",
"- if SL[r] < p:",
"- return r",
"- elif SL[l] < p:",
"- return l",
"- else:",
"- return -1",
"- center = l + ((r - l) // 2)",
"- if SL[center] < p:",
"- l = center",
"- continue",
"- else:",
"- r = center - 1",
"- continue",
"-",
"-",
"-min_A = A[0]",
"-max_C = C[-1]",
"+B.sort()",
"+B = np.array(B)",
"+C = list(map(int, input().split()))",
"+C.sort()",
"+C = np.array(C)",
"-for b in B:",
"- if not (min_A < b < max_C):",
"- continue",
"- a = BinaryIndexSearch_ceil(b, A)",
"- c = BinaryIndexSearch_floor(b, C)",
"- ans += (a + 1) * (N - c)",
"+for i in range(N):",
"+ b = B[i]",
"+ a_ind = np.searchsorted(A, b, side=\"left\")",
"+ c_ind = np.searchsorted(C, b, side=\"right\")",
"+ ans += a_ind * (N - c_ind)"
] | false | 0.049126 | 0.179446 | 0.273764 |
[
"s293615964",
"s709353019"
] |
u620084012
|
p03998
|
python
|
s374256096
|
s557655445
| 38 | 17 | 3,064 | 3,064 |
Accepted
|
Accepted
| 55.26 |
A = str(eval(input()))
B = str(eval(input()))
C = str(eval(input()))
p = 0
while True:
if p == 0:
if A == "":
print("A")
exit()
if A[0] == "b":
p = 1
elif A[0] == "c":
p = 2
A = A[1:]
elif p == 1:
if B == "":
print("B")
exit()
if B[0] == "a":
p = 0
elif B[0] == "c":
p = 2
B = B[1:]
else:
if C == "":
print("C")
exit()
if C[0] == "b":
p = 1
elif C[0] == "a":
p = 0
C = C[1:]
|
A = [str(x) for x in eval(input())]
B = [str(x) for x in eval(input())]
C = [str(x) for x in eval(input())]
t = 0
c = ""
while True:
if t == 0:
if len(A) == 0:
print("A")
exit(0)
else:
c = A.pop(0)
elif t == 1:
if len(B) == 0:
print("B")
exit(0)
else:
c = B.pop(0)
else:
if len(C) == 0:
print("C")
exit(0)
else:
c = C.pop(0)
if c == "a":
t = 0
elif c == "b":
t = 1
else:
t = 2
| 34 | 31 | 644 | 594 |
A = str(eval(input()))
B = str(eval(input()))
C = str(eval(input()))
p = 0
while True:
if p == 0:
if A == "":
print("A")
exit()
if A[0] == "b":
p = 1
elif A[0] == "c":
p = 2
A = A[1:]
elif p == 1:
if B == "":
print("B")
exit()
if B[0] == "a":
p = 0
elif B[0] == "c":
p = 2
B = B[1:]
else:
if C == "":
print("C")
exit()
if C[0] == "b":
p = 1
elif C[0] == "a":
p = 0
C = C[1:]
|
A = [str(x) for x in eval(input())]
B = [str(x) for x in eval(input())]
C = [str(x) for x in eval(input())]
t = 0
c = ""
while True:
if t == 0:
if len(A) == 0:
print("A")
exit(0)
else:
c = A.pop(0)
elif t == 1:
if len(B) == 0:
print("B")
exit(0)
else:
c = B.pop(0)
else:
if len(C) == 0:
print("C")
exit(0)
else:
c = C.pop(0)
if c == "a":
t = 0
elif c == "b":
t = 1
else:
t = 2
| false | 8.823529 |
[
"-A = str(eval(input()))",
"-B = str(eval(input()))",
"-C = str(eval(input()))",
"-p = 0",
"+A = [str(x) for x in eval(input())]",
"+B = [str(x) for x in eval(input())]",
"+C = [str(x) for x in eval(input())]",
"+t = 0",
"+c = \"\"",
"- if p == 0:",
"- if A == \"\":",
"+ if t == 0:",
"+ if len(A) == 0:",
"- exit()",
"- if A[0] == \"b\":",
"- p = 1",
"- elif A[0] == \"c\":",
"- p = 2",
"- A = A[1:]",
"- elif p == 1:",
"- if B == \"\":",
"+ exit(0)",
"+ else:",
"+ c = A.pop(0)",
"+ elif t == 1:",
"+ if len(B) == 0:",
"- exit()",
"- if B[0] == \"a\":",
"- p = 0",
"- elif B[0] == \"c\":",
"- p = 2",
"- B = B[1:]",
"+ exit(0)",
"+ else:",
"+ c = B.pop(0)",
"- if C == \"\":",
"+ if len(C) == 0:",
"- exit()",
"- if C[0] == \"b\":",
"- p = 1",
"- elif C[0] == \"a\":",
"- p = 0",
"- C = C[1:]",
"+ exit(0)",
"+ else:",
"+ c = C.pop(0)",
"+ if c == \"a\":",
"+ t = 0",
"+ elif c == \"b\":",
"+ t = 1",
"+ else:",
"+ t = 2"
] | false | 0.046951 | 0.20456 | 0.229523 |
[
"s374256096",
"s557655445"
] |
u399616977
|
p02899
|
python
|
s705962026
|
s191731786
| 157 | 143 | 25,700 | 23,652 |
Accepted
|
Accepted
| 8.92 |
n=int(eval(input()))
l=[]
tem=list(map(int,input().split()))
for i in range(n):
l.append((tem[i],i+1))
print((" ".join(list([str(x[1]) for x in sorted(l,key=lambda x: x[0])]))))
|
n=int(eval(input()))
l=[]
tem=list(map(int,input().split()))
print((" ".join(list([str(x[1]) for x in sorted(zip(tem,list(range(1,n+1))),key=lambda x: x[0])]))))
| 7 | 6 | 185 | 159 |
n = int(eval(input()))
l = []
tem = list(map(int, input().split()))
for i in range(n):
l.append((tem[i], i + 1))
print((" ".join(list([str(x[1]) for x in sorted(l, key=lambda x: x[0])]))))
|
n = int(eval(input()))
l = []
tem = list(map(int, input().split()))
print(
(
" ".join(
list(
[
str(x[1])
for x in sorted(zip(tem, list(range(1, n + 1))), key=lambda x: x[0])
]
)
)
)
)
| false | 14.285714 |
[
"-for i in range(n):",
"- l.append((tem[i], i + 1))",
"-print((\" \".join(list([str(x[1]) for x in sorted(l, key=lambda x: x[0])]))))",
"+print(",
"+ (",
"+ \" \".join(",
"+ list(",
"+ [",
"+ str(x[1])",
"+ for x in sorted(zip(tem, list(range(1, n + 1))), key=lambda x: x[0])",
"+ ]",
"+ )",
"+ )",
"+ )",
"+)"
] | false | 0.118023 | 0.041458 | 2.846824 |
[
"s705962026",
"s191731786"
] |
u844789719
|
p02863
|
python
|
s967597855
|
s211094482
| 377 | 300 | 45,376 | 42,860 |
Accepted
|
Accepted
| 20.42 |
I = [int(_) for _ in open(0).read().split()]
N, T = I[:2]
A, B = I[2::2], I[3::2]
dp = [-1] * 6001
dp[0] = 0
for a, b in sorted(zip(A, B)):
dp_new = dp[:]
for k in range(T):
if dp[k] == -1:
continue
dp_new[k + a] = max(dp[k + a], dp[k] + b)
dp = dp_new
print((max(dp)))
|
I = [int(_) for _ in open(0).read().split()]
N, T = I[:2]
A, B = I[2::2], I[3::2]
dp = [-1] * 6001
dp[0] = 0
for a, b in sorted(zip(A, B)):
for k in range(T - 1, -1, -1):
if dp[k] == -1:
continue
dp[k + a] = max(dp[k + a], dp[k] + b)
print((max(dp)))
| 13 | 11 | 320 | 291 |
I = [int(_) for _ in open(0).read().split()]
N, T = I[:2]
A, B = I[2::2], I[3::2]
dp = [-1] * 6001
dp[0] = 0
for a, b in sorted(zip(A, B)):
dp_new = dp[:]
for k in range(T):
if dp[k] == -1:
continue
dp_new[k + a] = max(dp[k + a], dp[k] + b)
dp = dp_new
print((max(dp)))
|
I = [int(_) for _ in open(0).read().split()]
N, T = I[:2]
A, B = I[2::2], I[3::2]
dp = [-1] * 6001
dp[0] = 0
for a, b in sorted(zip(A, B)):
for k in range(T - 1, -1, -1):
if dp[k] == -1:
continue
dp[k + a] = max(dp[k + a], dp[k] + b)
print((max(dp)))
| false | 15.384615 |
[
"- dp_new = dp[:]",
"- for k in range(T):",
"+ for k in range(T - 1, -1, -1):",
"- dp_new[k + a] = max(dp[k + a], dp[k] + b)",
"- dp = dp_new",
"+ dp[k + a] = max(dp[k + a], dp[k] + b)"
] | false | 0.032246 | 0.048597 | 0.663543 |
[
"s967597855",
"s211094482"
] |
u983918956
|
p03078
|
python
|
s116091626
|
s168988660
| 722 | 35 | 8,708 | 5,104 |
Accepted
|
Accepted
| 95.15 |
import sys
input = sys.stdin.readline
X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
res = []
for i in range(X):
for j in range(Y):
sup = min(K //((i+1)*(j+1)),Z)
for k in range(sup):
res.append(A[i]+B[j]+C[k])
res.sort(reverse=True)
for ans in res[:K]:
print(ans)
|
from heapq import heappush, heappop
X, Y, Z, K = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
C = sorted(list(map(int,input().split())),reverse=True)
ans_list = []
s = set()
pq = []
item = (-(A[0]+B[0]+C[0]),0,0,0)
heappush(pq,item)
for _ in range(K):
value, i, j, k = heappop(pq)
ans_list.append(-value)
if len(ans_list) == K:
break
if i <= X-2 and (i+1,j,k) not in s:
item = (-(A[i+1]+B[j]+C[k]),i+1,j,k)
heappush(pq,item)
s.add((i+1,j,k))
if j <= Y-2 and (i,j+1,k) not in s:
item = (-(A[i]+B[j+1]+C[k]),i,j+1,k)
heappush(pq,item)
s.add((i,j+1,k))
if k <= Z-2 and (i,j,k+1) not in s:
item = (-(A[i]+B[j]+C[k+1]),i,j,k+1)
heappush(pq,item)
s.add((i,j,k+1))
for ans in ans_list:
print(ans)
| 24 | 33 | 485 | 925 |
import sys
input = sys.stdin.readline
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
res = []
for i in range(X):
for j in range(Y):
sup = min(K // ((i + 1) * (j + 1)), Z)
for k in range(sup):
res.append(A[i] + B[j] + C[k])
res.sort(reverse=True)
for ans in res[:K]:
print(ans)
|
from heapq import heappush, heappop
X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
ans_list = []
s = set()
pq = []
item = (-(A[0] + B[0] + C[0]), 0, 0, 0)
heappush(pq, item)
for _ in range(K):
value, i, j, k = heappop(pq)
ans_list.append(-value)
if len(ans_list) == K:
break
if i <= X - 2 and (i + 1, j, k) not in s:
item = (-(A[i + 1] + B[j] + C[k]), i + 1, j, k)
heappush(pq, item)
s.add((i + 1, j, k))
if j <= Y - 2 and (i, j + 1, k) not in s:
item = (-(A[i] + B[j + 1] + C[k]), i, j + 1, k)
heappush(pq, item)
s.add((i, j + 1, k))
if k <= Z - 2 and (i, j, k + 1) not in s:
item = (-(A[i] + B[j] + C[k + 1]), i, j, k + 1)
heappush(pq, item)
s.add((i, j, k + 1))
for ans in ans_list:
print(ans)
| false | 27.272727 |
[
"-import sys",
"+from heapq import heappush, heappop",
"-input = sys.stdin.readline",
"-A = list(map(int, input().split()))",
"-B = list(map(int, input().split()))",
"-C = list(map(int, input().split()))",
"-A.sort(reverse=True)",
"-B.sort(reverse=True)",
"-C.sort(reverse=True)",
"-res = []",
"-for i in range(X):",
"- for j in range(Y):",
"- sup = min(K // ((i + 1) * (j + 1)), Z)",
"- for k in range(sup):",
"- res.append(A[i] + B[j] + C[k])",
"-res.sort(reverse=True)",
"-for ans in res[:K]:",
"+A = sorted(list(map(int, input().split())), reverse=True)",
"+B = sorted(list(map(int, input().split())), reverse=True)",
"+C = sorted(list(map(int, input().split())), reverse=True)",
"+ans_list = []",
"+s = set()",
"+pq = []",
"+item = (-(A[0] + B[0] + C[0]), 0, 0, 0)",
"+heappush(pq, item)",
"+for _ in range(K):",
"+ value, i, j, k = heappop(pq)",
"+ ans_list.append(-value)",
"+ if len(ans_list) == K:",
"+ break",
"+ if i <= X - 2 and (i + 1, j, k) not in s:",
"+ item = (-(A[i + 1] + B[j] + C[k]), i + 1, j, k)",
"+ heappush(pq, item)",
"+ s.add((i + 1, j, k))",
"+ if j <= Y - 2 and (i, j + 1, k) not in s:",
"+ item = (-(A[i] + B[j + 1] + C[k]), i, j + 1, k)",
"+ heappush(pq, item)",
"+ s.add((i, j + 1, k))",
"+ if k <= Z - 2 and (i, j, k + 1) not in s:",
"+ item = (-(A[i] + B[j] + C[k + 1]), i, j, k + 1)",
"+ heappush(pq, item)",
"+ s.add((i, j, k + 1))",
"+for ans in ans_list:"
] | false | 0.052371 | 0.036173 | 1.447801 |
[
"s116091626",
"s168988660"
] |
u372144784
|
p02732
|
python
|
s451867438
|
s784076896
| 441 | 400 | 80,928 | 71,024 |
Accepted
|
Accepted
| 9.3 |
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
#二項係数(modなし) O(k)
def large_conbination(n,k): #no mod. return nCk.
res1 = 1
for i in range(n,n-k,-1):
res1*=i
res2 = 1
for i in range(1,k+1):
res2*= i
return res1//res2
n = int(readline())
lst1 = list(map(int,readline().split()))
c = Counter(lst1)
ans = 0
dic1 = dict()
for i,j in list(c.items()):
res1 = large_conbination(j,2)
res2 = large_conbination(j-1,2)
ans += res1
dic1[i] = (res1,res2)
for i in lst1:
res12 = dic1[i]
print((ans-res12[0]+res12[1]))
|
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = list(map(int,readline().split()))
dic1 = defaultdict(int)
for i in lst1:
dic1[i] += 1
al = 0
for i in list(dic1.values()):
if i >= 2:
al += i*(i-1)//2
for i in lst1:
res = dic1[i]
if res >= 2:
print((al-res*(res-1)//2+(res-1)*(res-2)//2))
else:
print(al)
| 29 | 24 | 619 | 468 |
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
# 二項係数(modなし) O(k)
def large_conbination(n, k): # no mod. return nCk.
res1 = 1
for i in range(n, n - k, -1):
res1 *= i
res2 = 1
for i in range(1, k + 1):
res2 *= i
return res1 // res2
n = int(readline())
lst1 = list(map(int, readline().split()))
c = Counter(lst1)
ans = 0
dic1 = dict()
for i, j in list(c.items()):
res1 = large_conbination(j, 2)
res2 = large_conbination(j - 1, 2)
ans += res1
dic1[i] = (res1, res2)
for i in lst1:
res12 = dic1[i]
print((ans - res12[0] + res12[1]))
|
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n):
return 1 if n % 2 == 0 else 0
n = int(readline())
lst1 = list(map(int, readline().split()))
dic1 = defaultdict(int)
for i in lst1:
dic1[i] += 1
al = 0
for i in list(dic1.values()):
if i >= 2:
al += i * (i - 1) // 2
for i in lst1:
res = dic1[i]
if res >= 2:
print((al - res * (res - 1) // 2 + (res - 1) * (res - 2) // 2))
else:
print(al)
| false | 17.241379 |
[
"-from collections import Counter",
"+from collections import defaultdict",
"-# 二項係数(modなし) O(k)",
"-def large_conbination(n, k): # no mod. return nCk.",
"- res1 = 1",
"- for i in range(n, n - k, -1):",
"- res1 *= i",
"- res2 = 1",
"- for i in range(1, k + 1):",
"- res2 *= i",
"- return res1 // res2",
"+",
"+",
"+def even(n):",
"+ return 1 if n % 2 == 0 else 0",
"-c = Counter(lst1)",
"-ans = 0",
"-dic1 = dict()",
"-for i, j in list(c.items()):",
"- res1 = large_conbination(j, 2)",
"- res2 = large_conbination(j - 1, 2)",
"- ans += res1",
"- dic1[i] = (res1, res2)",
"+dic1 = defaultdict(int)",
"- res12 = dic1[i]",
"- print((ans - res12[0] + res12[1]))",
"+ dic1[i] += 1",
"+al = 0",
"+for i in list(dic1.values()):",
"+ if i >= 2:",
"+ al += i * (i - 1) // 2",
"+for i in lst1:",
"+ res = dic1[i]",
"+ if res >= 2:",
"+ print((al - res * (res - 1) // 2 + (res - 1) * (res - 2) // 2))",
"+ else:",
"+ print(al)"
] | false | 0.110735 | 0.108841 | 1.017405 |
[
"s451867438",
"s784076896"
] |
u492910842
|
p03487
|
python
|
s801391927
|
s899687797
| 138 | 103 | 107,428 | 102,348 |
Accepted
|
Accepted
| 25.36 |
from collections import Counter
n=int(eval(input()))
a=Counter(list(map(int,input().split()))).most_common()
ans=0
for i in range(len(a)):
if a[i][0]<a[i][1]:
ans+=a[i][1]-a[i][0]
elif a[i][0]>a[i][1]:
ans+=a[i][1]
print(ans)
|
from collections import Counter
n=int(eval(input()))
a=list(Counter(list(map(int,input().split()))).items())
ans=0
for i in range(len(a)):
if a[i][0]<a[i][1]:
ans+=a[i][1]-a[i][0]
elif a[i][0]>a[i][1]:
ans+=a[i][1]
print(ans)
| 11 | 11 | 243 | 243 |
from collections import Counter
n = int(eval(input()))
a = Counter(list(map(int, input().split()))).most_common()
ans = 0
for i in range(len(a)):
if a[i][0] < a[i][1]:
ans += a[i][1] - a[i][0]
elif a[i][0] > a[i][1]:
ans += a[i][1]
print(ans)
|
from collections import Counter
n = int(eval(input()))
a = list(Counter(list(map(int, input().split()))).items())
ans = 0
for i in range(len(a)):
if a[i][0] < a[i][1]:
ans += a[i][1] - a[i][0]
elif a[i][0] > a[i][1]:
ans += a[i][1]
print(ans)
| false | 0 |
[
"-a = Counter(list(map(int, input().split()))).most_common()",
"+a = list(Counter(list(map(int, input().split()))).items())"
] | false | 0.046288 | 0.123047 | 0.376184 |
[
"s801391927",
"s899687797"
] |
u285891772
|
p03240
|
python
|
s027746665
|
s015112845
| 550 | 48 | 5,316 | 5,396 |
Accepted
|
Accepted
| 91.27 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
N = INT()
xyh = [LIST() for _ in range(N)]
xyh.sort(key = lambda x:[x[0], x[1]])
for Cx in range(101):
for Cy in range(101):
H = 0
H_max = INF
for x, y, h in xyh:
if h == 0:
H_max = min(H_max, h + abs(x-Cx) + abs(y-Cy))
else:
if H == 0:
H = h + abs(x-Cx) + abs(y-Cy)
else:
if H != h + abs(x-Cx) + abs(y-Cy):
break
else:
if H <= H_max:
print((Cx, Cy, H))
break
else:
continue
break
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
N = INT()
xyh = [LIST() for _ in range(N)]
ins = (-1, -1, -1)
for x, y, h in xyh:
if h >= 1:
ins = (x, y, h)
x1, y1, h1 = ins # h>=1 の条件中の任意の(x, y, h)
for Cx in range(101):
for Cy in range(101):
H = h1 + abs(x1-Cx) + abs(y1-Cy) #Hは条件中の任意の(x, y, h)で決定できる。
for x, y, h in xyh:
if max(H-abs(x-Cx)-abs(y-Cy), 0) != h:
break
else:
print((Cx, Cy, H))
exit()
| 46 | 41 | 1,358 | 1,294 |
import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# from decimal import *
N = INT()
xyh = [LIST() for _ in range(N)]
xyh.sort(key=lambda x: [x[0], x[1]])
for Cx in range(101):
for Cy in range(101):
H = 0
H_max = INF
for x, y, h in xyh:
if h == 0:
H_max = min(H_max, h + abs(x - Cx) + abs(y - Cy))
else:
if H == 0:
H = h + abs(x - Cx) + abs(y - Cy)
else:
if H != h + abs(x - Cx) + abs(y - Cy):
break
else:
if H <= H_max:
print((Cx, Cy, H))
break
else:
continue
break
|
import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# from decimal import *
N = INT()
xyh = [LIST() for _ in range(N)]
ins = (-1, -1, -1)
for x, y, h in xyh:
if h >= 1:
ins = (x, y, h)
x1, y1, h1 = ins # h>=1 の条件中の任意の(x, y, h)
for Cx in range(101):
for Cy in range(101):
H = h1 + abs(x1 - Cx) + abs(y1 - Cy) # Hは条件中の任意の(x, y, h)で決定できる。
for x, y, h in xyh:
if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
break
else:
print((Cx, Cy, H))
exit()
| false | 10.869565 |
[
"-xyh.sort(key=lambda x: [x[0], x[1]])",
"+ins = (-1, -1, -1)",
"+for x, y, h in xyh:",
"+ if h >= 1:",
"+ ins = (x, y, h)",
"+x1, y1, h1 = ins # h>=1 の条件中の任意の(x, y, h)",
"- H = 0",
"- H_max = INF",
"+ H = h1 + abs(x1 - Cx) + abs(y1 - Cy) # Hは条件中の任意の(x, y, h)で決定できる。",
"- if h == 0:",
"- H_max = min(H_max, h + abs(x - Cx) + abs(y - Cy))",
"- else:",
"- if H == 0:",
"- H = h + abs(x - Cx) + abs(y - Cy)",
"- else:",
"- if H != h + abs(x - Cx) + abs(y - Cy):",
"- break",
"+ if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:",
"+ break",
"- if H <= H_max:",
"- print((Cx, Cy, H))",
"- break",
"- else:",
"- continue",
"- break",
"+ print((Cx, Cy, H))",
"+ exit()"
] | false | 0.083927 | 0.040086 | 2.09367 |
[
"s027746665",
"s015112845"
] |
u606045429
|
p03317
|
python
|
s813284119
|
s128070439
| 41 | 17 | 13,940 | 2,940 |
Accepted
|
Accepted
| 58.54 |
N, K, *A = list(map(int, open(0).read().split()))
print((-(-(N - 1) // (K - 1))))
|
N, K = list(map(int, input().split()))
print((-(-(N - 1) // (K - 1))))
| 2 | 2 | 75 | 64 |
N, K, *A = list(map(int, open(0).read().split()))
print((-(-(N - 1) // (K - 1))))
|
N, K = list(map(int, input().split()))
print((-(-(N - 1) // (K - 1))))
| false | 0 |
[
"-N, K, *A = list(map(int, open(0).read().split()))",
"+N, K = list(map(int, input().split()))"
] | false | 0.037674 | 0.037998 | 0.991466 |
[
"s813284119",
"s128070439"
] |
u977389981
|
p02987
|
python
|
s632188683
|
s834443648
| 169 | 17 | 38,384 | 2,940 |
Accepted
|
Accepted
| 89.94 |
from collections import Counter
S = Counter(eval(input()))
i = 0
count2 = 0
for k, v in list(S.items()):
i += 1
if v == 2:
count2 += 1
if i == 2 and count2 == 2:
print('Yes')
else:
print('No')
|
S = eval(input())
if len(set(S)) == 2:
for x in set(S):
if S.count(x) == 2:
continue
else:
print('No')
break
else:
print('Yes')
else:
print('No')
| 14 | 13 | 227 | 224 |
from collections import Counter
S = Counter(eval(input()))
i = 0
count2 = 0
for k, v in list(S.items()):
i += 1
if v == 2:
count2 += 1
if i == 2 and count2 == 2:
print("Yes")
else:
print("No")
|
S = eval(input())
if len(set(S)) == 2:
for x in set(S):
if S.count(x) == 2:
continue
else:
print("No")
break
else:
print("Yes")
else:
print("No")
| false | 7.142857 |
[
"-from collections import Counter",
"-",
"-S = Counter(eval(input()))",
"-i = 0",
"-count2 = 0",
"-for k, v in list(S.items()):",
"- i += 1",
"- if v == 2:",
"- count2 += 1",
"-if i == 2 and count2 == 2:",
"- print(\"Yes\")",
"+S = eval(input())",
"+if len(set(S)) == 2:",
"+ for x in set(S):",
"+ if S.count(x) == 2:",
"+ continue",
"+ else:",
"+ print(\"No\")",
"+ break",
"+ else:",
"+ print(\"Yes\")"
] | false | 0.042895 | 0.007566 | 5.66982 |
[
"s632188683",
"s834443648"
] |
u297089927
|
p02711
|
python
|
s890440350
|
s788212551
| 25 | 21 | 9,028 | 8,980 |
Accepted
|
Accepted
| 16 |
N=str(eval(input()))
if "7" in N:
print("Yes")
else:
print("No")
|
n=eval(input())
if "7" in n:
print("Yes")
else:
print("No")
| 5 | 5 | 66 | 61 |
N = str(eval(input()))
if "7" in N:
print("Yes")
else:
print("No")
|
n = eval(input())
if "7" in n:
print("Yes")
else:
print("No")
| false | 0 |
[
"-N = str(eval(input()))",
"-if \"7\" in N:",
"+n = eval(input())",
"+if \"7\" in n:"
] | false | 0.039521 | 0.046706 | 0.846165 |
[
"s890440350",
"s788212551"
] |
u026402121
|
p03161
|
python
|
s579404251
|
s599827158
| 511 | 432 | 59,428 | 52,960 |
Accepted
|
Accepted
| 15.46 |
import sys
input = sys.stdin.readline
N,K = list(map(int,input().split()))
h = [0] + list(map(int,input().split()))
dp = [None for _ in range(N+1)]
dp[1] = 0
for i in range(2,N+1):
scope = min(i-1,K)
jump = [dp[i-x] + abs(h[i]-h[i-x]) for x in range(1,scope+1)]
dp[i] = min(jump)
print((dp[N]))
|
N,K = list(map(int,input().split()))
h = [0] + list(map(int,input().split()))
dp = [0] * (N+1)
for i in range(2,N+1):
scope = min(i-1,K)
jump = [dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,scope+1)]
dp[i] = min(jump)
print((dp[N]))
| 15 | 11 | 323 | 246 |
import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
h = [0] + list(map(int, input().split()))
dp = [None for _ in range(N + 1)]
dp[1] = 0
for i in range(2, N + 1):
scope = min(i - 1, K)
jump = [dp[i - x] + abs(h[i] - h[i - x]) for x in range(1, scope + 1)]
dp[i] = min(jump)
print((dp[N]))
|
N, K = list(map(int, input().split()))
h = [0] + list(map(int, input().split()))
dp = [0] * (N + 1)
for i in range(2, N + 1):
scope = min(i - 1, K)
jump = [dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, scope + 1)]
dp[i] = min(jump)
print((dp[N]))
| false | 26.666667 |
[
"-import sys",
"-",
"-input = sys.stdin.readline",
"-dp = [None for _ in range(N + 1)]",
"-dp[1] = 0",
"+dp = [0] * (N + 1)",
"- jump = [dp[i - x] + abs(h[i] - h[i - x]) for x in range(1, scope + 1)]",
"+ jump = [dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, scope + 1)]"
] | false | 0.045816 | 0.044428 | 1.031234 |
[
"s579404251",
"s599827158"
] |
u803102116
|
p03835
|
python
|
s096707124
|
s400376607
| 1,511 | 1,229 | 2,568 | 2,692 |
Accepted
|
Accepted
| 18.66 |
# your code goes here
[K, S] = input().split()
K = int(K)
S = int(S)
res = 0
for X in range(K+1):
for Y in range(K+1):
Z = S - X - Y
if 0 <= Z <= K:
res+=1
print(res)
|
[K, S] = input().split()
K = int(K)
S = int(S)
res = 0
for X in range(K+1):
for Y in range(K+1):
res += 0 <= S - X - Y <= K
print(res)
| 13 | 10 | 196 | 156 |
# your code goes here
[K, S] = input().split()
K = int(K)
S = int(S)
res = 0
for X in range(K + 1):
for Y in range(K + 1):
Z = S - X - Y
if 0 <= Z <= K:
res += 1
print(res)
|
[K, S] = input().split()
K = int(K)
S = int(S)
res = 0
for X in range(K + 1):
for Y in range(K + 1):
res += 0 <= S - X - Y <= K
print(res)
| false | 23.076923 |
[
"-# your code goes here",
"- Z = S - X - Y",
"- if 0 <= Z <= K:",
"- res += 1",
"+ res += 0 <= S - X - Y <= K"
] | false | 0.115181 | 0.031184 | 3.693532 |
[
"s096707124",
"s400376607"
] |
u408325839
|
p03044
|
python
|
s815375861
|
s028526393
| 605 | 480 | 102,940 | 92,772 |
Accepted
|
Accepted
| 20.66 |
import sys
sys.setrecursionlimit(10**6)
N = int(eval(input()))
paths = [dict() for i in range(N + 1)]
for i in range(N-1):
u, v, w = list(map(int,input().split()))
paths[u][v] = w
paths[v][u] = w
node_colors = [-1] * (N+1)
def route(last, now, dist):
for next_node, next_distance in zip(list(paths[now].keys()), list(paths[now].values())):
node_colors[next_node] = (dist + next_distance) % 2
if next_node != last:
route(now, next_node, dist + next_distance)
node_colors[1] = 0
route(0, 1, 0)
for i in range(N):
print((node_colors[i+1]))
|
import sys
sys.setrecursionlimit(10**6)
N = int(eval(input()))
paths = [dict() for i in range(N + 1)]
for i in range(N-1):
u, v, w = list(map(int,input().split()))
paths[u][v] = w
paths[v][u] = w
node_colors = [-1] * (N+1)
def route(last, now, dist):
for next_node, next_distance in list(paths[now].items()):
node_colors[next_node] = (dist + next_distance) % 2
if next_node != last:
route(now, next_node, dist + next_distance)
node_colors[1] = 0
route(0, 1, 0)
for i in range(N):
print((node_colors[i+1]))
| 24 | 24 | 588 | 563 |
import sys
sys.setrecursionlimit(10**6)
N = int(eval(input()))
paths = [dict() for i in range(N + 1)]
for i in range(N - 1):
u, v, w = list(map(int, input().split()))
paths[u][v] = w
paths[v][u] = w
node_colors = [-1] * (N + 1)
def route(last, now, dist):
for next_node, next_distance in zip(
list(paths[now].keys()), list(paths[now].values())
):
node_colors[next_node] = (dist + next_distance) % 2
if next_node != last:
route(now, next_node, dist + next_distance)
node_colors[1] = 0
route(0, 1, 0)
for i in range(N):
print((node_colors[i + 1]))
|
import sys
sys.setrecursionlimit(10**6)
N = int(eval(input()))
paths = [dict() for i in range(N + 1)]
for i in range(N - 1):
u, v, w = list(map(int, input().split()))
paths[u][v] = w
paths[v][u] = w
node_colors = [-1] * (N + 1)
def route(last, now, dist):
for next_node, next_distance in list(paths[now].items()):
node_colors[next_node] = (dist + next_distance) % 2
if next_node != last:
route(now, next_node, dist + next_distance)
node_colors[1] = 0
route(0, 1, 0)
for i in range(N):
print((node_colors[i + 1]))
| false | 0 |
[
"- for next_node, next_distance in zip(",
"- list(paths[now].keys()), list(paths[now].values())",
"- ):",
"+ for next_node, next_distance in list(paths[now].items()):"
] | false | 0.036016 | 0.032628 | 1.103843 |
[
"s815375861",
"s028526393"
] |
u607563136
|
p02756
|
python
|
s176024443
|
s709866134
| 968 | 390 | 11,840 | 13,892 |
Accepted
|
Accepted
| 59.71 |
s = eval(input())
q = int(eval(input()))
f1 = 1
f2 = 2
st = ""
se = ""
for _ in range(q):
q = input().split()
if int(q[0]) == 1:
f1,f2 = f2,f1
elif int(q[0]) == 2:
if int(q[1]) == f1:
st = q[2] + st
elif int(q[1]) == f2:
se += q[2]
ans = st + s + se
if f1 == 1:
print(ans)
else:
ans = list(ans)
ans.reverse()
ans = "".join(ans)
print(ans)
|
from collections import deque
s = eval(input())
q = int(eval(input()))
dt = deque()
de = deque()
f1 = 1
f2 = 2
for _ in range(q):
q = input().split()
if int(q[0]) == 1:
f1,f2 = f2,f1
elif int(q[0]) == 2:
if int(q[1]) == f1:
dt.appendleft(q[2])
elif int(q[1]) == f2:
de.append(q[2])
st = "".join(dt)
se = "".join(de)
ans = st + s + se
if f1 == 1:
print(ans)
else:
ans = list(ans)
ans.reverse()
ans = "".join(ans)
print(ans)
| 27 | 32 | 452 | 559 |
s = eval(input())
q = int(eval(input()))
f1 = 1
f2 = 2
st = ""
se = ""
for _ in range(q):
q = input().split()
if int(q[0]) == 1:
f1, f2 = f2, f1
elif int(q[0]) == 2:
if int(q[1]) == f1:
st = q[2] + st
elif int(q[1]) == f2:
se += q[2]
ans = st + s + se
if f1 == 1:
print(ans)
else:
ans = list(ans)
ans.reverse()
ans = "".join(ans)
print(ans)
|
from collections import deque
s = eval(input())
q = int(eval(input()))
dt = deque()
de = deque()
f1 = 1
f2 = 2
for _ in range(q):
q = input().split()
if int(q[0]) == 1:
f1, f2 = f2, f1
elif int(q[0]) == 2:
if int(q[1]) == f1:
dt.appendleft(q[2])
elif int(q[1]) == f2:
de.append(q[2])
st = "".join(dt)
se = "".join(de)
ans = st + s + se
if f1 == 1:
print(ans)
else:
ans = list(ans)
ans.reverse()
ans = "".join(ans)
print(ans)
| false | 15.625 |
[
"+from collections import deque",
"+",
"+dt = deque()",
"+de = deque()",
"-st = \"\"",
"-se = \"\"",
"- st = q[2] + st",
"+ dt.appendleft(q[2])",
"- se += q[2]",
"+ de.append(q[2])",
"+st = \"\".join(dt)",
"+se = \"\".join(de)"
] | false | 0.037753 | 0.036286 | 1.04042 |
[
"s176024443",
"s709866134"
] |
u449473917
|
p02714
|
python
|
s571217478
|
s715437245
| 1,471 | 167 | 9,128 | 73,540 |
Accepted
|
Accepted
| 88.65 |
n=int(eval(input()))
s=eval(input())
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n):
for d in range(n):
j=i+d
k=j+d
if k>=n: break
if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
ans-=1
print(ans)
|
n=int(eval(input()))
s=eval(input())
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n):
for d in range(n):
j=i+d
k=j+d
if k<n:
if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
ans-=1
print(ans)
| 18 | 18 | 277 | 278 |
n = int(eval(input()))
s = eval(input())
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r * g * b
for i in range(n):
for d in range(n):
j = i + d
k = j + d
if k >= n:
break
if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
ans -= 1
print(ans)
|
n = int(eval(input()))
s = eval(input())
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r * g * b
for i in range(n):
for d in range(n):
j = i + d
k = j + d
if k < n:
if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
ans -= 1
print(ans)
| false | 0 |
[
"- if k >= n:",
"- break",
"- if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:",
"- ans -= 1",
"+ if k < n:",
"+ if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:",
"+ ans -= 1"
] | false | 0.037983 | 0.053573 | 0.708996 |
[
"s571217478",
"s715437245"
] |
u394950523
|
p02881
|
python
|
s827440606
|
s818281897
| 159 | 144 | 3,060 | 3,060 |
Accepted
|
Accepted
| 9.43 |
N = int(eval(input()))
n = int(N**0.5) + 1
A = 0
B = 0
b = 0
for a in range(1, n):
if N % a == 0:
b = N // a
A = a
B = b
ans = (A - 1) + (B - 1)
print(ans)
|
N = int(eval(input()))
n = int(N**0.5) + 1
for a in range(1, n):
if N % a == 0:
b = N // a
ans = (a - 1) + (b - 1)
print(ans)
| 13 | 9 | 190 | 149 |
N = int(eval(input()))
n = int(N**0.5) + 1
A = 0
B = 0
b = 0
for a in range(1, n):
if N % a == 0:
b = N // a
A = a
B = b
ans = (A - 1) + (B - 1)
print(ans)
|
N = int(eval(input()))
n = int(N**0.5) + 1
for a in range(1, n):
if N % a == 0:
b = N // a
ans = (a - 1) + (b - 1)
print(ans)
| false | 30.769231 |
[
"-A = 0",
"-B = 0",
"-b = 0",
"- A = a",
"- B = b",
"-ans = (A - 1) + (B - 1)",
"+ ans = (a - 1) + (b - 1)"
] | false | 0.050887 | 0.053856 | 0.944857 |
[
"s827440606",
"s818281897"
] |
u425950110
|
p02571
|
python
|
s619745623
|
s461288699
| 65 | 58 | 9,064 | 9,036 |
Accepted
|
Accepted
| 10.77 |
S = list(eval(input()))
T = list(eval(input()))
lst_of_values = []
for i in range(len(S)):
current = 0
if i + len(T) > len(S):
break
k = 0
for j in range(i, i+len(T)):
if S[j] != T[k]:
current += 1
k+=1
lst_of_values.append(current)
k=0
print((min(lst_of_values)))
|
S = eval(input())
T = eval(input())
counter = 0
for i in range(len(S)):
second = 0
group = S[i:i+len(T)]
if len(group) < len(T):
break
for j in range(len(T)):
if T[j] != group[j]:
second += 1
if counter == 0:
counter = second
elif second < counter:
counter = second
print(counter)
| 19 | 19 | 333 | 357 |
S = list(eval(input()))
T = list(eval(input()))
lst_of_values = []
for i in range(len(S)):
current = 0
if i + len(T) > len(S):
break
k = 0
for j in range(i, i + len(T)):
if S[j] != T[k]:
current += 1
k += 1
lst_of_values.append(current)
k = 0
print((min(lst_of_values)))
|
S = eval(input())
T = eval(input())
counter = 0
for i in range(len(S)):
second = 0
group = S[i : i + len(T)]
if len(group) < len(T):
break
for j in range(len(T)):
if T[j] != group[j]:
second += 1
if counter == 0:
counter = second
elif second < counter:
counter = second
print(counter)
| false | 0 |
[
"-S = list(eval(input()))",
"-T = list(eval(input()))",
"-lst_of_values = []",
"+S = eval(input())",
"+T = eval(input())",
"+counter = 0",
"- current = 0",
"- if i + len(T) > len(S):",
"+ second = 0",
"+ group = S[i : i + len(T)]",
"+ if len(group) < len(T):",
"- k = 0",
"- for j in range(i, i + len(T)):",
"- if S[j] != T[k]:",
"- current += 1",
"- k += 1",
"- lst_of_values.append(current)",
"- k = 0",
"-print((min(lst_of_values)))",
"+ for j in range(len(T)):",
"+ if T[j] != group[j]:",
"+ second += 1",
"+ if counter == 0:",
"+ counter = second",
"+ elif second < counter:",
"+ counter = second",
"+print(counter)"
] | false | 0.046203 | 0.037859 | 1.220401 |
[
"s619745623",
"s461288699"
] |
u604774382
|
p02268
|
python
|
s552157932
|
s328085243
| 570 | 380 | 21,084 | 13,160 |
Accepted
|
Accepted
| 33.33 |
n = int( eval(input( )) )
s = [ int( val ) for val in input( ).split( " " ) ]
q = int( eval(input( )) )
t = [ int( val ) for val in input( ).split( " " ) ]
cnt = 0
cnt = 0
for ti in t:
low = 0
high = n - 1
while low <= high:
m = ( low+high )//2
if ti < s[m]:
high = m - 1
elif s[m] < ti:
low = m + 1
else:
cnt += 1
break
print( cnt )
|
n = int( input( ) )
s = [ int( val ) for val in input( ).split( " " ) ]
q = int( input( ) )
t = [ int( val ) for val in input( ).split( " " ) ]
cnt = 0
cnt = 0
for ti in t:
low = 0
high = n - 1
while low <= high:
m = ( low+high )//2
if ti < s[m]:
high = m - 1
elif s[m] < ti:
low = m + 1
else:
cnt += 1
break
print( cnt )
| 21 | 21 | 366 | 382 |
n = int(eval(input()))
s = [int(val) for val in input().split(" ")]
q = int(eval(input()))
t = [int(val) for val in input().split(" ")]
cnt = 0
cnt = 0
for ti in t:
low = 0
high = n - 1
while low <= high:
m = (low + high) // 2
if ti < s[m]:
high = m - 1
elif s[m] < ti:
low = m + 1
else:
cnt += 1
break
print(cnt)
|
n = int(input())
s = [int(val) for val in input().split(" ")]
q = int(input())
t = [int(val) for val in input().split(" ")]
cnt = 0
cnt = 0
for ti in t:
low = 0
high = n - 1
while low <= high:
m = (low + high) // 2
if ti < s[m]:
high = m - 1
elif s[m] < ti:
low = m + 1
else:
cnt += 1
break
print(cnt)
| false | 0 |
[
"-n = int(eval(input()))",
"+n = int(input())",
"-q = int(eval(input()))",
"+q = int(input())"
] | false | 0.043243 | 0.060586 | 0.71374 |
[
"s552157932",
"s328085243"
] |
u028973125
|
p03817
|
python
|
s816402822
|
s275472582
| 164 | 28 | 38,360 | 8,992 |
Accepted
|
Accepted
| 82.93 |
import sys
x = int(sys.stdin.readline().strip())
"""
1
5423
6
"""
r = x // 11
res = x - 11*r
if res == 0:
print((2*r))
elif res > 6:
print((2*r + 2))
else:
print((2*r + 1))
|
import sys
x = int(sys.stdin.readline())
n = x // 11
r = x % 11
if r == 0:
print((2*n))
elif r <= 6:
print((2*n + 1))
else:
print((2 * (n+1)))
| 18 | 11 | 198 | 159 |
import sys
x = int(sys.stdin.readline().strip())
"""
1
5423
6
"""
r = x // 11
res = x - 11 * r
if res == 0:
print((2 * r))
elif res > 6:
print((2 * r + 2))
else:
print((2 * r + 1))
|
import sys
x = int(sys.stdin.readline())
n = x // 11
r = x % 11
if r == 0:
print((2 * n))
elif r <= 6:
print((2 * n + 1))
else:
print((2 * (n + 1)))
| false | 38.888889 |
[
"-x = int(sys.stdin.readline().strip())",
"-\"\"\"",
"-1",
"-5423",
"-6",
"-\"\"\"",
"-r = x // 11",
"-res = x - 11 * r",
"-if res == 0:",
"- print((2 * r))",
"-elif res > 6:",
"- print((2 * r + 2))",
"+x = int(sys.stdin.readline())",
"+n = x // 11",
"+r = x % 11",
"+if r == 0:",
"+ print((2 * n))",
"+elif r <= 6:",
"+ print((2 * n + 1))",
"- print((2 * r + 1))",
"+ print((2 * (n + 1)))"
] | false | 0.082846 | 0.089036 | 0.930481 |
[
"s816402822",
"s275472582"
] |
u102461423
|
p03667
|
python
|
s750372956
|
s525368970
| 1,006 | 305 | 47,496 | 54,020 |
Accepted
|
Accepted
| 69.68 |
import sys
input = sys.stdin.readline
"""
・とりあえず部分点解法:各クエリに対してO(N)
・いくつかを残していくつかを自由に埋める
・残すもの:被覆区間がoverlapしないように残す
・つまり、区間で覆えている点が処理できて、区間で覆えていない点が他所から持ってこないといけない。
"""
N,M = list(map(int,input().split()))
A = [int(x) for x in input().split()]
XY = [tuple(int(x) for x in input().split()) for _ in range(M)]
def subscore_solution():
from collections import Counter
for x,y in XY:
A[x-1] = y
covered = [False] * (N+N+10)
for key,cnt in list(Counter(A).items()):
for i in range(cnt):
covered[max(0,key-i)] = True
print((sum(not bl for bl in covered[1:N+1])))
counter = [0] * (N+1)
covered = [0] * (N+N+10)
for a in A:
counter[a] += 1
covered[a-counter[a]+1] += 1
magic = sum(x==0 for x in covered[1:N+1])
for i,y in XY:
x = A[i-1]
A[i-1] = y
rem = x - counter[x] + 1
counter[x] -= 1
counter[y] += 1
add = y - counter[y] + 1
covered[rem] -= 1
if 1<=rem<=N and covered[rem] == 0:
magic += 1
if 1<=add<=N and covered[add] == 0:
magic -= 1
covered[add] += 1
print(magic)
|
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(A, X, Y):
N = len(A)
count = np.zeros(N + 1, np.int64)
covered = np.zeros(N + 1, np.int64)
for x in A:
count[x] += 1
y = x - count[x] + 1
if y > 0:
covered[y] += 1
spell = np.sum(covered[1:] == 0)
for i in range(len(X)):
x, y = X[i], Y[i]
before = A[x - 1]
after = y
A[x - 1] = y
rem = before - count[before] + 1
count[before] -= 1
add = after - count[after]
count[after] += 1
if rem > 0:
covered[rem] -= 1
if not covered[rem]:
spell += 1
if add > 0:
if not covered[add]:
spell -= 1
covered[add] += 1
print(spell)
if sys.argv[-1] == 'ONLINE_JUDGE':
import numba
from numba.pycc import CC
i8 = numba.from_dtype(np.int64)
signature = (i8[:], i8[:], i8[:])
cc = CC('my_module')
cc.export('main', signature)(main)
cc.compile()
from my_module import main
N, M = list(map(int, readline().split()))
A = np.array(readline().split(), np.int64)
XY = np.array(read().split(), np.int64)
X = XY[::2]
Y = XY[1::2]
main(A, X, Y)
| 46 | 55 | 1,137 | 1,368 |
import sys
input = sys.stdin.readline
"""
・とりあえず部分点解法:各クエリに対してO(N)
・いくつかを残していくつかを自由に埋める
・残すもの:被覆区間がoverlapしないように残す
・つまり、区間で覆えている点が処理できて、区間で覆えていない点が他所から持ってこないといけない。
"""
N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
XY = [tuple(int(x) for x in input().split()) for _ in range(M)]
def subscore_solution():
from collections import Counter
for x, y in XY:
A[x - 1] = y
covered = [False] * (N + N + 10)
for key, cnt in list(Counter(A).items()):
for i in range(cnt):
covered[max(0, key - i)] = True
print((sum(not bl for bl in covered[1 : N + 1])))
counter = [0] * (N + 1)
covered = [0] * (N + N + 10)
for a in A:
counter[a] += 1
covered[a - counter[a] + 1] += 1
magic = sum(x == 0 for x in covered[1 : N + 1])
for i, y in XY:
x = A[i - 1]
A[i - 1] = y
rem = x - counter[x] + 1
counter[x] -= 1
counter[y] += 1
add = y - counter[y] + 1
covered[rem] -= 1
if 1 <= rem <= N and covered[rem] == 0:
magic += 1
if 1 <= add <= N and covered[add] == 0:
magic -= 1
covered[add] += 1
print(magic)
|
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(A, X, Y):
N = len(A)
count = np.zeros(N + 1, np.int64)
covered = np.zeros(N + 1, np.int64)
for x in A:
count[x] += 1
y = x - count[x] + 1
if y > 0:
covered[y] += 1
spell = np.sum(covered[1:] == 0)
for i in range(len(X)):
x, y = X[i], Y[i]
before = A[x - 1]
after = y
A[x - 1] = y
rem = before - count[before] + 1
count[before] -= 1
add = after - count[after]
count[after] += 1
if rem > 0:
covered[rem] -= 1
if not covered[rem]:
spell += 1
if add > 0:
if not covered[add]:
spell -= 1
covered[add] += 1
print(spell)
if sys.argv[-1] == "ONLINE_JUDGE":
import numba
from numba.pycc import CC
i8 = numba.from_dtype(np.int64)
signature = (i8[:], i8[:], i8[:])
cc = CC("my_module")
cc.export("main", signature)(main)
cc.compile()
from my_module import main
N, M = list(map(int, readline().split()))
A = np.array(readline().split(), np.int64)
XY = np.array(read().split(), np.int64)
X = XY[::2]
Y = XY[1::2]
main(A, X, Y)
| false | 16.363636 |
[
"+import numpy as np",
"-input = sys.stdin.readline",
"-\"\"\"",
"-・とりあえず部分点解法:各クエリに対してO(N)",
"-・いくつかを残していくつかを自由に埋める",
"-・残すもの:被覆区間がoverlapしないように残す",
"-・つまり、区間で覆えている点が処理できて、区間で覆えていない点が他所から持ってこないといけない。",
"-\"\"\"",
"-N, M = list(map(int, input().split()))",
"-A = [int(x) for x in input().split()]",
"-XY = [tuple(int(x) for x in input().split()) for _ in range(M)]",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"-def subscore_solution():",
"- from collections import Counter",
"-",
"- for x, y in XY:",
"+def main(A, X, Y):",
"+ N = len(A)",
"+ count = np.zeros(N + 1, np.int64)",
"+ covered = np.zeros(N + 1, np.int64)",
"+ for x in A:",
"+ count[x] += 1",
"+ y = x - count[x] + 1",
"+ if y > 0:",
"+ covered[y] += 1",
"+ spell = np.sum(covered[1:] == 0)",
"+ for i in range(len(X)):",
"+ x, y = X[i], Y[i]",
"+ before = A[x - 1]",
"+ after = y",
"- covered = [False] * (N + N + 10)",
"- for key, cnt in list(Counter(A).items()):",
"- for i in range(cnt):",
"- covered[max(0, key - i)] = True",
"- print((sum(not bl for bl in covered[1 : N + 1])))",
"+ rem = before - count[before] + 1",
"+ count[before] -= 1",
"+ add = after - count[after]",
"+ count[after] += 1",
"+ if rem > 0:",
"+ covered[rem] -= 1",
"+ if not covered[rem]:",
"+ spell += 1",
"+ if add > 0:",
"+ if not covered[add]:",
"+ spell -= 1",
"+ covered[add] += 1",
"+ print(spell)",
"-counter = [0] * (N + 1)",
"-covered = [0] * (N + N + 10)",
"-for a in A:",
"- counter[a] += 1",
"- covered[a - counter[a] + 1] += 1",
"-magic = sum(x == 0 for x in covered[1 : N + 1])",
"-for i, y in XY:",
"- x = A[i - 1]",
"- A[i - 1] = y",
"- rem = x - counter[x] + 1",
"- counter[x] -= 1",
"- counter[y] += 1",
"- add = y - counter[y] + 1",
"- covered[rem] -= 1",
"- if 1 <= rem <= N and covered[rem] == 0:",
"- magic += 1",
"- if 1 <= add <= N and covered[add] == 0:",
"- magic -= 1",
"- covered[add] += 1",
"- print(magic)",
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ import numba",
"+ from numba.pycc import CC",
"+",
"+ i8 = numba.from_dtype(np.int64)",
"+ signature = (i8[:], i8[:], i8[:])",
"+ cc = CC(\"my_module\")",
"+ cc.export(\"main\", signature)(main)",
"+ cc.compile()",
"+from my_module import main",
"+",
"+N, M = list(map(int, readline().split()))",
"+A = np.array(readline().split(), np.int64)",
"+XY = np.array(read().split(), np.int64)",
"+X = XY[::2]",
"+Y = XY[1::2]",
"+main(A, X, Y)"
] | false | 0.042707 | 0.349415 | 0.122224 |
[
"s750372956",
"s525368970"
] |
u419686324
|
p04013
|
python
|
s005331442
|
s639120981
| 137 | 46 | 13,400 | 3,572 |
Accepted
|
Accepted
| 66.42 |
N, A = list(map(int, input().split()))
X = [int(x) - A for x in input().split()]
import functools
@functools.lru_cache(maxsize=None)
def f(acc, left):
if not left: return 0
ret = 0
y = acc + left[0]
ret += 1 if y == 0 else 0
ret += f(y, left[1:])
ret += f(acc, left[1:])
return ret
print((f(0, tuple(X))))
|
N, A = list(map(int, input().split()))
X = [int(x) - A for x in input().split()]
from collections import Counter
total = Counter([0])
for x in X:
mix = Counter()
for i, cnt in list(total.items()):
mix[i + x] += cnt
total += mix
print((total[0] - 1))
| 14 | 13 | 339 | 270 |
N, A = list(map(int, input().split()))
X = [int(x) - A for x in input().split()]
import functools
@functools.lru_cache(maxsize=None)
def f(acc, left):
if not left:
return 0
ret = 0
y = acc + left[0]
ret += 1 if y == 0 else 0
ret += f(y, left[1:])
ret += f(acc, left[1:])
return ret
print((f(0, tuple(X))))
|
N, A = list(map(int, input().split()))
X = [int(x) - A for x in input().split()]
from collections import Counter
total = Counter([0])
for x in X:
mix = Counter()
for i, cnt in list(total.items()):
mix[i + x] += cnt
total += mix
print((total[0] - 1))
| false | 7.142857 |
[
"-import functools",
"+from collections import Counter",
"-",
"[email protected]_cache(maxsize=None)",
"-def f(acc, left):",
"- if not left:",
"- return 0",
"- ret = 0",
"- y = acc + left[0]",
"- ret += 1 if y == 0 else 0",
"- ret += f(y, left[1:])",
"- ret += f(acc, left[1:])",
"- return ret",
"-",
"-",
"-print((f(0, tuple(X))))",
"+total = Counter([0])",
"+for x in X:",
"+ mix = Counter()",
"+ for i, cnt in list(total.items()):",
"+ mix[i + x] += cnt",
"+ total += mix",
"+print((total[0] - 1))"
] | false | 0.040131 | 0.040735 | 0.985171 |
[
"s005331442",
"s639120981"
] |
u429029348
|
p02608
|
python
|
s460954031
|
s604890806
| 1,788 | 454 | 69,548 | 9,344 |
Accepted
|
Accepted
| 74.61 |
n=int(eval(input()))
ans=0
for i in range(1,n+1):
cnt=0
for x in range(1,101):
if x**2>i:
break
for y in range(1,x+1):
if x**2+y**2>i:
break
for z in range(1,y+1):
if x**2+y**2+z**2+x*y+y*z+z*x==i:
if x==y==z:
cnt+=1
if (x>y and y==z) or (x==y and y>z):
cnt+=3
if x>y>z:
cnt+=6
ans=cnt
print(ans)
|
n = int(eval(input()))
ans = [0] * n
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
d = x * x + y * y + z * z + x * y + y * z + z * x
if d <= n:
ans[d - 1] += 1
for i in ans:
print(i)
| 20 | 12 | 428 | 272 |
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
cnt = 0
for x in range(1, 101):
if x**2 > i:
break
for y in range(1, x + 1):
if x**2 + y**2 > i:
break
for z in range(1, y + 1):
if x**2 + y**2 + z**2 + x * y + y * z + z * x == i:
if x == y == z:
cnt += 1
if (x > y and y == z) or (x == y and y > z):
cnt += 3
if x > y > z:
cnt += 6
ans = cnt
print(ans)
|
n = int(eval(input()))
ans = [0] * n
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
d = x * x + y * y + z * z + x * y + y * z + z * x
if d <= n:
ans[d - 1] += 1
for i in ans:
print(i)
| false | 40 |
[
"-ans = 0",
"-for i in range(1, n + 1):",
"- cnt = 0",
"- for x in range(1, 101):",
"- if x**2 > i:",
"- break",
"- for y in range(1, x + 1):",
"- if x**2 + y**2 > i:",
"- break",
"- for z in range(1, y + 1):",
"- if x**2 + y**2 + z**2 + x * y + y * z + z * x == i:",
"- if x == y == z:",
"- cnt += 1",
"- if (x > y and y == z) or (x == y and y > z):",
"- cnt += 3",
"- if x > y > z:",
"- cnt += 6",
"- ans = cnt",
"- print(ans)",
"+ans = [0] * n",
"+for x in range(1, 101):",
"+ for y in range(1, 101):",
"+ for z in range(1, 101):",
"+ d = x * x + y * y + z * z + x * y + y * z + z * x",
"+ if d <= n:",
"+ ans[d - 1] += 1",
"+for i in ans:",
"+ print(i)"
] | false | 0.049794 | 0.938109 | 0.053079 |
[
"s460954031",
"s604890806"
] |
u133038626
|
p03304
|
python
|
s032490187
|
s767276343
| 38 | 17 | 5,304 | 2,940 |
Accepted
|
Accepted
| 55.26 |
# coding: utf-8
import fractions
n, m, d = list(map(int, input().split()))
p = fractions.Fraction(2 * (n-d), n**2) if d != 0 else fractions.Fraction(1, n)
print((float(p * (m-1))))
|
n,m,d=list(map(int,input().split()))
print(((2*(n-d)/n**2 if d!=0 else 1/n)*(m-1)))
| 7 | 2 | 181 | 76 |
# coding: utf-8
import fractions
n, m, d = list(map(int, input().split()))
p = fractions.Fraction(2 * (n - d), n**2) if d != 0 else fractions.Fraction(1, n)
print((float(p * (m - 1))))
|
n, m, d = list(map(int, input().split()))
print(((2 * (n - d) / n**2 if d != 0 else 1 / n) * (m - 1)))
| false | 71.428571 |
[
"-# coding: utf-8",
"-import fractions",
"-",
"-p = fractions.Fraction(2 * (n - d), n**2) if d != 0 else fractions.Fraction(1, n)",
"-print((float(p * (m - 1))))",
"+print(((2 * (n - d) / n**2 if d != 0 else 1 / n) * (m - 1)))"
] | false | 0.086798 | 0.070631 | 1.228892 |
[
"s032490187",
"s767276343"
] |
u155024797
|
p03040
|
python
|
s298230746
|
s612699542
| 1,997 | 852 | 90,968 | 89,304 |
Accepted
|
Accepted
| 57.34 |
from heapq import heappop, heappush
def main():
Q = int(input())
y = 0
lheap = []
rheap = []
lsum = 0
rsum = 0
for _ in range(Q):
q = input()
if q[0] == '1':
# update
_, a, b = map(int, q.split())
y += b
if len(lheap) == 0 or -lheap[0] <= a <= rheap[0]:
heappush(lheap, -a)
heappush(rheap, a)
lsum += a
rsum += a
elif a < -lheap[0]:
mov = -heappop(lheap)
heappush(rheap, mov)
heappush(lheap, -a)
heappush(lheap, -a)
lsum += a*2 - mov
rsum += mov
elif rheap[0] < a:
mov = heappop(rheap)
heappush(lheap, -mov)
heappush(rheap, a)
heappush(rheap, a)
lsum += mov
rsum += a*2 - mov
else:
# inquiry
x = -lheap[0]
minimum = abs(x * len(lheap) - lsum) // 2 + \
abs(x * len(rheap) - rsum) // 2 + y
print(x, minimum)
if __name__ == "__main__":
main()
|
from heapq import heappop, heappush
import sys
input = sys.stdin.readline
def main():
Q = int(input())
y = 0
lheap = []
rheap = []
lsum = 0
rsum = 0
for _ in range(Q):
q = input()
if q[0] == '1':
# update
_, a, b = map(int, q.split())
y += b
if len(lheap) == 0 or -lheap[0] <= a <= rheap[0]:
heappush(lheap, -a)
heappush(rheap, a)
lsum += a
rsum += a
elif a < -lheap[0]:
mov = -heappop(lheap)
heappush(rheap, mov)
heappush(lheap, -a)
heappush(lheap, -a)
lsum += a*2 - mov
rsum += mov
elif rheap[0] < a:
mov = heappop(rheap)
heappush(lheap, -mov)
heappush(rheap, a)
heappush(rheap, a)
lsum += mov
rsum += a*2 - mov
else:
# inquiry
x = -lheap[0]
minimum = abs(x * len(lheap) - lsum) // 2 + \
abs(x * len(rheap) - rsum) // 2 + y
print(x, minimum)
if __name__ == "__main__":
main()
| 45 | 47 | 1,236 | 1,276 |
from heapq import heappop, heappush
def main():
Q = int(input())
y = 0
lheap = []
rheap = []
lsum = 0
rsum = 0
for _ in range(Q):
q = input()
if q[0] == "1":
# update
_, a, b = map(int, q.split())
y += b
if len(lheap) == 0 or -lheap[0] <= a <= rheap[0]:
heappush(lheap, -a)
heappush(rheap, a)
lsum += a
rsum += a
elif a < -lheap[0]:
mov = -heappop(lheap)
heappush(rheap, mov)
heappush(lheap, -a)
heappush(lheap, -a)
lsum += a * 2 - mov
rsum += mov
elif rheap[0] < a:
mov = heappop(rheap)
heappush(lheap, -mov)
heappush(rheap, a)
heappush(rheap, a)
lsum += mov
rsum += a * 2 - mov
else:
# inquiry
x = -lheap[0]
minimum = (
abs(x * len(lheap) - lsum) // 2 + abs(x * len(rheap) - rsum) // 2 + y
)
print(x, minimum)
if __name__ == "__main__":
main()
|
from heapq import heappop, heappush
import sys
input = sys.stdin.readline
def main():
Q = int(input())
y = 0
lheap = []
rheap = []
lsum = 0
rsum = 0
for _ in range(Q):
q = input()
if q[0] == "1":
# update
_, a, b = map(int, q.split())
y += b
if len(lheap) == 0 or -lheap[0] <= a <= rheap[0]:
heappush(lheap, -a)
heappush(rheap, a)
lsum += a
rsum += a
elif a < -lheap[0]:
mov = -heappop(lheap)
heappush(rheap, mov)
heappush(lheap, -a)
heappush(lheap, -a)
lsum += a * 2 - mov
rsum += mov
elif rheap[0] < a:
mov = heappop(rheap)
heappush(lheap, -mov)
heappush(rheap, a)
heappush(rheap, a)
lsum += mov
rsum += a * 2 - mov
else:
# inquiry
x = -lheap[0]
minimum = (
abs(x * len(lheap) - lsum) // 2 + abs(x * len(rheap) - rsum) // 2 + y
)
print(x, minimum)
if __name__ == "__main__":
main()
| false | 4.255319 |
[
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.091052 | 0.081826 | 1.112747 |
[
"s298230746",
"s612699542"
] |
u357751375
|
p03598
|
python
|
s355465710
|
s025837339
| 32 | 25 | 9,160 | 9,096 |
Accepted
|
Accepted
| 21.88 |
n = int(eval(input()))
k = int(eval(input()))
x = list(map(int,input().split()))
a = 0
b = 0
c = 0
for i in range(n):
a = x[i] * 2
b = abs(x[i] - k) * 2
c += min(a,b)
print(c)
|
n = int(eval(input()))
k = int(eval(input()))
x = list(map(int,input().split()))
ans = 0
for i in range(n):
a = x[i] * 2
b = abs(x[i] - k) * 2
ans += min(a,b)
print(ans)
| 13 | 9 | 193 | 177 |
n = int(eval(input()))
k = int(eval(input()))
x = list(map(int, input().split()))
a = 0
b = 0
c = 0
for i in range(n):
a = x[i] * 2
b = abs(x[i] - k) * 2
c += min(a, b)
print(c)
|
n = int(eval(input()))
k = int(eval(input()))
x = list(map(int, input().split()))
ans = 0
for i in range(n):
a = x[i] * 2
b = abs(x[i] - k) * 2
ans += min(a, b)
print(ans)
| false | 30.769231 |
[
"-a = 0",
"-b = 0",
"-c = 0",
"+ans = 0",
"- c += min(a, b)",
"-print(c)",
"+ ans += min(a, b)",
"+print(ans)"
] | false | 0.047641 | 0.047628 | 1.00027 |
[
"s355465710",
"s025837339"
] |
u077291787
|
p02726
|
python
|
s405850198
|
s753219665
| 1,269 | 1,024 | 3,188 | 3,188 |
Accepted
|
Accepted
| 19.31 |
# D - Line++
def main():
N, X, Y = list(map(int, input().split()))
dist_cnt = [0] * N
calc_min_dist = lambda x, y: min(y - x, abs(X - x) + abs(Y - y) + 1) # assume x < y
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
dist_cnt[calc_min_dist(i, j)] += 1
print(("\n".join(map(str, dist_cnt[1:]))))
if __name__ == "__main__":
main()
|
# D - Line++
def main():
N, X, Y = list(map(int, input().split()))
dist_cnt = [0] * N
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
dist_cnt[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1
print(("\n".join(map(str, dist_cnt[1:]))))
if __name__ == "__main__":
main()
| 13 | 12 | 389 | 319 |
# D - Line++
def main():
N, X, Y = list(map(int, input().split()))
dist_cnt = [0] * N
calc_min_dist = lambda x, y: min(y - x, abs(X - x) + abs(Y - y) + 1) # assume x < y
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
dist_cnt[calc_min_dist(i, j)] += 1
print(("\n".join(map(str, dist_cnt[1:]))))
if __name__ == "__main__":
main()
|
# D - Line++
def main():
N, X, Y = list(map(int, input().split()))
dist_cnt = [0] * N
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
dist_cnt[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1
print(("\n".join(map(str, dist_cnt[1:]))))
if __name__ == "__main__":
main()
| false | 7.692308 |
[
"- calc_min_dist = lambda x, y: min(y - x, abs(X - x) + abs(Y - y) + 1) # assume x < y",
"- dist_cnt[calc_min_dist(i, j)] += 1",
"+ dist_cnt[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1"
] | false | 0.043233 | 0.047468 | 0.91078 |
[
"s405850198",
"s753219665"
] |
u016128476
|
p02585
|
python
|
s201111979
|
s150449044
| 603 | 510 | 74,412 | 75,124 |
Accepted
|
Accepted
| 15.42 |
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
C = list(map(int, input().split()))
INF = 10**9+1
def solve():
cycles = []
memo = [False] * N
i = 0
while i < N-1:
cycle = []
j = i
while not memo[j]:
cycle.append(j)
memo[j] = True
j = P[j] - 1
k = i
for i in range(k, N):
if not memo[i]:
break
cycles.append(cycle)
ans = -INF
for cycle in cycles:
n = len(cycle)
# q, r = divmod(K-1, n)
# r += 1
memo = [-INF] * n
for i in range(n):
s = 0
for j in range(n):
s += C[cycle[(i+j)%n]]
memo[j] = max(memo[j], s)
tmpmax = -INF
imax = -1
if K < n:
for i in range(K):
if tmpmax < memo[i]:
tmpmax = memo[i]
imax = i+1
else:
if memo[-1] > 0:
for i in range(n):
q = (K-i-1) // n
tmpmax = max(tmpmax, memo[i] + memo[-1] * q)
else:
for i in range(n):
tmpmax = max(tmpmax, memo[i])
ans = max(ans, tmpmax)
return ans
if __name__ == "__main__":
print((solve()))
|
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
C = list(map(int, input().split()))
INF = 10**9+1
def solve():
ans = -INF
for i in range(N):
memo = [0] * (N+1)
j = 0
p = i
while j < N:
memo[j+1] = memo[j] + C[p]
p = P[p] - 1
j += 1
if p == i:
break
tans =-INF
if memo[j] > 0:
for k in range(j):
q = (K-k-1) // j
tans = max(tans, memo[k+1] + memo[j] * q)
else:
for k in range(min(K, j)):
tans = max(tans, memo[k+1])
ans = max(ans, tans)
return ans
if __name__ == "__main__":
print((solve()))
| 55 | 32 | 1,386 | 761 |
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
C = list(map(int, input().split()))
INF = 10**9 + 1
def solve():
cycles = []
memo = [False] * N
i = 0
while i < N - 1:
cycle = []
j = i
while not memo[j]:
cycle.append(j)
memo[j] = True
j = P[j] - 1
k = i
for i in range(k, N):
if not memo[i]:
break
cycles.append(cycle)
ans = -INF
for cycle in cycles:
n = len(cycle)
# q, r = divmod(K-1, n)
# r += 1
memo = [-INF] * n
for i in range(n):
s = 0
for j in range(n):
s += C[cycle[(i + j) % n]]
memo[j] = max(memo[j], s)
tmpmax = -INF
imax = -1
if K < n:
for i in range(K):
if tmpmax < memo[i]:
tmpmax = memo[i]
imax = i + 1
else:
if memo[-1] > 0:
for i in range(n):
q = (K - i - 1) // n
tmpmax = max(tmpmax, memo[i] + memo[-1] * q)
else:
for i in range(n):
tmpmax = max(tmpmax, memo[i])
ans = max(ans, tmpmax)
return ans
if __name__ == "__main__":
print((solve()))
|
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
C = list(map(int, input().split()))
INF = 10**9 + 1
def solve():
ans = -INF
for i in range(N):
memo = [0] * (N + 1)
j = 0
p = i
while j < N:
memo[j + 1] = memo[j] + C[p]
p = P[p] - 1
j += 1
if p == i:
break
tans = -INF
if memo[j] > 0:
for k in range(j):
q = (K - k - 1) // j
tans = max(tans, memo[k + 1] + memo[j] * q)
else:
for k in range(min(K, j)):
tans = max(tans, memo[k + 1])
ans = max(ans, tans)
return ans
if __name__ == "__main__":
print((solve()))
| false | 41.818182 |
[
"- cycles = []",
"- memo = [False] * N",
"- i = 0",
"- while i < N - 1:",
"- cycle = []",
"- j = i",
"- while not memo[j]:",
"- cycle.append(j)",
"- memo[j] = True",
"- j = P[j] - 1",
"- k = i",
"- for i in range(k, N):",
"- if not memo[i]:",
"+ ans = -INF",
"+ for i in range(N):",
"+ memo = [0] * (N + 1)",
"+ j = 0",
"+ p = i",
"+ while j < N:",
"+ memo[j + 1] = memo[j] + C[p]",
"+ p = P[p] - 1",
"+ j += 1",
"+ if p == i:",
"- cycles.append(cycle)",
"- ans = -INF",
"- for cycle in cycles:",
"- n = len(cycle)",
"- # q, r = divmod(K-1, n)",
"- # r += 1",
"- memo = [-INF] * n",
"- for i in range(n):",
"- s = 0",
"- for j in range(n):",
"- s += C[cycle[(i + j) % n]]",
"- memo[j] = max(memo[j], s)",
"- tmpmax = -INF",
"- imax = -1",
"- if K < n:",
"- for i in range(K):",
"- if tmpmax < memo[i]:",
"- tmpmax = memo[i]",
"- imax = i + 1",
"+ tans = -INF",
"+ if memo[j] > 0:",
"+ for k in range(j):",
"+ q = (K - k - 1) // j",
"+ tans = max(tans, memo[k + 1] + memo[j] * q)",
"- if memo[-1] > 0:",
"- for i in range(n):",
"- q = (K - i - 1) // n",
"- tmpmax = max(tmpmax, memo[i] + memo[-1] * q)",
"- else:",
"- for i in range(n):",
"- tmpmax = max(tmpmax, memo[i])",
"- ans = max(ans, tmpmax)",
"+ for k in range(min(K, j)):",
"+ tans = max(tans, memo[k + 1])",
"+ ans = max(ans, tans)"
] | false | 0.036309 | 0.035172 | 1.032321 |
[
"s201111979",
"s150449044"
] |
u102445737
|
p03061
|
python
|
s730921770
|
s724244017
| 703 | 382 | 100,832 | 89,580 |
Accepted
|
Accepted
| 45.66 |
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
# # # # class Segtree # # # #
# 0
# 1 2
# 3 4 5 6
# :
# leaf i - n-1+i
# parent - (i-1)//2
# children - 2*i+1, 2*i+2
class Segtree:
# modify UNIT and oper depending on the reduce operation
#UNIT = 0 # sum/or:0 and:fff..f min:BIG max:-BIG gcd:0 lcm:1 ..
#@classmethod
#def oper(c,x,y):
# return x|y # sum:+ or/and/min/max/gcd/lcm:(same)
# call like this: sgt = Segtree(n, 0, lambda x,y: max(x,y))
def __init__(s,l,unit,oper):
s.unit = unit
s.oper = oper
s.n = 1
while s.n<l:
s.n *= 2
s.ary = [s.unit for i in range(2*s.n-1)]
def get(s,i):
return s.ary[i+s.n-1]
def set(s,i,v):
k = i+s.n-1
s.ary[k] = v
while k>0:
k = (k-1)//2
s.ary[k] = s.oper( \
s.ary[2*k+1], s.ary[2*k+2])
def setary(s,a):
for i,v in enumerate(a):
s.ary[i+s.n-1] = v
for k in range(s.n-2,-1,-1):
s.ary[k] = s.oper( \
s.ary[2*k+1], s.ary[2*k+2])
def query(s,x,y):
l = x+s.n-1
r = y+s.n-1
res = s.unit
while l<r:
if not l%2:
res = s.oper(res,s.ary[l])
l += 1
if not r%2:
r -= 1
res = s.oper(res,s.ary[r])
l >>= 1
r >>= 1
return res
# # # # class Segtree end # # # #
from fractions import gcd
n = inn()
a = inl()
sgt = Segtree(n,0,gcd)
sgt.setary(a)
mx = max(sgt.query(1,n), sgt.query(0,n-1))
for i in range(1,n-1):
g = gcd(sgt.query(0,i),sgt.query(i+1,n))
mx = max(mx,g)
print(mx)
|
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
from fractions import gcd
n = inn()
a = inl()
l = [a[0]]*n
for i in range(1,n):
l[i] = gcd(l[i-1],a[i])
r = [a[n-1]]*n
for i in range(n-2,-1,-1):
r[i] = gcd(r[i+1],a[i])
mx = max(l[n-2],r[1])
for i in range(1,n-1):
mx = max(mx, gcd(l[i-1],r[i+1]))
print(mx)
| 89 | 26 | 2,057 | 575 |
printn = lambda x: print(x, end="")
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda: input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
# # # # class Segtree # # # #
# 0
# 1 2
# 3 4 5 6
# :
# leaf i - n-1+i
# parent - (i-1)//2
# children - 2*i+1, 2*i+2
class Segtree:
# modify UNIT and oper depending on the reduce operation
# UNIT = 0 # sum/or:0 and:fff..f min:BIG max:-BIG gcd:0 lcm:1 ..
# @classmethod
# def oper(c,x,y):
# return x|y # sum:+ or/and/min/max/gcd/lcm:(same)
# call like this: sgt = Segtree(n, 0, lambda x,y: max(x,y))
def __init__(s, l, unit, oper):
s.unit = unit
s.oper = oper
s.n = 1
while s.n < l:
s.n *= 2
s.ary = [s.unit for i in range(2 * s.n - 1)]
def get(s, i):
return s.ary[i + s.n - 1]
def set(s, i, v):
k = i + s.n - 1
s.ary[k] = v
while k > 0:
k = (k - 1) // 2
s.ary[k] = s.oper(s.ary[2 * k + 1], s.ary[2 * k + 2])
def setary(s, a):
for i, v in enumerate(a):
s.ary[i + s.n - 1] = v
for k in range(s.n - 2, -1, -1):
s.ary[k] = s.oper(s.ary[2 * k + 1], s.ary[2 * k + 2])
def query(s, x, y):
l = x + s.n - 1
r = y + s.n - 1
res = s.unit
while l < r:
if not l % 2:
res = s.oper(res, s.ary[l])
l += 1
if not r % 2:
r -= 1
res = s.oper(res, s.ary[r])
l >>= 1
r >>= 1
return res
# # # # class Segtree end # # # #
from fractions import gcd
n = inn()
a = inl()
sgt = Segtree(n, 0, gcd)
sgt.setary(a)
mx = max(sgt.query(1, n), sgt.query(0, n - 1))
for i in range(1, n - 1):
g = gcd(sgt.query(0, i), sgt.query(i + 1, n))
mx = max(mx, g)
print(mx)
|
printn = lambda x: print(x, end="")
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda: input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
from fractions import gcd
n = inn()
a = inl()
l = [a[0]] * n
for i in range(1, n):
l[i] = gcd(l[i - 1], a[i])
r = [a[n - 1]] * n
for i in range(n - 2, -1, -1):
r[i] = gcd(r[i + 1], a[i])
mx = max(l[n - 2], r[1])
for i in range(1, n - 1):
mx = max(mx, gcd(l[i - 1], r[i + 1]))
print(mx)
| false | 70.786517 |
[
"-# # # # class Segtree # # # #",
"-# 0",
"-# 1 2",
"-# 3 4 5 6",
"-# :",
"-# leaf i - n-1+i",
"-# parent - (i-1)//2",
"-# children - 2*i+1, 2*i+2",
"-class Segtree:",
"- # modify UNIT and oper depending on the reduce operation",
"- # UNIT = 0 # sum/or:0 and:fff..f min:BIG max:-BIG gcd:0 lcm:1 ..",
"- # @classmethod",
"- # def oper(c,x,y):",
"- # return x|y # sum:+ or/and/min/max/gcd/lcm:(same)",
"- # call like this: sgt = Segtree(n, 0, lambda x,y: max(x,y))",
"- def __init__(s, l, unit, oper):",
"- s.unit = unit",
"- s.oper = oper",
"- s.n = 1",
"- while s.n < l:",
"- s.n *= 2",
"- s.ary = [s.unit for i in range(2 * s.n - 1)]",
"-",
"- def get(s, i):",
"- return s.ary[i + s.n - 1]",
"-",
"- def set(s, i, v):",
"- k = i + s.n - 1",
"- s.ary[k] = v",
"- while k > 0:",
"- k = (k - 1) // 2",
"- s.ary[k] = s.oper(s.ary[2 * k + 1], s.ary[2 * k + 2])",
"-",
"- def setary(s, a):",
"- for i, v in enumerate(a):",
"- s.ary[i + s.n - 1] = v",
"- for k in range(s.n - 2, -1, -1):",
"- s.ary[k] = s.oper(s.ary[2 * k + 1], s.ary[2 * k + 2])",
"-",
"- def query(s, x, y):",
"- l = x + s.n - 1",
"- r = y + s.n - 1",
"- res = s.unit",
"- while l < r:",
"- if not l % 2:",
"- res = s.oper(res, s.ary[l])",
"- l += 1",
"- if not r % 2:",
"- r -= 1",
"- res = s.oper(res, s.ary[r])",
"- l >>= 1",
"- r >>= 1",
"- return res",
"-",
"-",
"-# # # # class Segtree end # # # #",
"-sgt = Segtree(n, 0, gcd)",
"-sgt.setary(a)",
"-mx = max(sgt.query(1, n), sgt.query(0, n - 1))",
"+l = [a[0]] * n",
"+for i in range(1, n):",
"+ l[i] = gcd(l[i - 1], a[i])",
"+r = [a[n - 1]] * n",
"+for i in range(n - 2, -1, -1):",
"+ r[i] = gcd(r[i + 1], a[i])",
"+mx = max(l[n - 2], r[1])",
"- g = gcd(sgt.query(0, i), sgt.query(i + 1, n))",
"- mx = max(mx, g)",
"+ mx = max(mx, gcd(l[i - 1], r[i + 1]))"
] | false | 0.046842 | 0.078477 | 0.596888 |
[
"s730921770",
"s724244017"
] |
u391875425
|
p03074
|
python
|
s013877051
|
s020601862
| 197 | 104 | 46,320 | 8,856 |
Accepted
|
Accepted
| 47.21 |
N, K = list(map(int, input().split()))
S = "1" + eval(input()) + "1"
arr = []
cnt = 0
flg = 1
for s in S:
if s == "1" and 1 - flg:
flg = 1
arr.append(cnt)
cnt = 1
elif s == "0" and flg:
flg = 0
arr.append(cnt)
cnt = 1
else:
cnt += 1
arr.append(cnt)
csum = [0] * (len(arr)+1)
for i in range(len(arr)):
csum[i + 1] = csum[i] + arr[i]
ans = 0
tmp = 0
for i in range(0, len(csum), 2):
l = i
r = min(i + 2*K + 1, len(csum) - 1)
tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)
ans = max(ans, tmp)
if len(csum) == 2:
print((csum[1] - 2))
else:
print(ans)
|
from itertools import accumulate
N, K = list(map(int, input().split()))
S = "1" + eval(input()) + "1"
arr = []
cnt = 0
flg = 1
for s in S:
if s == "1" and 1 - flg:
flg = 1
arr.append(cnt)
cnt = 1
elif s == "0" and flg:
flg = 0
arr.append(cnt)
cnt = 1
else:
cnt += 1
arr.append(cnt)
csum = [0] + list(accumulate(arr))
ans = 0
tmp = 0
for i in range(0, len(csum), 2):
l = i
r = min(i + 2*K + 1, len(csum) - 1)
tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)
ans = max(ans, tmp)
if len(csum) == 2:
print((csum[1] - 2))
else:
print(ans)
| 31 | 30 | 681 | 661 |
N, K = list(map(int, input().split()))
S = "1" + eval(input()) + "1"
arr = []
cnt = 0
flg = 1
for s in S:
if s == "1" and 1 - flg:
flg = 1
arr.append(cnt)
cnt = 1
elif s == "0" and flg:
flg = 0
arr.append(cnt)
cnt = 1
else:
cnt += 1
arr.append(cnt)
csum = [0] * (len(arr) + 1)
for i in range(len(arr)):
csum[i + 1] = csum[i] + arr[i]
ans = 0
tmp = 0
for i in range(0, len(csum), 2):
l = i
r = min(i + 2 * K + 1, len(csum) - 1)
tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)
ans = max(ans, tmp)
if len(csum) == 2:
print((csum[1] - 2))
else:
print(ans)
|
from itertools import accumulate
N, K = list(map(int, input().split()))
S = "1" + eval(input()) + "1"
arr = []
cnt = 0
flg = 1
for s in S:
if s == "1" and 1 - flg:
flg = 1
arr.append(cnt)
cnt = 1
elif s == "0" and flg:
flg = 0
arr.append(cnt)
cnt = 1
else:
cnt += 1
arr.append(cnt)
csum = [0] + list(accumulate(arr))
ans = 0
tmp = 0
for i in range(0, len(csum), 2):
l = i
r = min(i + 2 * K + 1, len(csum) - 1)
tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)
ans = max(ans, tmp)
if len(csum) == 2:
print((csum[1] - 2))
else:
print(ans)
| false | 3.225806 |
[
"+from itertools import accumulate",
"+",
"-csum = [0] * (len(arr) + 1)",
"-for i in range(len(arr)):",
"- csum[i + 1] = csum[i] + arr[i]",
"+csum = [0] + list(accumulate(arr))"
] | false | 0.056068 | 0.037629 | 1.490036 |
[
"s013877051",
"s020601862"
] |
u887207211
|
p03804
|
python
|
s357468430
|
s742973726
| 20 | 17 | 3,060 | 3,060 |
Accepted
|
Accepted
| 15 |
N, M = list(map(int,input().split()))
A = [eval(input()) for _ in range(N)]
B = [eval(input()) for _ in range(M)]
cnt = 0
tmp = []
for a in A:
for b in B:
if(tmp != B):
if(b in a):
tmp.append(b)
else:
break
if(tmp == B):
print("Yes")
else:
print("No")
|
N, M = list(map(int,input().split()))
A = [eval(input()) for _ in range(N)]
B = [eval(input()) for _ in range(M)]
tmp = []
for a in A:
for b in B:
if(tmp != B):
if(b in a):
tmp.append(b)
else:
break
if(tmp == B):
print('Yes')
else:
print('No')
| 17 | 16 | 285 | 275 |
N, M = list(map(int, input().split()))
A = [eval(input()) for _ in range(N)]
B = [eval(input()) for _ in range(M)]
cnt = 0
tmp = []
for a in A:
for b in B:
if tmp != B:
if b in a:
tmp.append(b)
else:
break
if tmp == B:
print("Yes")
else:
print("No")
|
N, M = list(map(int, input().split()))
A = [eval(input()) for _ in range(N)]
B = [eval(input()) for _ in range(M)]
tmp = []
for a in A:
for b in B:
if tmp != B:
if b in a:
tmp.append(b)
else:
break
if tmp == B:
print("Yes")
else:
print("No")
| false | 5.882353 |
[
"-cnt = 0"
] | false | 0.049533 | 0.049951 | 0.991643 |
[
"s357468430",
"s742973726"
] |
u709304134
|
p02695
|
python
|
s366412780
|
s473940589
| 163 | 113 | 107,536 | 67,996 |
Accepted
|
Accepted
| 30.67 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
N, M, Q = list(map(int,input().split()))
query = []
for q in range(Q):
a,b,c,d = list(map(int,input().split()))
a-=1
b-=1
query.append((a,b,c,d))
old = []
for i in range(1,M+1):
old.append([i])
for j in range(N-1):
new = []
for e in old:
for i in range(e[-1],M+1):
new.append(e+[i])
old = new
#print (new)
mx = 0
for n in new:
score = 0
for a,b,c,d in query:
if (n[b] - n[a] == c):
score += d
mx = max(score,mx)
print (mx)
|
import itertools
N, M, Q = list(map(int,input().split()))
query = []
for q in range(Q):
a,b,c,d = list(map(int,input().split()))
a-=1
b-=1
query.append((a,b,c,d))
mx = 0
for comb in itertools.combinations_with_replacement([i for i in range(1,M+1)],N):
score = 0
for a,b,c,d in query:
if (comb[b] - comb[a] == c):
score += d
mx = max(score,mx)
print (mx)
| 42 | 18 | 652 | 410 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
N, M, Q = list(map(int, input().split()))
query = []
for q in range(Q):
a, b, c, d = list(map(int, input().split()))
a -= 1
b -= 1
query.append((a, b, c, d))
old = []
for i in range(1, M + 1):
old.append([i])
for j in range(N - 1):
new = []
for e in old:
for i in range(e[-1], M + 1):
new.append(e + [i])
old = new
# print (new)
mx = 0
for n in new:
score = 0
for a, b, c, d in query:
if n[b] - n[a] == c:
score += d
mx = max(score, mx)
print(mx)
|
import itertools
N, M, Q = list(map(int, input().split()))
query = []
for q in range(Q):
a, b, c, d = list(map(int, input().split()))
a -= 1
b -= 1
query.append((a, b, c, d))
mx = 0
for comb in itertools.combinations_with_replacement([i for i in range(1, M + 1)], N):
score = 0
for a, b, c, d in query:
if comb[b] - comb[a] == c:
score += d
mx = max(score, mx)
print(mx)
| false | 57.142857 |
[
"-import sys",
"+import itertools",
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**7)",
"-INF = 10**10",
"-MOD = 10**9 + 7",
"-old = []",
"-for i in range(1, M + 1):",
"- old.append([i])",
"-for j in range(N - 1):",
"- new = []",
"- for e in old:",
"- for i in range(e[-1], M + 1):",
"- new.append(e + [i])",
"- old = new",
"-# print (new)",
"-for n in new:",
"+for comb in itertools.combinations_with_replacement([i for i in range(1, M + 1)], N):",
"- if n[b] - n[a] == c:",
"+ if comb[b] - comb[a] == c:"
] | false | 0.062041 | 0.093653 | 0.662455 |
[
"s366412780",
"s473940589"
] |
u556225812
|
p03208
|
python
|
s877436718
|
s896156752
| 282 | 239 | 11,288 | 7,384 |
Accepted
|
Accepted
| 15.25 |
N, K = list(map(int, input().split()))
lst = []
for i in range(N):
x = int(eval(input()))
lst.append(x)
lst.sort()
L = []
for i in range(N - K + 1):
L.append(lst[i + K -1] - lst[i])
L.sort()
print((L[0]))
|
N, K = list(map(int, input().split()))
lst = []
for i in range(N):
lst.append(int(eval(input())))
lst.sort()
dif = 10**9
for i in range(N-K+1):
if lst[i+K-1] - lst[i] < dif:
dif = lst[i+K-1] - lst[i]
print(dif)
| 11 | 10 | 212 | 223 |
N, K = list(map(int, input().split()))
lst = []
for i in range(N):
x = int(eval(input()))
lst.append(x)
lst.sort()
L = []
for i in range(N - K + 1):
L.append(lst[i + K - 1] - lst[i])
L.sort()
print((L[0]))
|
N, K = list(map(int, input().split()))
lst = []
for i in range(N):
lst.append(int(eval(input())))
lst.sort()
dif = 10**9
for i in range(N - K + 1):
if lst[i + K - 1] - lst[i] < dif:
dif = lst[i + K - 1] - lst[i]
print(dif)
| false | 9.090909 |
[
"- x = int(eval(input()))",
"- lst.append(x)",
"+ lst.append(int(eval(input())))",
"-L = []",
"+dif = 10**9",
"- L.append(lst[i + K - 1] - lst[i])",
"-L.sort()",
"-print((L[0]))",
"+ if lst[i + K - 1] - lst[i] < dif:",
"+ dif = lst[i + K - 1] - lst[i]",
"+print(dif)"
] | false | 0.039514 | 0.039589 | 0.998099 |
[
"s877436718",
"s896156752"
] |
u124735330
|
p02936
|
python
|
s734643600
|
s506917064
| 1,080 | 888 | 86,460 | 62,260 |
Accepted
|
Accepted
| 17.78 |
import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
def main():
N, Q = list(map(int, input().split()))
con = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
con[a - 1].append(b - 1)
con[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stacks = deque()
stacks.append((0, -1))
while stacks:
stack = stacks.pop()
node, parent = stack[0], stack[1]
children = con[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stacks.append((child, node))
print((*ans))
if __name__ == '__main__':
main()
|
import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
def main():
N, Q = list(map(int, input().split()))
con = [[] for i in range(N)]
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
con[a - 1].append(b - 1)
con[b - 1].append(a - 1)
for _ in range(Q):
p, v = list(map(int, input().split()))
ans[p-1] += v
stacks = deque()
stacks.append((0, -1))
while stacks:
stack = stacks.pop()
node, parent = stack[0], stack[1]
children = con[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stacks.append((child, node))
print((*ans))
if __name__ == '__main__':
main()
| 43 | 39 | 948 | 860 |
import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def main():
N, Q = list(map(int, input().split()))
con = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
con[a - 1].append(b - 1)
con[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stacks = deque()
stacks.append((0, -1))
while stacks:
stack = stacks.pop()
node, parent = stack[0], stack[1]
children = con[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stacks.append((child, node))
print((*ans))
if __name__ == "__main__":
main()
|
import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def main():
N, Q = list(map(int, input().split()))
con = [[] for i in range(N)]
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
con[a - 1].append(b - 1)
con[b - 1].append(a - 1)
for _ in range(Q):
p, v = list(map(int, input().split()))
ans[p - 1] += v
stacks = deque()
stacks.append((0, -1))
while stacks:
stack = stacks.pop()
node, parent = stack[0], stack[1]
children = con[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stacks.append((child, node))
print((*ans))
if __name__ == "__main__":
main()
| false | 9.302326 |
[
"- ops = []",
"- ops.append(tuple(map(int, input().split())))",
"- for op in ops:",
"- node = op[0] - 1",
"- pnt = op[1]",
"- ans[node] += pnt",
"+ p, v = list(map(int, input().split()))",
"+ ans[p - 1] += v"
] | false | 0.039757 | 0.042782 | 0.929291 |
[
"s734643600",
"s506917064"
] |
u452337391
|
p03544
|
python
|
s901090038
|
s224362737
| 30 | 26 | 9,032 | 9,060 |
Accepted
|
Accepted
| 13.33 |
N = int(eval(input()))
R = [None] * (N+1)
R[0] = 2
if N == 0:
print((R[0]))
exit()
R[1] =1
if N == 1:
print((R[1]))
exit()
if N >= 2:
for i in range(2, N+1):
R[i] = R[i-1] + R[i-2]
print((R[N]))
|
N = int(eval(input()))
R = [2, 1]
if N < 2:
print((R[N]))
exit()
for i in range(2, N+1):
R.append(R[i-1] + R[i-2])
print((R[N]))
| 15 | 8 | 229 | 137 |
N = int(eval(input()))
R = [None] * (N + 1)
R[0] = 2
if N == 0:
print((R[0]))
exit()
R[1] = 1
if N == 1:
print((R[1]))
exit()
if N >= 2:
for i in range(2, N + 1):
R[i] = R[i - 1] + R[i - 2]
print((R[N]))
|
N = int(eval(input()))
R = [2, 1]
if N < 2:
print((R[N]))
exit()
for i in range(2, N + 1):
R.append(R[i - 1] + R[i - 2])
print((R[N]))
| false | 46.666667 |
[
"-R = [None] * (N + 1)",
"-R[0] = 2",
"-if N == 0:",
"- print((R[0]))",
"+R = [2, 1]",
"+if N < 2:",
"+ print((R[N]))",
"-R[1] = 1",
"-if N == 1:",
"- print((R[1]))",
"- exit()",
"-if N >= 2:",
"- for i in range(2, N + 1):",
"- R[i] = R[i - 1] + R[i - 2]",
"- print((R[N]))",
"+for i in range(2, N + 1):",
"+ R.append(R[i - 1] + R[i - 2])",
"+print((R[N]))"
] | false | 0.043069 | 0.042482 | 1.013805 |
[
"s901090038",
"s224362737"
] |
u347640436
|
p03014
|
python
|
s657392211
|
s906575946
| 1,687 | 1,514 | 38,900 | 38,900 |
Accepted
|
Accepted
| 10.25 |
from sys import stdin
def main():
from itertools import repeat
from builtins import range
readline = stdin.readline
h, w = list(map(int, readline().split()))
s = [readline().rstrip('\r\n') + '#' for _ in range(h)]
s.append('#' * w)
yoko = [[0] * w for _ in range(h)]
for i in range(h):
start = -1
si = s[i]
yokoi = yoko[i]
for j in range(w + 1):
if si[j] == '#':
if start != -1:
t = j - start
yokoi[start:j] = repeat(t, t)
start = -1
else:
if start == -1:
start = j
result = 0
for i in range(w):
start = -1
for j in range(h + 1):
if s[j][i] == '#':
if start != -1:
t = yoko_max + j - start - 1
if t > result:
result = t
start = -1
else:
yji = yoko[j][i]
if start == -1:
start = j
yoko_max = yji
else:
if yji > yoko_max:
yoko_max = yji
print(result)
main()
|
from sys import stdin
def main():
from builtins import range
readline = stdin.readline
h, w = list(map(int, readline().split()))
s = [readline().rstrip('\r\n') + '#' for _ in range(h)]
s.append('#' * w)
yoko = [[0] * w for _ in range(h)]
for i in range(h):
start = -1
si = s[i]
yokoi = yoko[i]
for j in range(w + 1):
if si[j] == '#':
if start != -1:
t = j - start
yokoi[start:j] = [t] * t
start = -1
else:
if start == -1:
start = j
result = 0
for i in range(w):
start = -1
for j in range(h + 1):
if s[j][i] == '#':
if start != -1:
t = yoko_max + j - start - 1
if t > result:
result = t
start = -1
else:
yji = yoko[j][i]
if start == -1:
start = j
yoko_max = yji
else:
if yji > yoko_max:
yoko_max = yji
print(result)
main()
| 42 | 41 | 1,032 | 995 |
from sys import stdin
def main():
from itertools import repeat
from builtins import range
readline = stdin.readline
h, w = list(map(int, readline().split()))
s = [readline().rstrip("\r\n") + "#" for _ in range(h)]
s.append("#" * w)
yoko = [[0] * w for _ in range(h)]
for i in range(h):
start = -1
si = s[i]
yokoi = yoko[i]
for j in range(w + 1):
if si[j] == "#":
if start != -1:
t = j - start
yokoi[start:j] = repeat(t, t)
start = -1
else:
if start == -1:
start = j
result = 0
for i in range(w):
start = -1
for j in range(h + 1):
if s[j][i] == "#":
if start != -1:
t = yoko_max + j - start - 1
if t > result:
result = t
start = -1
else:
yji = yoko[j][i]
if start == -1:
start = j
yoko_max = yji
else:
if yji > yoko_max:
yoko_max = yji
print(result)
main()
|
from sys import stdin
def main():
from builtins import range
readline = stdin.readline
h, w = list(map(int, readline().split()))
s = [readline().rstrip("\r\n") + "#" for _ in range(h)]
s.append("#" * w)
yoko = [[0] * w for _ in range(h)]
for i in range(h):
start = -1
si = s[i]
yokoi = yoko[i]
for j in range(w + 1):
if si[j] == "#":
if start != -1:
t = j - start
yokoi[start:j] = [t] * t
start = -1
else:
if start == -1:
start = j
result = 0
for i in range(w):
start = -1
for j in range(h + 1):
if s[j][i] == "#":
if start != -1:
t = yoko_max + j - start - 1
if t > result:
result = t
start = -1
else:
yji = yoko[j][i]
if start == -1:
start = j
yoko_max = yji
else:
if yji > yoko_max:
yoko_max = yji
print(result)
main()
| false | 2.380952 |
[
"- from itertools import repeat",
"- yokoi[start:j] = repeat(t, t)",
"+ yokoi[start:j] = [t] * t"
] | false | 0.103937 | 0.108005 | 0.962337 |
[
"s657392211",
"s906575946"
] |
u033606236
|
p03329
|
python
|
s581170155
|
s662300096
| 1,044 | 881 | 3,828 | 3,828 |
Accepted
|
Accepted
| 15.61 |
n = int(eval(input()))
dp = [float("Inf")]*(n+1)
for i in range(n+1):
if i < 6:dp[i] = i
power = 1
while i >= 6 ** power:
dp[i] = min(dp[i],dp[i-6**power]+1)
power += 1
power = 1
while i >= 9 ** power:
dp[i] = min(dp[i],dp[i-9**power]+1)
power += 1
print((dp[n]))
|
n = int(eval(input()))
dp = [float("Inf")]*(n+1)
for i in range(n+1):
if i < 6:dp[i] = i
power = 1
while i >= 6 ** power:
if dp[i] > dp[i-6**power]+1:dp[i] = dp[i-6**power] + 1
power += 1
power = 1
while i >= 9 ** power:
if dp[i] > dp[i-9**power]+1:dp[i] = dp[i-9**power] + 1
power += 1
print((int(dp[n])))
| 13 | 13 | 319 | 362 |
n = int(eval(input()))
dp = [float("Inf")] * (n + 1)
for i in range(n + 1):
if i < 6:
dp[i] = i
power = 1
while i >= 6**power:
dp[i] = min(dp[i], dp[i - 6**power] + 1)
power += 1
power = 1
while i >= 9**power:
dp[i] = min(dp[i], dp[i - 9**power] + 1)
power += 1
print((dp[n]))
|
n = int(eval(input()))
dp = [float("Inf")] * (n + 1)
for i in range(n + 1):
if i < 6:
dp[i] = i
power = 1
while i >= 6**power:
if dp[i] > dp[i - 6**power] + 1:
dp[i] = dp[i - 6**power] + 1
power += 1
power = 1
while i >= 9**power:
if dp[i] > dp[i - 9**power] + 1:
dp[i] = dp[i - 9**power] + 1
power += 1
print((int(dp[n])))
| false | 0 |
[
"- dp[i] = min(dp[i], dp[i - 6**power] + 1)",
"+ if dp[i] > dp[i - 6**power] + 1:",
"+ dp[i] = dp[i - 6**power] + 1",
"- dp[i] = min(dp[i], dp[i - 9**power] + 1)",
"+ if dp[i] > dp[i - 9**power] + 1:",
"+ dp[i] = dp[i - 9**power] + 1",
"-print((dp[n]))",
"+print((int(dp[n])))"
] | false | 0.125645 | 0.116443 | 1.079021 |
[
"s581170155",
"s662300096"
] |
u811967730
|
p03835
|
python
|
s619295369
|
s709192946
| 1,916 | 1,626 | 2,940 | 2,940 |
Accepted
|
Accepted
| 15.14 |
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
if x > S:
break
for y in range(K + 1):
z = S - (x + y)
if z < 0:
break
if 0 <= z and z <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - (x + y)
if 0 <= z and z <= K:
count += 1
print(count)
| 14 | 10 | 262 | 194 |
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
if x > S:
break
for y in range(K + 1):
z = S - (x + y)
if z < 0:
break
if 0 <= z and z <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - (x + y)
if 0 <= z and z <= K:
count += 1
print(count)
| false | 28.571429 |
[
"- if x > S:",
"- break",
"- if z < 0:",
"- break"
] | false | 0.116916 | 0.036385 | 3.21326 |
[
"s619295369",
"s709192946"
] |
u672220554
|
p02972
|
python
|
s172533248
|
s454636637
| 837 | 448 | 17,204 | 17,208 |
Accepted
|
Accepted
| 46.48 |
n = int(eval(input()))
a = list(map(int,input().split()))
res = [0 for i in range(n)]
lres = []
for i in range(n,0,-1):
l = []
flag = 0
t = i*2
while t <= n:
flag = flag ^ res[t-1]
t = t+i
if a[i-1] != flag:
res[i-1] = 1
lres.append(str(i))
print((len(lres)))
if len(lres) != 0:
print((" ".join(lres)))
|
def main():
n = int(eval(input()))
a = list(map(int,input().split()))
res = [0 for i in range(n)]
lres = []
for i in range(n,0,-1):
l = []
flag = 0
t = i*2
while t <= n:
flag = flag ^ res[t-1]
t = t+i
if a[i-1] != flag:
res[i-1] = 1
lres.append(str(i))
print((len(lres)))
if len(lres) != 0:
print((" ".join(lres)))
main()
| 19 | 21 | 369 | 457 |
n = int(eval(input()))
a = list(map(int, input().split()))
res = [0 for i in range(n)]
lres = []
for i in range(n, 0, -1):
l = []
flag = 0
t = i * 2
while t <= n:
flag = flag ^ res[t - 1]
t = t + i
if a[i - 1] != flag:
res[i - 1] = 1
lres.append(str(i))
print((len(lres)))
if len(lres) != 0:
print((" ".join(lres)))
|
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
res = [0 for i in range(n)]
lres = []
for i in range(n, 0, -1):
l = []
flag = 0
t = i * 2
while t <= n:
flag = flag ^ res[t - 1]
t = t + i
if a[i - 1] != flag:
res[i - 1] = 1
lres.append(str(i))
print((len(lres)))
if len(lres) != 0:
print((" ".join(lres)))
main()
| false | 9.52381 |
[
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-res = [0 for i in range(n)]",
"-lres = []",
"-for i in range(n, 0, -1):",
"- l = []",
"- flag = 0",
"- t = i * 2",
"- while t <= n:",
"- flag = flag ^ res[t - 1]",
"- t = t + i",
"- if a[i - 1] != flag:",
"- res[i - 1] = 1",
"- lres.append(str(i))",
"-print((len(lres)))",
"-if len(lres) != 0:",
"- print((\" \".join(lres)))",
"+def main():",
"+ n = int(eval(input()))",
"+ a = list(map(int, input().split()))",
"+ res = [0 for i in range(n)]",
"+ lres = []",
"+ for i in range(n, 0, -1):",
"+ l = []",
"+ flag = 0",
"+ t = i * 2",
"+ while t <= n:",
"+ flag = flag ^ res[t - 1]",
"+ t = t + i",
"+ if a[i - 1] != flag:",
"+ res[i - 1] = 1",
"+ lres.append(str(i))",
"+ print((len(lres)))",
"+ if len(lres) != 0:",
"+ print((\" \".join(lres)))",
"+",
"+",
"+main()"
] | false | 0.045632 | 0.046037 | 0.991208 |
[
"s172533248",
"s454636637"
] |
u753803401
|
p02868
|
python
|
s746037804
|
s824032379
| 1,231 | 1,119 | 103,772 | 96,348 |
Accepted
|
Accepted
| 9.1 |
import sys
class AlgSegmentTreeMin:
def __init__(self, n, default_value):
self.Nelem = n
self.default_value = default_value
self.size = 1 << (n.bit_length())
self.data = [default_value] * (2 * self.size)
def update(self, i, x):
i += self.size
self.data[i] = x
i >>= 1
while i:
x = self.data[i + i]
y = self.data[i + i + 1]
self.data[i] = min(x, y)
i >>= 1
def get_value(self, left, right):
left += self.size
right += self.size + 1
x = self.default_value
while left < right:
if left & 1:
y = self.data[left]
x = min(x, y)
left += 1
if right & 1:
right -= 1
y = self.data[right]
x = min(x, y)
left >>= 1
right >>= 1
return x
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, m = list(map(int, input().rstrip('\n').split()))
stree = AlgSegmentTreeMin(n, 10 ** 15)
lrc = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
lrc.sort()
stree.update(0, 0)
for l, r, c in lrc:
l -= 1
r -= 1
tm = stree.get_value(l, r-1)
now = stree.get_value(r, r)
tm = tm + c if tm + c < now else now
stree.update(r, tm)
mt = stree.get_value(n-1, n)
print((mt if mt != stree.default_value else -1))
if __name__ == '__main__':
solve()
|
import sys
class AlgSegmentTreeMin:
def __init__(self, n, default_value):
self.Nelem = n
self.default_value = default_value
self.size = 1 << (n.bit_length())
self.data = [default_value] * (2 * self.size)
def update(self, i, x):
i += self.size
self.data[i] = x
i >>= 1
while i:
x = self.data[i + i]
y = self.data[i + i + 1]
self.data[i] = min(x, y)
i >>= 1
def get_value(self, left, right):
left += self.size
right += self.size + 1
x = self.default_value
while left < right:
if left & 1:
y = self.data[left]
x = min(x, y)
left += 1
if right & 1:
right -= 1
y = self.data[right]
x = min(x, y)
left >>= 1
right >>= 1
return x
def solve():
input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, input().split()))
stree = AlgSegmentTreeMin(n, 10 ** 15)
lrc = [list(map(int, input().split())) for _ in range(m)]
lrc.sort()
stree.update(0, 0)
for l, r, c in lrc:
l -= 1
r -= 1
tm = stree.get_value(l, r)
now = stree.get_value(r, r)
tm = tm + c if tm + c < now else now
stree.update(r, tm)
mt = stree.get_value(n-1, n)
print((mt if mt != stree.default_value else -1))
if __name__ == '__main__':
solve()
| 60 | 59 | 1,600 | 1,577 |
import sys
class AlgSegmentTreeMin:
def __init__(self, n, default_value):
self.Nelem = n
self.default_value = default_value
self.size = 1 << (n.bit_length())
self.data = [default_value] * (2 * self.size)
def update(self, i, x):
i += self.size
self.data[i] = x
i >>= 1
while i:
x = self.data[i + i]
y = self.data[i + i + 1]
self.data[i] = min(x, y)
i >>= 1
def get_value(self, left, right):
left += self.size
right += self.size + 1
x = self.default_value
while left < right:
if left & 1:
y = self.data[left]
x = min(x, y)
left += 1
if right & 1:
right -= 1
y = self.data[right]
x = min(x, y)
left >>= 1
right >>= 1
return x
def solve():
input = sys.stdin.readline
mod = 10**9 + 7
n, m = list(map(int, input().rstrip("\n").split()))
stree = AlgSegmentTreeMin(n, 10**15)
lrc = [list(map(int, input().rstrip("\n").split())) for _ in range(m)]
lrc.sort()
stree.update(0, 0)
for l, r, c in lrc:
l -= 1
r -= 1
tm = stree.get_value(l, r - 1)
now = stree.get_value(r, r)
tm = tm + c if tm + c < now else now
stree.update(r, tm)
mt = stree.get_value(n - 1, n)
print((mt if mt != stree.default_value else -1))
if __name__ == "__main__":
solve()
|
import sys
class AlgSegmentTreeMin:
def __init__(self, n, default_value):
self.Nelem = n
self.default_value = default_value
self.size = 1 << (n.bit_length())
self.data = [default_value] * (2 * self.size)
def update(self, i, x):
i += self.size
self.data[i] = x
i >>= 1
while i:
x = self.data[i + i]
y = self.data[i + i + 1]
self.data[i] = min(x, y)
i >>= 1
def get_value(self, left, right):
left += self.size
right += self.size + 1
x = self.default_value
while left < right:
if left & 1:
y = self.data[left]
x = min(x, y)
left += 1
if right & 1:
right -= 1
y = self.data[right]
x = min(x, y)
left >>= 1
right >>= 1
return x
def solve():
input = sys.stdin.buffer.readline
mod = 10**9 + 7
n, m = list(map(int, input().split()))
stree = AlgSegmentTreeMin(n, 10**15)
lrc = [list(map(int, input().split())) for _ in range(m)]
lrc.sort()
stree.update(0, 0)
for l, r, c in lrc:
l -= 1
r -= 1
tm = stree.get_value(l, r)
now = stree.get_value(r, r)
tm = tm + c if tm + c < now else now
stree.update(r, tm)
mt = stree.get_value(n - 1, n)
print((mt if mt != stree.default_value else -1))
if __name__ == "__main__":
solve()
| false | 1.666667 |
[
"- input = sys.stdin.readline",
"+ input = sys.stdin.buffer.readline",
"- n, m = list(map(int, input().rstrip(\"\\n\").split()))",
"+ n, m = list(map(int, input().split()))",
"- lrc = [list(map(int, input().rstrip(\"\\n\").split())) for _ in range(m)]",
"+ lrc = [list(map(int, input().split())) for _ in range(m)]",
"- tm = stree.get_value(l, r - 1)",
"+ tm = stree.get_value(l, r)"
] | false | 0.037241 | 0.037076 | 1.004448 |
[
"s746037804",
"s824032379"
] |
u489959379
|
p02784
|
python
|
s701985879
|
s218511971
| 54 | 39 | 13,964 | 13,864 |
Accepted
|
Accepted
| 27.78 |
h, n = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
h -= a[i]
if h <= 0:
print("Yes")
else:
print("No")
|
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
h, n = list(map(int, input().split()))
A = list(map(int, input().split()))
print(("Yes" if h <= sum(A) else "No"))
if __name__ == '__main__':
resolve()
| 10 | 17 | 162 | 305 |
h, n = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
h -= a[i]
if h <= 0:
print("Yes")
else:
print("No")
|
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
h, n = list(map(int, input().split()))
A = list(map(int, input().split()))
print(("Yes" if h <= sum(A) else "No"))
if __name__ == "__main__":
resolve()
| false | 41.176471 |
[
"-h, n = list(map(int, input().split()))",
"-a = list(map(int, input().split()))",
"-for i in range(n):",
"- h -= a[i]",
"-if h <= 0:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+input = sys.stdin.readline",
"+f_inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+",
"+",
"+def resolve():",
"+ h, n = list(map(int, input().split()))",
"+ A = list(map(int, input().split()))",
"+ print((\"Yes\" if h <= sum(A) else \"No\"))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.078052 | 0.03504 | 2.227486 |
[
"s701985879",
"s218511971"
] |
u340500592
|
p02390
|
python
|
s608800399
|
s877019269
| 30 | 20 | 7,660 | 7,664 |
Accepted
|
Accepted
| 33.33 |
S = int(eval(input()))
h = int(S / 3600)
m = int( (S - h * 60**2) / 60)
s = int( (S - h * 60**2 - m * 60))
print((str(h) + ':' + str(m) + ':' + str(s)))
|
S = int(eval(input()))
h = S // 3600
m = (S % 3600) // 60
s = (S % 3600) % 60
print((str(h) + ':' + str(m) + ':' + str(s)))
| 5 | 5 | 148 | 119 |
S = int(eval(input()))
h = int(S / 3600)
m = int((S - h * 60**2) / 60)
s = int((S - h * 60**2 - m * 60))
print((str(h) + ":" + str(m) + ":" + str(s)))
|
S = int(eval(input()))
h = S // 3600
m = (S % 3600) // 60
s = (S % 3600) % 60
print((str(h) + ":" + str(m) + ":" + str(s)))
| false | 0 |
[
"-h = int(S / 3600)",
"-m = int((S - h * 60**2) / 60)",
"-s = int((S - h * 60**2 - m * 60))",
"+h = S // 3600",
"+m = (S % 3600) // 60",
"+s = (S % 3600) % 60"
] | false | 0.061167 | 0.060307 | 1.014261 |
[
"s608800399",
"s877019269"
] |
u747602774
|
p02781
|
python
|
s532733122
|
s931731635
| 45 | 19 | 3,188 | 3,444 |
Accepted
|
Accepted
| 57.78 |
import itertools
N = eval(input())
K = int(eval(input()))
lN = len(N)
if K == 1:
ans = int(N[0])+9*(lN-1)
print(ans)
elif K == 2:
not0 = 1000
for i in range(1,lN):
if int(N[i]) != 0:
not0 = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n,2):
if v[0] != 0:
ans += 9*9
else:
if not0 >= v[1]:
ans += (int(N[0])-1)*9 + int(N[v[1]])
else:
ans += int(N[0])*9
print(ans)
else:
not0f = 1000
not0s = 1000
for i in range(1,lN):
if int(N[i]) != 0:
not0f = i
break
for i in range(not0f+1,lN):
if int(N[i]) != 0:
not0s = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n,3):
if v[0] != 0:
ans += 9*9*9
else:
if not0f == v[1]:
if not0s >= v[2]:
ans += (int(N[0])-1)*9*9
ans += (int(N[v[1]])-1)*9
ans += int(N[v[2]])
else:
ans += (int(N[0])-1)*9*9
ans += int(N[v[1]])*9
elif not0f < v[1]:
ans += int(N[0])*9*9
else:
ans += (int(N[0])-1)*9*9
print(ans)
|
N = int(eval(input()))
K = int(eval(input()))
S = str(N)
'''
ans = 0
li = []
for i in range(1,N+1):
if str(i).count('0') == len(str(i)) - K:
ans += 1
li.append(i)
print(ans)
print(li)
'''
L = len(S)
dp = [[[1, 0], [0, 0], [0, 0], [0, 0]] for i in range(L)]
dp[0] = [[1, 0], [int(S[0])-1, 1], [0, 0], [0, 0]]
#print(dp)
for l in range(1,L):
s = int(S[l])
if s == 0:
dp[l][1][1] += dp[l-1][1][1]
dp[l][2][1] += dp[l-1][2][1]
else:
dp[l][1][1] += dp[l-1][0][1]
dp[l][2][1] += dp[l-1][1][1]
dp[l][3][1] += dp[l-1][2][1]
dp[l][1][0] += dp[l-1][1][1]
dp[l][2][0] += dp[l-1][2][1]
dp[l][3][0] += dp[l-1][3][1]
dp[l][1][0] += dp[l-1][0][0]*9 + dp[l-1][1][0]
dp[l][2][0] += dp[l-1][1][0]*9 + dp[l-1][2][0]
dp[l][3][0] += dp[l-1][2][0]*9 + dp[l-1][3][0]
dp[l][1][0] += dp[l-1][0][1]*max(0,s-1)
dp[l][2][0] += dp[l-1][1][1]*max(0,s-1)
dp[l][3][0] += dp[l-1][2][1]*max(0,s-1)
#print(dp)
print((sum(dp[L-1][K])))
| 58 | 40 | 1,414 | 1,047 |
import itertools
N = eval(input())
K = int(eval(input()))
lN = len(N)
if K == 1:
ans = int(N[0]) + 9 * (lN - 1)
print(ans)
elif K == 2:
not0 = 1000
for i in range(1, lN):
if int(N[i]) != 0:
not0 = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n, 2):
if v[0] != 0:
ans += 9 * 9
else:
if not0 >= v[1]:
ans += (int(N[0]) - 1) * 9 + int(N[v[1]])
else:
ans += int(N[0]) * 9
print(ans)
else:
not0f = 1000
not0s = 1000
for i in range(1, lN):
if int(N[i]) != 0:
not0f = i
break
for i in range(not0f + 1, lN):
if int(N[i]) != 0:
not0s = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n, 3):
if v[0] != 0:
ans += 9 * 9 * 9
else:
if not0f == v[1]:
if not0s >= v[2]:
ans += (int(N[0]) - 1) * 9 * 9
ans += (int(N[v[1]]) - 1) * 9
ans += int(N[v[2]])
else:
ans += (int(N[0]) - 1) * 9 * 9
ans += int(N[v[1]]) * 9
elif not0f < v[1]:
ans += int(N[0]) * 9 * 9
else:
ans += (int(N[0]) - 1) * 9 * 9
print(ans)
|
N = int(eval(input()))
K = int(eval(input()))
S = str(N)
"""
ans = 0
li = []
for i in range(1,N+1):
if str(i).count('0') == len(str(i)) - K:
ans += 1
li.append(i)
print(ans)
print(li)
"""
L = len(S)
dp = [[[1, 0], [0, 0], [0, 0], [0, 0]] for i in range(L)]
dp[0] = [[1, 0], [int(S[0]) - 1, 1], [0, 0], [0, 0]]
# print(dp)
for l in range(1, L):
s = int(S[l])
if s == 0:
dp[l][1][1] += dp[l - 1][1][1]
dp[l][2][1] += dp[l - 1][2][1]
else:
dp[l][1][1] += dp[l - 1][0][1]
dp[l][2][1] += dp[l - 1][1][1]
dp[l][3][1] += dp[l - 1][2][1]
dp[l][1][0] += dp[l - 1][1][1]
dp[l][2][0] += dp[l - 1][2][1]
dp[l][3][0] += dp[l - 1][3][1]
dp[l][1][0] += dp[l - 1][0][0] * 9 + dp[l - 1][1][0]
dp[l][2][0] += dp[l - 1][1][0] * 9 + dp[l - 1][2][0]
dp[l][3][0] += dp[l - 1][2][0] * 9 + dp[l - 1][3][0]
dp[l][1][0] += dp[l - 1][0][1] * max(0, s - 1)
dp[l][2][0] += dp[l - 1][1][1] * max(0, s - 1)
dp[l][3][0] += dp[l - 1][2][1] * max(0, s - 1)
# print(dp)
print((sum(dp[L - 1][K])))
| false | 31.034483 |
[
"-import itertools",
"-",
"-N = eval(input())",
"+N = int(eval(input()))",
"-lN = len(N)",
"-if K == 1:",
"- ans = int(N[0]) + 9 * (lN - 1)",
"- print(ans)",
"-elif K == 2:",
"- not0 = 1000",
"- for i in range(1, lN):",
"- if int(N[i]) != 0:",
"- not0 = i",
"- break",
"- ans = 0",
"- n = [i for i in range(lN)]",
"- for v in itertools.combinations(n, 2):",
"- if v[0] != 0:",
"- ans += 9 * 9",
"- else:",
"- if not0 >= v[1]:",
"- ans += (int(N[0]) - 1) * 9 + int(N[v[1]])",
"- else:",
"- ans += int(N[0]) * 9",
"- print(ans)",
"-else:",
"- not0f = 1000",
"- not0s = 1000",
"- for i in range(1, lN):",
"- if int(N[i]) != 0:",
"- not0f = i",
"- break",
"- for i in range(not0f + 1, lN):",
"- if int(N[i]) != 0:",
"- not0s = i",
"- break",
"- ans = 0",
"- n = [i for i in range(lN)]",
"- for v in itertools.combinations(n, 3):",
"- if v[0] != 0:",
"- ans += 9 * 9 * 9",
"- else:",
"- if not0f == v[1]:",
"- if not0s >= v[2]:",
"- ans += (int(N[0]) - 1) * 9 * 9",
"- ans += (int(N[v[1]]) - 1) * 9",
"- ans += int(N[v[2]])",
"- else:",
"- ans += (int(N[0]) - 1) * 9 * 9",
"- ans += int(N[v[1]]) * 9",
"- elif not0f < v[1]:",
"- ans += int(N[0]) * 9 * 9",
"- else:",
"- ans += (int(N[0]) - 1) * 9 * 9",
"- print(ans)",
"+S = str(N)",
"+\"\"\"",
"+ans = 0",
"+li = []",
"+for i in range(1,N+1):",
"+ if str(i).count('0') == len(str(i)) - K:",
"+ ans += 1",
"+ li.append(i)",
"+print(ans)",
"+print(li)",
"+\"\"\"",
"+L = len(S)",
"+dp = [[[1, 0], [0, 0], [0, 0], [0, 0]] for i in range(L)]",
"+dp[0] = [[1, 0], [int(S[0]) - 1, 1], [0, 0], [0, 0]]",
"+# print(dp)",
"+for l in range(1, L):",
"+ s = int(S[l])",
"+ if s == 0:",
"+ dp[l][1][1] += dp[l - 1][1][1]",
"+ dp[l][2][1] += dp[l - 1][2][1]",
"+ else:",
"+ dp[l][1][1] += dp[l - 1][0][1]",
"+ dp[l][2][1] += dp[l - 1][1][1]",
"+ dp[l][3][1] += dp[l - 1][2][1]",
"+ dp[l][1][0] += dp[l - 1][1][1]",
"+ dp[l][2][0] += dp[l - 1][2][1]",
"+ dp[l][3][0] += dp[l - 1][3][1]",
"+ dp[l][1][0] += dp[l - 1][0][0] * 9 + dp[l - 1][1][0]",
"+ dp[l][2][0] += dp[l - 1][1][0] * 9 + dp[l - 1][2][0]",
"+ dp[l][3][0] += dp[l - 1][2][0] * 9 + dp[l - 1][3][0]",
"+ dp[l][1][0] += dp[l - 1][0][1] * max(0, s - 1)",
"+ dp[l][2][0] += dp[l - 1][1][1] * max(0, s - 1)",
"+ dp[l][3][0] += dp[l - 1][2][1] * max(0, s - 1)",
"+# print(dp)",
"+print((sum(dp[L - 1][K])))"
] | false | 0.048657 | 0.048468 | 1.003888 |
[
"s532733122",
"s931731635"
] |
u782001565
|
p03424
|
python
|
s757972791
|
s760797852
| 30 | 27 | 9,140 | 9,164 |
Accepted
|
Accepted
| 10 |
N = int(eval(input()))
S = list(map(str, input().split()))
candy_list = ['P', 'W', 'G', 'Y']
answer = 0
for i in range(4):
if candy_list[i] in S:
answer += 1
if answer == 3:
print('Three')
if answer == 4:
print('Four')
|
N = int(eval(input()))
S = list(map(str, input().split()))
if 'Y' in S:
answer = 'Four'
else:
answer = 'Three'
print(answer)
| 13 | 8 | 246 | 134 |
N = int(eval(input()))
S = list(map(str, input().split()))
candy_list = ["P", "W", "G", "Y"]
answer = 0
for i in range(4):
if candy_list[i] in S:
answer += 1
if answer == 3:
print("Three")
if answer == 4:
print("Four")
|
N = int(eval(input()))
S = list(map(str, input().split()))
if "Y" in S:
answer = "Four"
else:
answer = "Three"
print(answer)
| false | 38.461538 |
[
"-candy_list = [\"P\", \"W\", \"G\", \"Y\"]",
"-answer = 0",
"-for i in range(4):",
"- if candy_list[i] in S:",
"- answer += 1",
"-if answer == 3:",
"- print(\"Three\")",
"-if answer == 4:",
"- print(\"Four\")",
"+if \"Y\" in S:",
"+ answer = \"Four\"",
"+else:",
"+ answer = \"Three\"",
"+print(answer)"
] | false | 0.047698 | 0.184069 | 0.259133 |
[
"s757972791",
"s760797852"
] |
u059210959
|
p03208
|
python
|
s025890509
|
s470753818
| 426 | 207 | 24,196 | 15,088 |
Accepted
|
Accepted
| 51.41 |
# encoding:utf-8
import copy
import numpy as np
import random
n,k = list(map(int,input().split()))
h = []
for i in range(n):
h.append(int(eval(input())))
h.sort()
# print(h)
max_tree = []
min_tree = []
ans = 10**9
for i in range(n-k+1):
ans = min(h[i+k-1]-h[i],ans)
print(ans)
|
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, K = LI()
h = [0 for i in range(N)]
for i in range(N):
h[i] = int(eval(input()))
h.sort()
ans = mod
for i in range(N - K + 1):
# print(h[i+K - 1] , h[i])
ans = min(ans, h[i + K - 1] - h[i])
print(ans)
| 21 | 28 | 298 | 611 |
# encoding:utf-8
import copy
import numpy as np
import random
n, k = list(map(int, input().split()))
h = []
for i in range(n):
h.append(int(eval(input())))
h.sort()
# print(h)
max_tree = []
min_tree = []
ans = 10**9
for i in range(n - k + 1):
ans = min(h[i + k - 1] - h[i], ans)
print(ans)
|
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect # bisect_left これで二部探索の大小検索が行える
import fractions # 最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9 + 7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI():
return list(map(int, sys.stdin.readline().split()))
N, K = LI()
h = [0 for i in range(N)]
for i in range(N):
h[i] = int(eval(input()))
h.sort()
ans = mod
for i in range(N - K + 1):
# print(h[i+K - 1] , h[i])
ans = min(ans, h[i + K - 1] - h[i])
print(ans)
| false | 25 |
[
"+#!/usr/bin/env python3",
"-import numpy as np",
"+import bisect # bisect_left これで二部探索の大小検索が行える",
"+import fractions # 最小公倍数などはこっち",
"+import math",
"+import sys",
"+import collections",
"+from decimal import Decimal # 10進数で考慮できる",
"-n, k = list(map(int, input().split()))",
"-h = []",
"-for i in range(n):",
"- h.append(int(eval(input())))",
"+mod = 10**9 + 7",
"+sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000",
"+d = collections.deque()",
"+",
"+",
"+def LI():",
"+ return list(map(int, sys.stdin.readline().split()))",
"+",
"+",
"+N, K = LI()",
"+h = [0 for i in range(N)]",
"+for i in range(N):",
"+ h[i] = int(eval(input()))",
"-# print(h)",
"-max_tree = []",
"-min_tree = []",
"-ans = 10**9",
"-for i in range(n - k + 1):",
"- ans = min(h[i + k - 1] - h[i], ans)",
"+ans = mod",
"+for i in range(N - K + 1):",
"+ # print(h[i+K - 1] , h[i])",
"+ ans = min(ans, h[i + K - 1] - h[i])"
] | false | 0.119676 | 0.148508 | 0.805857 |
[
"s025890509",
"s470753818"
] |
u565149926
|
p03075
|
python
|
s702090925
|
s886538978
| 165 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 89.7 |
num_a = 5
antennas = [int(eval(input())) for _ in range(num_a)]
k = int(eval(input()))
exist = False
for q in range(num_a - 1, 0, -1):
for p in range(q - 1, -1, -1):
if antennas[q] - antennas[p] > k:
exist = True
break
if exist:
print(":(")
else:
print("Yay!")
|
N = 5
inputs = [int(eval(input())) for _ in range(N)]
k = int(eval(input()))
print((":(" if inputs[N-1] - inputs[0] > k else "Yay!"))
| 14 | 4 | 307 | 123 |
num_a = 5
antennas = [int(eval(input())) for _ in range(num_a)]
k = int(eval(input()))
exist = False
for q in range(num_a - 1, 0, -1):
for p in range(q - 1, -1, -1):
if antennas[q] - antennas[p] > k:
exist = True
break
if exist:
print(":(")
else:
print("Yay!")
|
N = 5
inputs = [int(eval(input())) for _ in range(N)]
k = int(eval(input()))
print((":(" if inputs[N - 1] - inputs[0] > k else "Yay!"))
| false | 71.428571 |
[
"-num_a = 5",
"-antennas = [int(eval(input())) for _ in range(num_a)]",
"+N = 5",
"+inputs = [int(eval(input())) for _ in range(N)]",
"-exist = False",
"-for q in range(num_a - 1, 0, -1):",
"- for p in range(q - 1, -1, -1):",
"- if antennas[q] - antennas[p] > k:",
"- exist = True",
"- break",
"-if exist:",
"- print(\":(\")",
"-else:",
"- print(\"Yay!\")",
"+print((\":(\" if inputs[N - 1] - inputs[0] > k else \"Yay!\"))"
] | false | 0.03619 | 0.037749 | 0.958707 |
[
"s702090925",
"s886538978"
] |
u102461423
|
p03216
|
python
|
s974541417
|
s341530514
| 1,289 | 1,063 | 55,512 | 58,432 |
Accepted
|
Accepted
| 17.53 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
S = np.frombuffer(b'-'+readline().rstrip(),'S1')
Q = int(readline())
query = list(map(int,read().split()))
isD = S == b'D'
isM = S == b'M'
isC = S == b'C'
cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)
def F(K):
x = cumD.copy(); x[K:] -= cumD[:-K]
x *= isM
x[K+1:] -= isD[1:-K] * (cumM[K:-1] - cumM[:-K-1])
return (x.cumsum() * isC).sum()
print(('\n'.join(str(F(K)) for K in query)))
|
from numpy import *
I=input
N=int(I())
S=array(list('-'+I()))
Q=int(I())
query = list(map(int,I().split()))
D=S=='D';M=S=='M';C=S=='C'
d=D.cumsum(dtype=int64);m=M.cumsum(dtype=int64)
for K in query:
x=d.copy();x[K:]-=d[:-K];x*=M
x[K+1:]-=D[1:-K]*(m[K:-1]-m[:-K-1])
print((sum(cumsum(x)*C)))
| 26 | 12 | 598 | 299 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
S = np.frombuffer(b"-" + readline().rstrip(), "S1")
Q = int(readline())
query = list(map(int, read().split()))
isD = S == b"D"
isM = S == b"M"
isC = S == b"C"
cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)
def F(K):
x = cumD.copy()
x[K:] -= cumD[:-K]
x *= isM
x[K + 1 :] -= isD[1:-K] * (cumM[K:-1] - cumM[: -K - 1])
return (x.cumsum() * isC).sum()
print(("\n".join(str(F(K)) for K in query)))
|
from numpy import *
I = input
N = int(I())
S = array(list("-" + I()))
Q = int(I())
query = list(map(int, I().split()))
D = S == "D"
M = S == "M"
C = S == "C"
d = D.cumsum(dtype=int64)
m = M.cumsum(dtype=int64)
for K in query:
x = d.copy()
x[K:] -= d[:-K]
x *= M
x[K + 1 :] -= D[1:-K] * (m[K:-1] - m[: -K - 1])
print((sum(cumsum(x) * C)))
| false | 53.846154 |
[
"-import sys",
"+from numpy import *",
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines",
"-import numpy as np",
"-",
"-N = int(readline())",
"-S = np.frombuffer(b\"-\" + readline().rstrip(), \"S1\")",
"-Q = int(readline())",
"-query = list(map(int, read().split()))",
"-isD = S == b\"D\"",
"-isM = S == b\"M\"",
"-isC = S == b\"C\"",
"-cumD = isD.cumsum(dtype=np.int64)",
"-cumM = isM.cumsum(dtype=np.int64)",
"-",
"-",
"-def F(K):",
"- x = cumD.copy()",
"- x[K:] -= cumD[:-K]",
"- x *= isM",
"- x[K + 1 :] -= isD[1:-K] * (cumM[K:-1] - cumM[: -K - 1])",
"- return (x.cumsum() * isC).sum()",
"-",
"-",
"-print((\"\\n\".join(str(F(K)) for K in query)))",
"+I = input",
"+N = int(I())",
"+S = array(list(\"-\" + I()))",
"+Q = int(I())",
"+query = list(map(int, I().split()))",
"+D = S == \"D\"",
"+M = S == \"M\"",
"+C = S == \"C\"",
"+d = D.cumsum(dtype=int64)",
"+m = M.cumsum(dtype=int64)",
"+for K in query:",
"+ x = d.copy()",
"+ x[K:] -= d[:-K]",
"+ x *= M",
"+ x[K + 1 :] -= D[1:-K] * (m[K:-1] - m[: -K - 1])",
"+ print((sum(cumsum(x) * C)))"
] | false | 0.580445 | 0.194599 | 2.982778 |
[
"s974541417",
"s341530514"
] |
u173148629
|
p02756
|
python
|
s844097413
|
s237443527
| 839 | 523 | 70,232 | 8,692 |
Accepted
|
Accepted
| 37.66 |
S=eval(input())
Q=int(eval(input()))
X=[]
Y=[]
f=1
for _ in range(Q):
A=list(input().split())
if A[0]=="1":
f*=-1
if A[0]=="2":
if A[1]=="1":
if f==1:
X.append(A[2])
if f==-1:
Y.append(A[2])
if A[1]=="2":
if f==-1:
X.append(A[2])
if f==1:
Y.append(A[2])
x="".join(X)
x="".join(list(reversed(x)))
y="".join(Y)
a=[x,S,y]
b="".join(a)
if f==-1:
b="".join(list(reversed(b)))
print(b)
|
from collections import deque
S=eval(input())
Q=int(eval(input()))
X=deque(S)
f=1
for _ in range(Q):
A=list(input().split())
if A[0]=="1":
f*=-1
if A[0]=="2":
if A[1]=="1":
if f==1:
X.appendleft(A[2])
if f==-1:
X.append(A[2])
if A[1]=="2":
if f==-1:
X.appendleft(A[2])
if f==1:
X.append(A[2])
if f==-1:
print(("".join(list(reversed(X)))))
else:
print(("".join(list(X))))
| 33 | 26 | 557 | 537 |
S = eval(input())
Q = int(eval(input()))
X = []
Y = []
f = 1
for _ in range(Q):
A = list(input().split())
if A[0] == "1":
f *= -1
if A[0] == "2":
if A[1] == "1":
if f == 1:
X.append(A[2])
if f == -1:
Y.append(A[2])
if A[1] == "2":
if f == -1:
X.append(A[2])
if f == 1:
Y.append(A[2])
x = "".join(X)
x = "".join(list(reversed(x)))
y = "".join(Y)
a = [x, S, y]
b = "".join(a)
if f == -1:
b = "".join(list(reversed(b)))
print(b)
|
from collections import deque
S = eval(input())
Q = int(eval(input()))
X = deque(S)
f = 1
for _ in range(Q):
A = list(input().split())
if A[0] == "1":
f *= -1
if A[0] == "2":
if A[1] == "1":
if f == 1:
X.appendleft(A[2])
if f == -1:
X.append(A[2])
if A[1] == "2":
if f == -1:
X.appendleft(A[2])
if f == 1:
X.append(A[2])
if f == -1:
print(("".join(list(reversed(X)))))
else:
print(("".join(list(X))))
| false | 21.212121 |
[
"+from collections import deque",
"+",
"-X = []",
"-Y = []",
"+X = deque(S)",
"+ X.appendleft(A[2])",
"+ if f == -1:",
"- if f == -1:",
"- Y.append(A[2])",
"+ X.appendleft(A[2])",
"+ if f == 1:",
"- if f == 1:",
"- Y.append(A[2])",
"-x = \"\".join(X)",
"-x = \"\".join(list(reversed(x)))",
"-y = \"\".join(Y)",
"-a = [x, S, y]",
"-b = \"\".join(a)",
"- b = \"\".join(list(reversed(b)))",
"-print(b)",
"+ print((\"\".join(list(reversed(X)))))",
"+else:",
"+ print((\"\".join(list(X))))"
] | false | 0.126318 | 0.08928 | 1.414851 |
[
"s844097413",
"s237443527"
] |
u994307795
|
p02785
|
python
|
s748277449
|
s131543698
| 189 | 152 | 25,768 | 26,024 |
Accepted
|
Accepted
| 19.58 |
n, k = list(map(int, input().split()))
h = [int(i) for i in input().split()]
h = sorted(h)[::-1]
ans = 0
for i in range(k, n):
ans += h[i]
print(ans)
|
n, k = list(map(int, input().split()))
h = sorted(list(map(int, input().split())), reverse=True)
print((sum(h[k:])))
| 10 | 3 | 156 | 110 |
n, k = list(map(int, input().split()))
h = [int(i) for i in input().split()]
h = sorted(h)[::-1]
ans = 0
for i in range(k, n):
ans += h[i]
print(ans)
|
n, k = list(map(int, input().split()))
h = sorted(list(map(int, input().split())), reverse=True)
print((sum(h[k:])))
| false | 70 |
[
"-h = [int(i) for i in input().split()]",
"-h = sorted(h)[::-1]",
"-ans = 0",
"-for i in range(k, n):",
"- ans += h[i]",
"-print(ans)",
"+h = sorted(list(map(int, input().split())), reverse=True)",
"+print((sum(h[k:])))"
] | false | 0.045676 | 0.045364 | 1.006878 |
[
"s748277449",
"s131543698"
] |
u869919400
|
p02743
|
python
|
s280799280
|
s850872148
| 260 | 194 | 59,756 | 38,384 |
Accepted
|
Accepted
| 25.38 |
a, b, c = list(map(int, input().split()))
from decimal import Decimal
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
print('Yes')
else:
print('No')
|
a,b,c = list(map(int, input().split()))
if 4*a*b < (c-a-b)**2 and c-a-b > 0:
print('Yes')
else:
print('No')
| 8 | 6 | 173 | 115 |
a, b, c = list(map(int, input().split()))
from decimal import Decimal
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
print("Yes")
else:
print("No")
|
a, b, c = list(map(int, input().split()))
if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0:
print("Yes")
else:
print("No")
| false | 25 |
[
"-from decimal import Decimal",
"-",
"-if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():",
"+if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0:"
] | false | 0.040242 | 0.037905 | 1.061642 |
[
"s280799280",
"s850872148"
] |
u001024152
|
p03212
|
python
|
s930025760
|
s613365111
| 89 | 53 | 3,060 | 3,316 |
Accepted
|
Accepted
| 40.45 |
N = int(eval(input()))
def dfs(s):
if int(s)>N:
return 0
for c in list("753"):
if s.count(c) < 1:
ret = 0
break
else:
ret = 1
for c in list("753"):
ret += dfs(s+c)
return ret
print((dfs("0")))
|
from collections import deque
N = int(eval(input()))
ans = 0
q = deque([7, 5, 3])
while q:
s = q.pop()
str_s = str(s)
ok = True
ok &= "7" in str_s
ok &= "5" in str_s
ok &= "3" in str_s
ok &= s <= N
if ok:
ans += 1
if len(str_s) < 9:
q.append(10*s + 3)
q.append(10*s + 5)
q.append(10*s + 7)
print(ans)
| 16 | 22 | 278 | 387 |
N = int(eval(input()))
def dfs(s):
if int(s) > N:
return 0
for c in list("753"):
if s.count(c) < 1:
ret = 0
break
else:
ret = 1
for c in list("753"):
ret += dfs(s + c)
return ret
print((dfs("0")))
|
from collections import deque
N = int(eval(input()))
ans = 0
q = deque([7, 5, 3])
while q:
s = q.pop()
str_s = str(s)
ok = True
ok &= "7" in str_s
ok &= "5" in str_s
ok &= "3" in str_s
ok &= s <= N
if ok:
ans += 1
if len(str_s) < 9:
q.append(10 * s + 3)
q.append(10 * s + 5)
q.append(10 * s + 7)
print(ans)
| false | 27.272727 |
[
"+from collections import deque",
"+",
"-",
"-",
"-def dfs(s):",
"- if int(s) > N:",
"- return 0",
"- for c in list(\"753\"):",
"- if s.count(c) < 1:",
"- ret = 0",
"- break",
"- else:",
"- ret = 1",
"- for c in list(\"753\"):",
"- ret += dfs(s + c)",
"- return ret",
"-",
"-",
"-print((dfs(\"0\")))",
"+ans = 0",
"+q = deque([7, 5, 3])",
"+while q:",
"+ s = q.pop()",
"+ str_s = str(s)",
"+ ok = True",
"+ ok &= \"7\" in str_s",
"+ ok &= \"5\" in str_s",
"+ ok &= \"3\" in str_s",
"+ ok &= s <= N",
"+ if ok:",
"+ ans += 1",
"+ if len(str_s) < 9:",
"+ q.append(10 * s + 3)",
"+ q.append(10 * s + 5)",
"+ q.append(10 * s + 7)",
"+print(ans)"
] | false | 0.114542 | 0.070627 | 1.621789 |
[
"s930025760",
"s613365111"
] |
u878545651
|
p02577
|
python
|
s405798833
|
s884754063
| 205 | 52 | 9,264 | 10,764 |
Accepted
|
Accepted
| 74.63 |
def main():
N = int(input())
print('Yes') if N % 9 == 0 else print('No')
if __name__ == '__main__':
main()
|
def main():
N = str(input())
M = list(map(int, N))
S = sum(M)
print('Yes') if S % 9 == 0 else print('No')
if __name__ == '__main__':
main()
| 7 | 10 | 126 | 174 |
def main():
N = int(input())
print("Yes") if N % 9 == 0 else print("No")
if __name__ == "__main__":
main()
|
def main():
N = str(input())
M = list(map(int, N))
S = sum(M)
print("Yes") if S % 9 == 0 else print("No")
if __name__ == "__main__":
main()
| false | 30 |
[
"- N = int(input())",
"- print(\"Yes\") if N % 9 == 0 else print(\"No\")",
"+ N = str(input())",
"+ M = list(map(int, N))",
"+ S = sum(M)",
"+ print(\"Yes\") if S % 9 == 0 else print(\"No\")"
] | false | 0.095897 | 0.038528 | 2.48904 |
[
"s405798833",
"s884754063"
] |
u638282348
|
p03220
|
python
|
s511533246
|
s974019210
| 327 | 150 | 21,556 | 12,484 |
Accepted
|
Accepted
| 54.13 |
from numpy import array, argmin
eval(input())
temp_on_sea, oracle = list(map(int, input().rstrip("\n").split()))
heights = list(map(int , input().rstrip("\n").split()))
temp_diff = [abs(temp_on_sea - height * 0.006 - oracle) for height in heights]
print((array(temp_diff).argmin() + 1))
|
from numpy import argmin
eval(input())
T, A = list(map(int, input().split()))
print((argmin([abs(T - x * 0.006 - A) for x in map(int, input().split())]) + 1))
| 8 | 4 | 282 | 147 |
from numpy import array, argmin
eval(input())
temp_on_sea, oracle = list(map(int, input().rstrip("\n").split()))
heights = list(map(int, input().rstrip("\n").split()))
temp_diff = [abs(temp_on_sea - height * 0.006 - oracle) for height in heights]
print((array(temp_diff).argmin() + 1))
|
from numpy import argmin
eval(input())
T, A = list(map(int, input().split()))
print((argmin([abs(T - x * 0.006 - A) for x in map(int, input().split())]) + 1))
| false | 50 |
[
"-from numpy import array, argmin",
"+from numpy import argmin",
"-temp_on_sea, oracle = list(map(int, input().rstrip(\"\\n\").split()))",
"-heights = list(map(int, input().rstrip(\"\\n\").split()))",
"-temp_diff = [abs(temp_on_sea - height * 0.006 - oracle) for height in heights]",
"-print((array(temp_diff).argmin() + 1))",
"+T, A = list(map(int, input().split()))",
"+print((argmin([abs(T - x * 0.006 - A) for x in map(int, input().split())]) + 1))"
] | false | 0.176352 | 0.20932 | 0.842498 |
[
"s511533246",
"s974019210"
] |
u837745858
|
p02842
|
python
|
s226632909
|
s707692772
| 31 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 45.16 |
# Input the amount of money Takahashi paid
N = int(eval(input()))
# Check if the price before tax is X, for X = 1, 2, 3, ..., N
ans = -1
for i in range(1, N + 1):
if int(i * 1.08) == N:
ans = i
# Print answer
if ans != -1:
print(ans)
else:
print(":(")
|
import math
# Input the amount of money Takahashi paid
N = int(eval(input()))
# Find nearest integer price more than or equal to X/1.08
X = math.ceil(N / 1.08)
# Check if the "taxed price" is equal to N yen
if math.floor(X * 1.08) == N:
print(X)
else:
print(":(")
| 14 | 13 | 265 | 274 |
# Input the amount of money Takahashi paid
N = int(eval(input()))
# Check if the price before tax is X, for X = 1, 2, 3, ..., N
ans = -1
for i in range(1, N + 1):
if int(i * 1.08) == N:
ans = i
# Print answer
if ans != -1:
print(ans)
else:
print(":(")
|
import math
# Input the amount of money Takahashi paid
N = int(eval(input()))
# Find nearest integer price more than or equal to X/1.08
X = math.ceil(N / 1.08)
# Check if the "taxed price" is equal to N yen
if math.floor(X * 1.08) == N:
print(X)
else:
print(":(")
| false | 7.142857 |
[
"+import math",
"+",
"-# Check if the price before tax is X, for X = 1, 2, 3, ..., N",
"-ans = -1",
"-for i in range(1, N + 1):",
"- if int(i * 1.08) == N:",
"- ans = i",
"-# Print answer",
"-if ans != -1:",
"- print(ans)",
"+# Find nearest integer price more than or equal to X/1.08",
"+X = math.ceil(N / 1.08)",
"+# Check if the \"taxed price\" is equal to N yen",
"+if math.floor(X * 1.08) == N:",
"+ print(X)"
] | false | 0.046293 | 0.045591 | 1.015403 |
[
"s226632909",
"s707692772"
] |
u844789719
|
p02911
|
python
|
s361599013
|
s642203694
| 260 | 231 | 10,472 | 40,732 |
Accepted
|
Accepted
| 11.15 |
N, K, Q = [int(_) for _ in input().split()]
A = [int(eval(input())) for _ in range(Q)]
s = [K - Q] * (N + 1)
for a in A:
s[a] += 1
for i in range(1, N + 1):
if s[i] > 0:
print('Yes')
else:
print('No')
|
import sys
import numpy as np
def main(stdin):
N, K, Q = stdin[:3]
ans = np.full(N + 1, K - Q, dtype=np.int64)
for i in stdin[3:]:
ans[i] += 1
ans = np.where(ans > 0, 'Yes', 'No')
return ans[1:]
if sys.argv[-1] == 'ONLINE_JUDGE':
import numba
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', 'i8[:](i8[:],)')(main)
# b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
cc.compile()
else:
#from my_module import main
stdin = np.array([int(_) for _ in open(0).read().split()])
print(*main(stdin), sep='\n')
| 10 | 24 | 232 | 616 |
N, K, Q = [int(_) for _ in input().split()]
A = [int(eval(input())) for _ in range(Q)]
s = [K - Q] * (N + 1)
for a in A:
s[a] += 1
for i in range(1, N + 1):
if s[i] > 0:
print("Yes")
else:
print("No")
|
import sys
import numpy as np
def main(stdin):
N, K, Q = stdin[:3]
ans = np.full(N + 1, K - Q, dtype=np.int64)
for i in stdin[3:]:
ans[i] += 1
ans = np.where(ans > 0, "Yes", "No")
return ans[1:]
if sys.argv[-1] == "ONLINE_JUDGE":
import numba
from numba.pycc import CC
cc = CC("my_module")
cc.export("main", "i8[:](i8[:],)")(main)
# b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
cc.compile()
else:
# from my_module import main
stdin = np.array([int(_) for _ in open(0).read().split()])
print(*main(stdin), sep="\n")
| false | 58.333333 |
[
"-N, K, Q = [int(_) for _ in input().split()]",
"-A = [int(eval(input())) for _ in range(Q)]",
"-s = [K - Q] * (N + 1)",
"-for a in A:",
"- s[a] += 1",
"-for i in range(1, N + 1):",
"- if s[i] > 0:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+import sys",
"+import numpy as np",
"+",
"+",
"+def main(stdin):",
"+ N, K, Q = stdin[:3]",
"+ ans = np.full(N + 1, K - Q, dtype=np.int64)",
"+ for i in stdin[3:]:",
"+ ans[i] += 1",
"+ ans = np.where(ans > 0, \"Yes\", \"No\")",
"+ return ans[1:]",
"+",
"+",
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ import numba",
"+ from numba.pycc import CC",
"+",
"+ cc = CC(\"my_module\")",
"+ cc.export(\"main\", \"i8[:](i8[:],)\")(main)",
"+ # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]",
"+ cc.compile()",
"+else:",
"+ # from my_module import main",
"+ stdin = np.array([int(_) for _ in open(0).read().split()])",
"+ print(*main(stdin), sep=\"\\n\")"
] | false | 0.045044 | 0.72001 | 0.06256 |
[
"s361599013",
"s642203694"
] |
u391589398
|
p02661
|
python
|
s939698051
|
s190744560
| 575 | 488 | 42,132 | 27,140 |
Accepted
|
Accepted
| 15.13 |
n = int(eval(input()))
AB = []
for _ in range(n):
ab = tuple(map(int, input().split()))
AB.append(ab)
AB_A = sorted(AB, key=lambda x: x[0])
AB_B = sorted(AB, key=lambda x: x[1])
if n%2==1:
sa, sb = AB_A[n//2]
la, lb = AB_B[n//2]
print((lb - sa + 1))
else:
sal, sbl = AB_A[n//2-1]
sar, sbr = AB_A[n//2]
lal, lbl = AB_B[n//2-1]
lar, lbr = AB_B[n//2]
print(((lbl + lbr) - (sal + sar) +1))
|
n = int(eval(input()))
A = []
B = []
for _ in range(n):
a, b = tuple(map(int, input().split()))
A.append(a)
B.append(b)
A = sorted(A)
B = sorted(B)
if n%2==1:
sa = A[n//2]
lb = B[n//2]
print((lb - sa + 1))
else:
sal = A[n//2-1]
sar = A[n//2]
lbl = B[n//2-1]
lbr = B[n//2]
print(((lbl + lbr) - (sal + sar) +1))
| 21 | 22 | 440 | 368 |
n = int(eval(input()))
AB = []
for _ in range(n):
ab = tuple(map(int, input().split()))
AB.append(ab)
AB_A = sorted(AB, key=lambda x: x[0])
AB_B = sorted(AB, key=lambda x: x[1])
if n % 2 == 1:
sa, sb = AB_A[n // 2]
la, lb = AB_B[n // 2]
print((lb - sa + 1))
else:
sal, sbl = AB_A[n // 2 - 1]
sar, sbr = AB_A[n // 2]
lal, lbl = AB_B[n // 2 - 1]
lar, lbr = AB_B[n // 2]
print(((lbl + lbr) - (sal + sar) + 1))
|
n = int(eval(input()))
A = []
B = []
for _ in range(n):
a, b = tuple(map(int, input().split()))
A.append(a)
B.append(b)
A = sorted(A)
B = sorted(B)
if n % 2 == 1:
sa = A[n // 2]
lb = B[n // 2]
print((lb - sa + 1))
else:
sal = A[n // 2 - 1]
sar = A[n // 2]
lbl = B[n // 2 - 1]
lbr = B[n // 2]
print(((lbl + lbr) - (sal + sar) + 1))
| false | 4.545455 |
[
"-AB = []",
"+A = []",
"+B = []",
"- ab = tuple(map(int, input().split()))",
"- AB.append(ab)",
"-AB_A = sorted(AB, key=lambda x: x[0])",
"-AB_B = sorted(AB, key=lambda x: x[1])",
"+ a, b = tuple(map(int, input().split()))",
"+ A.append(a)",
"+ B.append(b)",
"+A = sorted(A)",
"+B = sorted(B)",
"- sa, sb = AB_A[n // 2]",
"- la, lb = AB_B[n // 2]",
"+ sa = A[n // 2]",
"+ lb = B[n // 2]",
"- sal, sbl = AB_A[n // 2 - 1]",
"- sar, sbr = AB_A[n // 2]",
"- lal, lbl = AB_B[n // 2 - 1]",
"- lar, lbr = AB_B[n // 2]",
"+ sal = A[n // 2 - 1]",
"+ sar = A[n // 2]",
"+ lbl = B[n // 2 - 1]",
"+ lbr = B[n // 2]"
] | false | 0.035681 | 0.042651 | 0.836586 |
[
"s939698051",
"s190744560"
] |
u620868411
|
p02760
|
python
|
s678775469
|
s312677492
| 174 | 18 | 39,760 | 3,064 |
Accepted
|
Accepted
| 89.66 |
al = [input().split() for _ in range(3)]
n = int(eval(input()))
for _ in range(n):
b = eval(input())
for i in range(3):
for j in range(3):
if al[i][j]==b:
al[i][j] = "0"
if al[0][0]=="0" and al[0][1]=="0" and al[0][2]=="0":
print("Yes")
elif al[1][0]=="0" and al[1][1]=="0" and al[1][2]=="0":
print("Yes")
elif al[2][0]=="0" and al[2][1]=="0" and al[2][2]=="0":
print("Yes")
elif al[0][0]=="0" and al[1][0]=="0" and al[2][0]=="0":
print("Yes")
elif al[0][1]=="0" and al[1][1]=="0" and al[2][1]=="0":
print("Yes")
elif al[0][2]=="0" and al[1][2]=="0" and al[2][2]=="0":
print("Yes")
elif al[0][0]=="0" and al[1][1]=="0" and al[2][2]=="0":
print("Yes")
elif al[0][2]=="0" and al[1][1]=="0" and al[2][0]=="0":
print("Yes")
else:
print("No")
|
al = [list(map(int, input().split())) for _ in range(3)]
n = int(eval(input()))
for _ in range(n):
x = int(eval(input()))
for i in range(3):
for j in range(3):
if al[i][j]==x:
al[i][j] = -1
for i in range(3):
if -3==sum(al[i]):
print("Yes")
exit()
if -3==sum([al[j][i] for j in range(3)]):
print("Yes")
exit()
if al[0][0]+al[1][1]+al[2][2]==-3:
print("Yes")
exit()
if al[0][2]+al[1][1]+al[2][0]==-3:
print("Yes")
exit()
print("No")
| 27 | 27 | 832 | 551 |
al = [input().split() for _ in range(3)]
n = int(eval(input()))
for _ in range(n):
b = eval(input())
for i in range(3):
for j in range(3):
if al[i][j] == b:
al[i][j] = "0"
if al[0][0] == "0" and al[0][1] == "0" and al[0][2] == "0":
print("Yes")
elif al[1][0] == "0" and al[1][1] == "0" and al[1][2] == "0":
print("Yes")
elif al[2][0] == "0" and al[2][1] == "0" and al[2][2] == "0":
print("Yes")
elif al[0][0] == "0" and al[1][0] == "0" and al[2][0] == "0":
print("Yes")
elif al[0][1] == "0" and al[1][1] == "0" and al[2][1] == "0":
print("Yes")
elif al[0][2] == "0" and al[1][2] == "0" and al[2][2] == "0":
print("Yes")
elif al[0][0] == "0" and al[1][1] == "0" and al[2][2] == "0":
print("Yes")
elif al[0][2] == "0" and al[1][1] == "0" and al[2][0] == "0":
print("Yes")
else:
print("No")
|
al = [list(map(int, input().split())) for _ in range(3)]
n = int(eval(input()))
for _ in range(n):
x = int(eval(input()))
for i in range(3):
for j in range(3):
if al[i][j] == x:
al[i][j] = -1
for i in range(3):
if -3 == sum(al[i]):
print("Yes")
exit()
if -3 == sum([al[j][i] for j in range(3)]):
print("Yes")
exit()
if al[0][0] + al[1][1] + al[2][2] == -3:
print("Yes")
exit()
if al[0][2] + al[1][1] + al[2][0] == -3:
print("Yes")
exit()
print("No")
| false | 0 |
[
"-al = [input().split() for _ in range(3)]",
"+al = [list(map(int, input().split())) for _ in range(3)]",
"- b = eval(input())",
"+ x = int(eval(input()))",
"- if al[i][j] == b:",
"- al[i][j] = \"0\"",
"-if al[0][0] == \"0\" and al[0][1] == \"0\" and al[0][2] == \"0\":",
"+ if al[i][j] == x:",
"+ al[i][j] = -1",
"+for i in range(3):",
"+ if -3 == sum(al[i]):",
"+ print(\"Yes\")",
"+ exit()",
"+ if -3 == sum([al[j][i] for j in range(3)]):",
"+ print(\"Yes\")",
"+ exit()",
"+if al[0][0] + al[1][1] + al[2][2] == -3:",
"-elif al[1][0] == \"0\" and al[1][1] == \"0\" and al[1][2] == \"0\":",
"+ exit()",
"+if al[0][2] + al[1][1] + al[2][0] == -3:",
"-elif al[2][0] == \"0\" and al[2][1] == \"0\" and al[2][2] == \"0\":",
"- print(\"Yes\")",
"-elif al[0][0] == \"0\" and al[1][0] == \"0\" and al[2][0] == \"0\":",
"- print(\"Yes\")",
"-elif al[0][1] == \"0\" and al[1][1] == \"0\" and al[2][1] == \"0\":",
"- print(\"Yes\")",
"-elif al[0][2] == \"0\" and al[1][2] == \"0\" and al[2][2] == \"0\":",
"- print(\"Yes\")",
"-elif al[0][0] == \"0\" and al[1][1] == \"0\" and al[2][2] == \"0\":",
"- print(\"Yes\")",
"-elif al[0][2] == \"0\" and al[1][1] == \"0\" and al[2][0] == \"0\":",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+ exit()",
"+print(\"No\")"
] | false | 0.092951 | 0.037793 | 2.459474 |
[
"s678775469",
"s312677492"
] |
u729133443
|
p02909
|
python
|
s461103006
|
s638622277
| 64 | 23 | 61,312 | 8,924 |
Accepted
|
Accepted
| 64.06 |
print(('CRSlauoinunndyyy'[ord(input()[0])%7%3::3]))
|
print(('CRSlauoinunndyyy'[id(id)%3::3]))
| 1 | 1 | 49 | 38 |
print(("CRSlauoinunndyyy"[ord(input()[0]) % 7 % 3 :: 3]))
|
print(("CRSlauoinunndyyy"[id(id) % 3 :: 3]))
| false | 0 |
[
"-print((\"CRSlauoinunndyyy\"[ord(input()[0]) % 7 % 3 :: 3]))",
"+print((\"CRSlauoinunndyyy\"[id(id) % 3 :: 3]))"
] | false | 0.040583 | 0.039977 | 1.015146 |
[
"s461103006",
"s638622277"
] |
u982591663
|
p03073
|
python
|
s265863380
|
s632499850
| 56 | 49 | 3,956 | 3,956 |
Accepted
|
Accepted
| 12.5 |
S = list(eval(input()))
ans = 0
if len(S) > 1:
for i in range(len(S)-1):
if S[i] == S[i+1]:
if S[i+1] == "0":
S[i+1] = "1"
ans += 1
else:
S[i+1] = "0"
ans += 1
print(ans)
else:
print((0))
|
S = list(eval(input()))
before_tile = S[0]
ans = 0
for i in range(1, len(S)):
if S[i] == before_tile:
ans += 1
if S[i] == "0":
S[i] = "1"
else:
S[i] = "0"
before_tile = S[i]
print(ans)
| 15 | 15 | 303 | 252 |
S = list(eval(input()))
ans = 0
if len(S) > 1:
for i in range(len(S) - 1):
if S[i] == S[i + 1]:
if S[i + 1] == "0":
S[i + 1] = "1"
ans += 1
else:
S[i + 1] = "0"
ans += 1
print(ans)
else:
print((0))
|
S = list(eval(input()))
before_tile = S[0]
ans = 0
for i in range(1, len(S)):
if S[i] == before_tile:
ans += 1
if S[i] == "0":
S[i] = "1"
else:
S[i] = "0"
before_tile = S[i]
print(ans)
| false | 0 |
[
"+before_tile = S[0]",
"-if len(S) > 1:",
"- for i in range(len(S) - 1):",
"- if S[i] == S[i + 1]:",
"- if S[i + 1] == \"0\":",
"- S[i + 1] = \"1\"",
"- ans += 1",
"- else:",
"- S[i + 1] = \"0\"",
"- ans += 1",
"- print(ans)",
"-else:",
"- print((0))",
"+for i in range(1, len(S)):",
"+ if S[i] == before_tile:",
"+ ans += 1",
"+ if S[i] == \"0\":",
"+ S[i] = \"1\"",
"+ else:",
"+ S[i] = \"0\"",
"+ before_tile = S[i]",
"+print(ans)"
] | false | 0.043661 | 0.045559 | 0.958325 |
[
"s265863380",
"s632499850"
] |
u992910889
|
p03221
|
python
|
s118886110
|
s672211358
| 1,071 | 947 | 78,296 | 89,432 |
Accepted
|
Accepted
| 11.58 |
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
def resolve():
N,M=list(map(int,input().split()))
P=[]
city_count=[0]*N
city_end=[1]*N
for i in range(M):
p,y=list(map(int,input().split()))
city_count[p-1]+=1
P.append([p,y])
P1 = sorted(P, key=lambda x: x[1])
P1=sorted(P1)
for i in P1:
i.append(city_end[i[0]-1])
city_end[i[0] - 1]+=1
for i in P:
print((str(i[0]).zfill(6)+str(i[2]).zfill(6)))
#P = dict(sorted(P.items()))
resolve()
|
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
def resolve():
N,M=list(map(int,input().split()))
data=[list(map(int,input().split())) for i in range(M)]
data1 = sorted(data, key=lambda x: x[1])
cnt=[0]*N
dic={}
for [p,y] in data1:
cnt[p-1]+=1
dic[y]="%06d%06d"%(p,cnt[p-1])
for [p,y] in data:
print((dic[y]))
resolve()
| 36 | 36 | 853 | 716 |
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10**5 + 10)
# input = sys.stdin.readline
def resolve():
N, M = list(map(int, input().split()))
P = []
city_count = [0] * N
city_end = [1] * N
for i in range(M):
p, y = list(map(int, input().split()))
city_count[p - 1] += 1
P.append([p, y])
P1 = sorted(P, key=lambda x: x[1])
P1 = sorted(P1)
for i in P1:
i.append(city_end[i[0] - 1])
city_end[i[0] - 1] += 1
for i in P:
print((str(i[0]).zfill(6) + str(i[2]).zfill(6)))
# P = dict(sorted(P.items()))
resolve()
|
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10**5 + 10)
# input = sys.stdin.readline
def resolve():
N, M = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(M)]
data1 = sorted(data, key=lambda x: x[1])
cnt = [0] * N
dic = {}
for [p, y] in data1:
cnt[p - 1] += 1
dic[y] = "%06d%06d" % (p, cnt[p - 1])
for [p, y] in data:
print((dic[y]))
resolve()
| false | 0 |
[
"- P = []",
"- city_count = [0] * N",
"- city_end = [1] * N",
"- for i in range(M):",
"- p, y = list(map(int, input().split()))",
"- city_count[p - 1] += 1",
"- P.append([p, y])",
"- P1 = sorted(P, key=lambda x: x[1])",
"- P1 = sorted(P1)",
"- for i in P1:",
"- i.append(city_end[i[0] - 1])",
"- city_end[i[0] - 1] += 1",
"- for i in P:",
"- print((str(i[0]).zfill(6) + str(i[2]).zfill(6)))",
"- # P = dict(sorted(P.items()))",
"+ data = [list(map(int, input().split())) for i in range(M)]",
"+ data1 = sorted(data, key=lambda x: x[1])",
"+ cnt = [0] * N",
"+ dic = {}",
"+ for [p, y] in data1:",
"+ cnt[p - 1] += 1",
"+ dic[y] = \"%06d%06d\" % (p, cnt[p - 1])",
"+ for [p, y] in data:",
"+ print((dic[y]))"
] | false | 0.049383 | 0.038306 | 1.289171 |
[
"s118886110",
"s672211358"
] |
u932465688
|
p03329
|
python
|
s925703271
|
s446205528
| 917 | 682 | 3,828 | 3,828 |
Accepted
|
Accepted
| 25.63 |
N = int(eval(input()))
dp = [0]*100001
L = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
for i in range(100001):
for j in range(len(L)):
if 1 <= i+L[j] <= 100000:
if dp[i+L[j]] == 0:
dp[i+L[j]] = dp[i]+1
else:
dp[i+L[j]] = min(dp[i]+1,dp[i+L[j]])
print((dp[N]))
|
N = int(eval(input()))
dp = [float('inf')]*100001
dp[0],dp[1] = 0,1
L = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
for i in range(2,100001):
for j in range(len(L)):
if i-L[j] >= 0:
dp[i] = min(dp[i-L[j]]+1,dp[i])
print((dp[N]))
| 11 | 9 | 335 | 245 |
N = int(eval(input()))
dp = [0] * 100001
L = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]
for i in range(100001):
for j in range(len(L)):
if 1 <= i + L[j] <= 100000:
if dp[i + L[j]] == 0:
dp[i + L[j]] = dp[i] + 1
else:
dp[i + L[j]] = min(dp[i] + 1, dp[i + L[j]])
print((dp[N]))
|
N = int(eval(input()))
dp = [float("inf")] * 100001
dp[0], dp[1] = 0, 1
L = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]
for i in range(2, 100001):
for j in range(len(L)):
if i - L[j] >= 0:
dp[i] = min(dp[i - L[j]] + 1, dp[i])
print((dp[N]))
| false | 18.181818 |
[
"-dp = [0] * 100001",
"+dp = [float(\"inf\")] * 100001",
"+dp[0], dp[1] = 0, 1",
"-for i in range(100001):",
"+for i in range(2, 100001):",
"- if 1 <= i + L[j] <= 100000:",
"- if dp[i + L[j]] == 0:",
"- dp[i + L[j]] = dp[i] + 1",
"- else:",
"- dp[i + L[j]] = min(dp[i] + 1, dp[i + L[j]])",
"+ if i - L[j] >= 0:",
"+ dp[i] = min(dp[i - L[j]] + 1, dp[i])"
] | false | 2.148806 | 0.883839 | 2.431218 |
[
"s925703271",
"s446205528"
] |
u057109575
|
p03043
|
python
|
s681476593
|
s215483424
| 171 | 61 | 39,536 | 65,336 |
Accepted
|
Accepted
| 64.33 |
N, K = list(map(int, input().split()))
coin = [0] * N
for i in range(len(coin)):
cnt = 0
v = i + 1
while v < K:
cnt += 1
v *= 2
coin[i] = cnt
ans = 0
for v in coin:
ans += 0.5 ** v
print((ans / N))
|
N, K = list(map(int, input().split()))
cnt = 0
for n in range(1, N + 1):
tmp = 0
while n < K:
n *= 2
tmp += 1
cnt += 1 / 2 ** tmp
print((cnt / N))
| 15 | 12 | 246 | 181 |
N, K = list(map(int, input().split()))
coin = [0] * N
for i in range(len(coin)):
cnt = 0
v = i + 1
while v < K:
cnt += 1
v *= 2
coin[i] = cnt
ans = 0
for v in coin:
ans += 0.5**v
print((ans / N))
|
N, K = list(map(int, input().split()))
cnt = 0
for n in range(1, N + 1):
tmp = 0
while n < K:
n *= 2
tmp += 1
cnt += 1 / 2**tmp
print((cnt / N))
| false | 20 |
[
"-coin = [0] * N",
"-for i in range(len(coin)):",
"- cnt = 0",
"- v = i + 1",
"- while v < K:",
"- cnt += 1",
"- v *= 2",
"- coin[i] = cnt",
"-ans = 0",
"-for v in coin:",
"- ans += 0.5**v",
"-print((ans / N))",
"+cnt = 0",
"+for n in range(1, N + 1):",
"+ tmp = 0",
"+ while n < K:",
"+ n *= 2",
"+ tmp += 1",
"+ cnt += 1 / 2**tmp",
"+print((cnt / N))"
] | false | 0.057774 | 0.084746 | 0.681731 |
[
"s681476593",
"s215483424"
] |
u425762225
|
p02848
|
python
|
s288926034
|
s981005196
| 37 | 33 | 9,604 | 9,592 |
Accepted
|
Accepted
| 10.81 |
from functools import partial
N = int(eval(input()))
S = eval(input())
lst = [chr(ord("A")+i) for i in range(26)]
def convert(x,n):
id = ord(x) - ord("A")
return lst[(id+n)%26]
convert1 = partial(convert,n=N)
ans = "".join(map(convert1,S))
print(ans)
|
from functools import partial
N = int(eval(input()))
S = eval(input())
lst = [chr(ord("A")+i) for i in range(26)]
def convert(x,n,l):
id = ord(x) - ord("A")
return l[(id+n)%26]
ans = "".join(map(partial(convert,n=N,l=lst),S))
print(ans)
| 15 | 12 | 261 | 242 |
from functools import partial
N = int(eval(input()))
S = eval(input())
lst = [chr(ord("A") + i) for i in range(26)]
def convert(x, n):
id = ord(x) - ord("A")
return lst[(id + n) % 26]
convert1 = partial(convert, n=N)
ans = "".join(map(convert1, S))
print(ans)
|
from functools import partial
N = int(eval(input()))
S = eval(input())
lst = [chr(ord("A") + i) for i in range(26)]
def convert(x, n, l):
id = ord(x) - ord("A")
return l[(id + n) % 26]
ans = "".join(map(partial(convert, n=N, l=lst), S))
print(ans)
| false | 20 |
[
"-def convert(x, n):",
"+def convert(x, n, l):",
"- return lst[(id + n) % 26]",
"+ return l[(id + n) % 26]",
"-convert1 = partial(convert, n=N)",
"-ans = \"\".join(map(convert1, S))",
"+ans = \"\".join(map(partial(convert, n=N, l=lst), S))"
] | false | 0.037221 | 0.037397 | 0.995317 |
[
"s288926034",
"s981005196"
] |
u576917603
|
p02899
|
python
|
s311080442
|
s247678683
| 339 | 179 | 62,888 | 14,008 |
Accepted
|
Accepted
| 47.2 |
n=int(input())
a=list(map(int,input().split()))
b={}
cnt=1;
for i in a:
b[i]=cnt
cnt+=1
for i in range(1,n+1):
print(b[i], end=" ")
|
n=int(input())
a=list(map(int,input().split()))
d=[None]*n
for x,i in enumerate(a):
d[i-1]=x+1
for i in d:
print(i,end=" ")
| 9 | 7 | 151 | 137 |
n = int(input())
a = list(map(int, input().split()))
b = {}
cnt = 1
for i in a:
b[i] = cnt
cnt += 1
for i in range(1, n + 1):
print(b[i], end=" ")
|
n = int(input())
a = list(map(int, input().split()))
d = [None] * n
for x, i in enumerate(a):
d[i - 1] = x + 1
for i in d:
print(i, end=" ")
| false | 22.222222 |
[
"-b = {}",
"-cnt = 1",
"-for i in a:",
"- b[i] = cnt",
"- cnt += 1",
"-for i in range(1, n + 1):",
"- print(b[i], end=\" \")",
"+d = [None] * n",
"+for x, i in enumerate(a):",
"+ d[i - 1] = x + 1",
"+for i in d:",
"+ print(i, end=\" \")"
] | false | 0.118755 | 0.045028 | 2.63737 |
[
"s311080442",
"s247678683"
] |
u368796742
|
p02820
|
python
|
s908491664
|
s514738686
| 468 | 50 | 38,776 | 4,468 |
Accepted
|
Accepted
| 89.32 |
import copy
n,k = list(map(int,input().split()))
r,s,p = list(map(int,input().split()))
T = list(eval(input()))
mo = [[] for i in range(k)]
for i in range(n):
num = i % k
mo[num].append(T[i])
mo1 = copy.deepcopy(mo)
for i in range(k):
for j in range(len(mo[i])):
if mo[i][j] == "r":
mo1[i][j] = "p"
elif mo[i][j] == "p":
mo1[i][j] = "s"
else:
mo1[i][j] = "r"
if j > 0 and mo1[i][j] == mo1[i][j-1]:
mo1[i][j] = "x"
ans = 0
for i in range(k):
for j in range(len(mo1[i])):
if mo1[i][j] == "r":
ans += r
elif mo1[i][j] == "p":
ans += p
elif mo1[i][j] == "s":
ans += s
print(ans)
|
import copy
n,k = list(map(int,input().split()))
r,s,p = list(map(int,input().split()))
T = list(eval(input()))
for i in range(n-k):
if T[i] == T[i+k]:
T[i+k] = "x"
cr = T.count("r")
cp = T.count("p")
cs = T.count("s")
print((cp*s+cr*p+cs*r))
| 33 | 13 | 753 | 249 |
import copy
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
T = list(eval(input()))
mo = [[] for i in range(k)]
for i in range(n):
num = i % k
mo[num].append(T[i])
mo1 = copy.deepcopy(mo)
for i in range(k):
for j in range(len(mo[i])):
if mo[i][j] == "r":
mo1[i][j] = "p"
elif mo[i][j] == "p":
mo1[i][j] = "s"
else:
mo1[i][j] = "r"
if j > 0 and mo1[i][j] == mo1[i][j - 1]:
mo1[i][j] = "x"
ans = 0
for i in range(k):
for j in range(len(mo1[i])):
if mo1[i][j] == "r":
ans += r
elif mo1[i][j] == "p":
ans += p
elif mo1[i][j] == "s":
ans += s
print(ans)
|
import copy
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
T = list(eval(input()))
for i in range(n - k):
if T[i] == T[i + k]:
T[i + k] = "x"
cr = T.count("r")
cp = T.count("p")
cs = T.count("s")
print((cp * s + cr * p + cs * r))
| false | 60.606061 |
[
"-mo = [[] for i in range(k)]",
"-for i in range(n):",
"- num = i % k",
"- mo[num].append(T[i])",
"-mo1 = copy.deepcopy(mo)",
"-for i in range(k):",
"- for j in range(len(mo[i])):",
"- if mo[i][j] == \"r\":",
"- mo1[i][j] = \"p\"",
"- elif mo[i][j] == \"p\":",
"- mo1[i][j] = \"s\"",
"- else:",
"- mo1[i][j] = \"r\"",
"- if j > 0 and mo1[i][j] == mo1[i][j - 1]:",
"- mo1[i][j] = \"x\"",
"-ans = 0",
"-for i in range(k):",
"- for j in range(len(mo1[i])):",
"- if mo1[i][j] == \"r\":",
"- ans += r",
"- elif mo1[i][j] == \"p\":",
"- ans += p",
"- elif mo1[i][j] == \"s\":",
"- ans += s",
"-print(ans)",
"+for i in range(n - k):",
"+ if T[i] == T[i + k]:",
"+ T[i + k] = \"x\"",
"+cr = T.count(\"r\")",
"+cp = T.count(\"p\")",
"+cs = T.count(\"s\")",
"+print((cp * s + cr * p + cs * r))"
] | false | 0.045325 | 0.042514 | 1.066109 |
[
"s908491664",
"s514738686"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.