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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u440566786
|
p03183
|
python
|
s716943254
|
s245428440
| 491 | 274 | 135,560 | 41,072 |
Accepted
|
Accepted
| 44.2 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
from functools import cmp_to_key
n=int(eval(input()))
B=[list(map(int,input().split())) for _ in range(n)]
def cmp(a,b):
va=min(a[1],b[1]-a[0])
vb=min(b[1],a[1]-b[0])
if(va==vb): return 0
return -1 if(va>vb) else 1
B.sort(key=cmp_to_key(cmp))
maxS=20000
dp=[-INF]*(maxS+1)
dp[0]=0
for i in range(n):
w,s,v=B[i]
ndp=dp[:]
for total in range(maxS+1):
if(total<=s and total+s<=maxS):
ndp[total+w]=max(ndp[total+w],dp[total]+v)
dp=ndp[:]
print((max(dp)))
resolve()
|
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
n = int(eval(input()))
WSV = [tuple(map(int, input().split())) for _ in range(n)]
WSV.sort(key = lambda tup:tup[0] + tup[1])
# dp[i][w] : i 番目まで見て、total weight が w のときの max value
# solid_max <= 10^4 なので、total weight > 10^4 は考えなくて良い
res = 0
solid_max = 10 ** 4
dp = [-1] * (solid_max + 1)
dp[0] = 0
for w0, s0, v in WSV:
for w in range(solid_max, -1, -1):
if dp[w] == -1:
continue
if w > s0: # w <= s0
continue
if w + w0 > solid_max:
res = max(res, dp[w] + v)
else:
dp[w + w0] = max(dp[w + w0], dp[w] + v)
res = max(res, max(dp))
print(res)
resolve()
| 27 | 32 | 743 | 893 |
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
from functools import cmp_to_key
n = int(eval(input()))
B = [list(map(int, input().split())) for _ in range(n)]
def cmp(a, b):
va = min(a[1], b[1] - a[0])
vb = min(b[1], a[1] - b[0])
if va == vb:
return 0
return -1 if (va > vb) else 1
B.sort(key=cmp_to_key(cmp))
maxS = 20000
dp = [-INF] * (maxS + 1)
dp[0] = 0
for i in range(n):
w, s, v = B[i]
ndp = dp[:]
for total in range(maxS + 1):
if total <= s and total + s <= maxS:
ndp[total + w] = max(ndp[total + w], dp[total] + v)
dp = ndp[:]
print((max(dp)))
resolve()
|
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n = int(eval(input()))
WSV = [tuple(map(int, input().split())) for _ in range(n)]
WSV.sort(key=lambda tup: tup[0] + tup[1])
# dp[i][w] : i 番目まで見て、total weight が w のときの max value
# solid_max <= 10^4 なので、total weight > 10^4 は考えなくて良い
res = 0
solid_max = 10**4
dp = [-1] * (solid_max + 1)
dp[0] = 0
for w0, s0, v in WSV:
for w in range(solid_max, -1, -1):
if dp[w] == -1:
continue
if w > s0: # w <= s0
continue
if w + w0 > solid_max:
res = max(res, dp[w] + v)
else:
dp[w + w0] = max(dp[w + w0], dp[w] + v)
res = max(res, max(dp))
print(res)
resolve()
| false | 15.625 |
[
"-INF = float(\"inf\")",
"-MOD = 10**9 + 7",
"+INF = 1 << 60",
"+MOD = 10**9 + 7 # 998244353",
"- from functools import cmp_to_key",
"-",
"- B = [list(map(int, input().split())) for _ in range(n)]",
"-",
"- def cmp(a, b):",
"- va = min(a[1], b[1] - a[0])",
"- vb = min(b[1], a[1] - b[0])",
"- if va == vb:",
"- return 0",
"- return -1 if (va > vb) else 1",
"-",
"- B.sort(key=cmp_to_key(cmp))",
"- maxS = 20000",
"- dp = [-INF] * (maxS + 1)",
"+ WSV = [tuple(map(int, input().split())) for _ in range(n)]",
"+ WSV.sort(key=lambda tup: tup[0] + tup[1])",
"+ # dp[i][w] : i 番目まで見て、total weight が w のときの max value",
"+ # solid_max <= 10^4 なので、total weight > 10^4 は考えなくて良い",
"+ res = 0",
"+ solid_max = 10**4",
"+ dp = [-1] * (solid_max + 1)",
"- for i in range(n):",
"- w, s, v = B[i]",
"- ndp = dp[:]",
"- for total in range(maxS + 1):",
"- if total <= s and total + s <= maxS:",
"- ndp[total + w] = max(ndp[total + w], dp[total] + v)",
"- dp = ndp[:]",
"- print((max(dp)))",
"+ for w0, s0, v in WSV:",
"+ for w in range(solid_max, -1, -1):",
"+ if dp[w] == -1:",
"+ continue",
"+ if w > s0: # w <= s0",
"+ continue",
"+ if w + w0 > solid_max:",
"+ res = max(res, dp[w] + v)",
"+ else:",
"+ dp[w + w0] = max(dp[w + w0], dp[w] + v)",
"+ res = max(res, max(dp))",
"+ print(res)"
] | false | 0.091759 | 0.116998 | 0.784282 |
[
"s716943254",
"s245428440"
] |
u112364985
|
p02682
|
python
|
s001271131
|
s318923958
| 60 | 23 | 61,772 | 9,040 |
Accepted
|
Accepted
| 61.67 |
a,b,c,k=list(map(int,input().split()))
if a>=k:
print(k)
else:
if a+b>=k:
print(a)
else:
if a+b+c>=k:
print((a-(k-(a+b))))
|
a,b,c,k=list(map(int,input().split()))
if a>=k:
print(k)
elif a+b>=k:
print(a)
else:
print((a-(k-(a+b))))
| 9 | 7 | 162 | 115 |
a, b, c, k = list(map(int, input().split()))
if a >= k:
print(k)
else:
if a + b >= k:
print(a)
else:
if a + b + c >= k:
print((a - (k - (a + b))))
|
a, b, c, k = list(map(int, input().split()))
if a >= k:
print(k)
elif a + b >= k:
print(a)
else:
print((a - (k - (a + b))))
| false | 22.222222 |
[
"+elif a + b >= k:",
"+ print(a)",
"- if a + b >= k:",
"- print(a)",
"- else:",
"- if a + b + c >= k:",
"- print((a - (k - (a + b))))",
"+ print((a - (k - (a + b))))"
] | false | 0.093449 | 0.137697 | 0.678656 |
[
"s001271131",
"s318923958"
] |
u901447859
|
p03012
|
python
|
s065489232
|
s385393789
| 20 | 18 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10 |
n,*w=list(map(int,open(0).read().split()))
min_val=None
for i in range(n-1):
y=abs(sum(w[:i+1]) - sum(w[i+1:]))
if min_val is None or y < min_val:
min_val = y
print(min_val)
|
n,*w=list(map(int,open(0).read().split()))
min_val=float('inf')
for i in range(n-1):
y=abs(sum(w[:i+1]) - sum(w[i+1:]))
min_val = min(min_val, y)
print(min_val)
| 8 | 7 | 183 | 165 |
n, *w = list(map(int, open(0).read().split()))
min_val = None
for i in range(n - 1):
y = abs(sum(w[: i + 1]) - sum(w[i + 1 :]))
if min_val is None or y < min_val:
min_val = y
print(min_val)
|
n, *w = list(map(int, open(0).read().split()))
min_val = float("inf")
for i in range(n - 1):
y = abs(sum(w[: i + 1]) - sum(w[i + 1 :]))
min_val = min(min_val, y)
print(min_val)
| false | 12.5 |
[
"-min_val = None",
"+min_val = float(\"inf\")",
"- if min_val is None or y < min_val:",
"- min_val = y",
"+ min_val = min(min_val, y)"
] | false | 0.034499 | 0.036263 | 0.951371 |
[
"s065489232",
"s385393789"
] |
u347640436
|
p03426
|
python
|
s655878908
|
s425713372
| 571 | 397 | 35,428 | 40,212 |
Accepted
|
Accepted
| 30.47 |
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
d = {}
for y in range(H):
for x in range(W):
d[A[y][x]] = (y, x)
t = [[0] * (H * W // D + 1) for _ in range(D)]
for i in range(D):
ti = t[i]
j = 0
if i == 0:
j = 1
while i + (j + 1) * D <= H * W:
y1, x1 = d[i + j * D]
y2, x2 = d[i + (j + 1) * D]
ti[j + 1] = abs(y1 - y2) + abs(x1 - x2)
j += 1
for j in range(H * W // D):
ti[j + 1] += ti[j]
Q = int(eval(input()))
result = []
for _ in range(Q):
L, R = list(map(int, input().split()))
i = L % D
result.append(t[i][(R - i) // D] - t[i][(L - i) // D])
print(('\n'.join(str(i) for i in result)))
|
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
d = {}
for y in range(H):
for x in range(W):
d[A[y][x]] = (y, x)
t = [[0] * (H * W // D + 1) for _ in range(D)]
for i in range(D):
j = 0
if i == 0:
j = 1
while i + (j + 1) * D <= H * W:
y1, x1 = d[i + j * D]
y2, x2 = d[i + (j + 1) * D]
t[i][j + 1] = abs(y1 - y2) + abs(x1 - x2)
j += 1
for j in range(H * W // D):
t[i][j + 1] += t[i][j]
Q = int(eval(input()))
result = []
for _ in range(Q):
L, R = list(map(int, input().split()))
i = L % D
result.append(t[i][(R - i) // D] - t[i][(L - i) // D])
print(('\n'.join(str(i) for i in result)))
#print(*result, sep='\n')
| 29 | 29 | 742 | 760 |
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
d = {}
for y in range(H):
for x in range(W):
d[A[y][x]] = (y, x)
t = [[0] * (H * W // D + 1) for _ in range(D)]
for i in range(D):
ti = t[i]
j = 0
if i == 0:
j = 1
while i + (j + 1) * D <= H * W:
y1, x1 = d[i + j * D]
y2, x2 = d[i + (j + 1) * D]
ti[j + 1] = abs(y1 - y2) + abs(x1 - x2)
j += 1
for j in range(H * W // D):
ti[j + 1] += ti[j]
Q = int(eval(input()))
result = []
for _ in range(Q):
L, R = list(map(int, input().split()))
i = L % D
result.append(t[i][(R - i) // D] - t[i][(L - i) // D])
print(("\n".join(str(i) for i in result)))
|
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
d = {}
for y in range(H):
for x in range(W):
d[A[y][x]] = (y, x)
t = [[0] * (H * W // D + 1) for _ in range(D)]
for i in range(D):
j = 0
if i == 0:
j = 1
while i + (j + 1) * D <= H * W:
y1, x1 = d[i + j * D]
y2, x2 = d[i + (j + 1) * D]
t[i][j + 1] = abs(y1 - y2) + abs(x1 - x2)
j += 1
for j in range(H * W // D):
t[i][j + 1] += t[i][j]
Q = int(eval(input()))
result = []
for _ in range(Q):
L, R = list(map(int, input().split()))
i = L % D
result.append(t[i][(R - i) // D] - t[i][(L - i) // D])
print(("\n".join(str(i) for i in result)))
# print(*result, sep='\n')
| false | 0 |
[
"- ti = t[i]",
"- ti[j + 1] = abs(y1 - y2) + abs(x1 - x2)",
"+ t[i][j + 1] = abs(y1 - y2) + abs(x1 - x2)",
"- ti[j + 1] += ti[j]",
"+ t[i][j + 1] += t[i][j]",
"+# print(*result, sep='\\n')"
] | false | 0.035522 | 0.035814 | 0.991845 |
[
"s655878908",
"s425713372"
] |
u459639226
|
p03127
|
python
|
s235580174
|
s328083359
| 94 | 81 | 14,252 | 16,276 |
Accepted
|
Accepted
| 13.83 |
N = int(eval(input()))
A = list(map(int, input().split()))
ans = min(A)
while True:
for i in range(len(A)):
if A[i] % ans != 0:
A[i] %= ans
if min(A) < ans:
ans = min(A)
else:
break
print(ans)
|
import fractions
from functools import reduce
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
N = int(eval(input()))
A = list(map(int, input().split()))
print((gcd_list(A)))
| 12 | 10 | 246 | 195 |
N = int(eval(input()))
A = list(map(int, input().split()))
ans = min(A)
while True:
for i in range(len(A)):
if A[i] % ans != 0:
A[i] %= ans
if min(A) < ans:
ans = min(A)
else:
break
print(ans)
|
import fractions
from functools import reduce
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
N = int(eval(input()))
A = list(map(int, input().split()))
print((gcd_list(A)))
| false | 16.666667 |
[
"+import fractions",
"+from functools import reduce",
"+",
"+",
"+def gcd_list(numbers):",
"+ return reduce(fractions.gcd, numbers)",
"+",
"+",
"-ans = min(A)",
"-while True:",
"- for i in range(len(A)):",
"- if A[i] % ans != 0:",
"- A[i] %= ans",
"- if min(A) < ans:",
"- ans = min(A)",
"- else:",
"- break",
"-print(ans)",
"+print((gcd_list(A)))"
] | false | 0.036301 | 0.060036 | 0.604652 |
[
"s235580174",
"s328083359"
] |
u223646582
|
p03464
|
python
|
s183141020
|
s467408604
| 162 | 107 | 14,252 | 20,092 |
Accepted
|
Accepted
| 33.95 |
import math
K = int(eval(input()))
A = [int(i) for i in input().split()][::-1]
if A[0] != 2:
print((-1))
exit()
ans_low = 2
ans_high = 3
for i in range(1, K):
next_ans_high = ((ans_high//A[i])+1)*A[i]-1
next_ans_low = math.ceil(ans_low/A[i])*A[i]
if (next_ans_high // A[i])*A[i] > ans_high or next_ans_low > next_ans_high:
print((-1))
exit()
ans_high = next_ans_high
ans_low = next_ans_low
# print(A[i], ans_low, ans_high)
print((ans_low, ans_high))
|
K = int(eval(input()))
A = [int(i) for i in input().split()][::-1]
cb, cu = 2, 2
for a in A:
nb = ((cb+a-1)//a)*a
nu = (cu//a+1)*a-1
if nb > cu:
print((-1))
exit()
cb, cu = nb, nu
print((nb, nu))
| 25 | 12 | 517 | 230 |
import math
K = int(eval(input()))
A = [int(i) for i in input().split()][::-1]
if A[0] != 2:
print((-1))
exit()
ans_low = 2
ans_high = 3
for i in range(1, K):
next_ans_high = ((ans_high // A[i]) + 1) * A[i] - 1
next_ans_low = math.ceil(ans_low / A[i]) * A[i]
if (next_ans_high // A[i]) * A[i] > ans_high or next_ans_low > next_ans_high:
print((-1))
exit()
ans_high = next_ans_high
ans_low = next_ans_low
# print(A[i], ans_low, ans_high)
print((ans_low, ans_high))
|
K = int(eval(input()))
A = [int(i) for i in input().split()][::-1]
cb, cu = 2, 2
for a in A:
nb = ((cb + a - 1) // a) * a
nu = (cu // a + 1) * a - 1
if nb > cu:
print((-1))
exit()
cb, cu = nb, nu
print((nb, nu))
| false | 52 |
[
"-import math",
"-",
"-if A[0] != 2:",
"- print((-1))",
"- exit()",
"-ans_low = 2",
"-ans_high = 3",
"-for i in range(1, K):",
"- next_ans_high = ((ans_high // A[i]) + 1) * A[i] - 1",
"- next_ans_low = math.ceil(ans_low / A[i]) * A[i]",
"- if (next_ans_high // A[i]) * A[i] > ans_high or next_ans_low > next_ans_high:",
"+cb, cu = 2, 2",
"+for a in A:",
"+ nb = ((cb + a - 1) // a) * a",
"+ nu = (cu // a + 1) * a - 1",
"+ if nb > cu:",
"- ans_high = next_ans_high",
"- ans_low = next_ans_low",
"- # print(A[i], ans_low, ans_high)",
"-print((ans_low, ans_high))",
"+ cb, cu = nb, nu",
"+print((nb, nu))"
] | false | 0.03689 | 0.054835 | 0.67274 |
[
"s183141020",
"s467408604"
] |
u945181840
|
p02850
|
python
|
s951333310
|
s009870215
| 402 | 261 | 46,992 | 25,900 |
Accepted
|
Accepted
| 35.07 |
import sys
from collections import deque
read = sys.stdin.read
N, *ab = list(map(int, read().split()))
graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
graph[a].append(b)
color = [0] * (N + 1)
queue = deque([1])
color_v = [set() for _ in range(N + 1)]
while queue:
V = queue.popleft()
number = 1
for v in graph[V]:
if number in color_v[V]:
number += 1
color[v] = number
color_v[V].add(number)
color_v[v].add(number)
queue.append(v)
number += 1
print((max(color)))
for a, b in zip(*[iter(ab)] * 2):
print((color[b]))
|
import sys
from collections import deque
read = sys.stdin.read
N, *ab = list(map(int, read().split()))
graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
graph[a].append(b)
color = [0] * (N + 1)
queue = deque([1])
while queue:
V = queue.popleft()
number = 1
for v in graph[V]:
if number == color[V]:
number += 1
color[v] = number
queue.append(v)
number += 1
print((max(color)))
for a, b in zip(*[iter(ab)] * 2):
print((color[b]))
| 29 | 26 | 638 | 531 |
import sys
from collections import deque
read = sys.stdin.read
N, *ab = list(map(int, read().split()))
graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
graph[a].append(b)
color = [0] * (N + 1)
queue = deque([1])
color_v = [set() for _ in range(N + 1)]
while queue:
V = queue.popleft()
number = 1
for v in graph[V]:
if number in color_v[V]:
number += 1
color[v] = number
color_v[V].add(number)
color_v[v].add(number)
queue.append(v)
number += 1
print((max(color)))
for a, b in zip(*[iter(ab)] * 2):
print((color[b]))
|
import sys
from collections import deque
read = sys.stdin.read
N, *ab = list(map(int, read().split()))
graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
graph[a].append(b)
color = [0] * (N + 1)
queue = deque([1])
while queue:
V = queue.popleft()
number = 1
for v in graph[V]:
if number == color[V]:
number += 1
color[v] = number
queue.append(v)
number += 1
print((max(color)))
for a, b in zip(*[iter(ab)] * 2):
print((color[b]))
| false | 10.344828 |
[
"-color_v = [set() for _ in range(N + 1)]",
"- if number in color_v[V]:",
"+ if number == color[V]:",
"- color_v[V].add(number)",
"- color_v[v].add(number)"
] | false | 0.058538 | 0.057192 | 1.023527 |
[
"s951333310",
"s009870215"
] |
u391066416
|
p02729
|
python
|
s328738617
|
s843626860
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
N,M=list(map(int,input().split()))
print((int(1/2*N*(N-1)+1/2*M*(M-1))))
|
N,M=list(map(int,input().split()))
print((N*(N-1)//2+M*(M-1)//2))
| 2 | 2 | 65 | 58 |
N, M = list(map(int, input().split()))
print((int(1 / 2 * N * (N - 1) + 1 / 2 * M * (M - 1))))
|
N, M = list(map(int, input().split()))
print((N * (N - 1) // 2 + M * (M - 1) // 2))
| false | 0 |
[
"-print((int(1 / 2 * N * (N - 1) + 1 / 2 * M * (M - 1))))",
"+print((N * (N - 1) // 2 + M * (M - 1) // 2))"
] | false | 0.041346 | 0.093238 | 0.443441 |
[
"s328738617",
"s843626860"
] |
u535423069
|
p03274
|
python
|
s762223385
|
s221685067
| 230 | 97 | 58,736 | 14,840 |
Accepted
|
Accepted
| 57.83 |
import sys
stdin = sys.stdin
mod = 1000000007
inf = 1 << 60
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()
n, k = na()
x = na()
ans = inf
for i in range(n):
if i + k - 1 < n:
l, r = x[i], x[i + k - 1]
ans = min(ans, min(abs(l) + abs(r - l), abs(r) + abs(r - l)))
print(ans)
|
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
n, k = na()
x = na()
def dist(l, r):
mn = min(abs(l), abs(r))
mx = max(abs(l), abs(r))
if l < 0 and r < 0:
return mx
elif l >= 0 and r >= 0:
return mx
else:
return mn * 2 + mx
ans = inf
for i in range(n - k + 1):
ans = min(ans, dist(x[i], x[i + k - 1]))
print(ans)
| 22 | 37 | 430 | 956 |
import sys
stdin = sys.stdin
mod = 1000000007
inf = 1 << 60
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()
n, k = na()
x = na()
ans = inf
for i in range(n):
if i + k - 1 < n:
l, r = x[i], x[i + k - 1]
ans = min(ans, min(abs(l) + abs(r - l), abs(r) + abs(r - l)))
print(ans)
|
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
n, k = na()
x = na()
def dist(l, r):
mn = min(abs(l), abs(r))
mx = max(abs(l), abs(r))
if l < 0 and r < 0:
return mx
elif l >= 0 and r >= 0:
return mx
else:
return mn * 2 + mx
ans = inf
for i in range(n - k + 1):
ans = min(ans, dist(x[i], x[i + k - 1]))
print(ans)
| false | 40.540541 |
[
"+inf = 1 << 60",
"-inf = 1 << 60",
"+nin = lambda y: [ni() for _ in range(y)]",
"+nan = lambda y: [na() for _ in range(y)]",
"+nf = lambda: float(ns())",
"+nfn = lambda y: [nf() for _ in range(y)]",
"+nfa = lambda: list(map(float, stdin.readline().split()))",
"+nfan = lambda y: [nfa() for _ in range(y)]",
"+nsn = lambda y: [ns() for _ in range(y)]",
"+ncl = lambda y: [list(ns()) for _ in range(y)]",
"+",
"+",
"+def dist(l, r):",
"+ mn = min(abs(l), abs(r))",
"+ mx = max(abs(l), abs(r))",
"+ if l < 0 and r < 0:",
"+ return mx",
"+ elif l >= 0 and r >= 0:",
"+ return mx",
"+ else:",
"+ return mn * 2 + mx",
"+",
"+",
"-for i in range(n):",
"- if i + k - 1 < n:",
"- l, r = x[i], x[i + k - 1]",
"- ans = min(ans, min(abs(l) + abs(r - l), abs(r) + abs(r - l)))",
"+for i in range(n - k + 1):",
"+ ans = min(ans, dist(x[i], x[i + k - 1]))"
] | false | 0.165377 | 0.047985 | 3.446453 |
[
"s762223385",
"s221685067"
] |
u260980560
|
p00907
|
python
|
s720684662
|
s871793891
| 390 | 280 | 6,400 | 5,680 |
Accepted
|
Accepted
| 28.21 |
while 1:
d = eval(input())
if d==0:
break
V = [float(input()) for i in range(d+3)]
a = [0]*(d+3)
cnts = [0]*(d+3)
import itertools
for K in itertools.combinations(list(range(d+3)), d+1):
for k in K:
res = 1
for j in K:
if k==j: continue
res *= k-j
a[k] = V[k] / res
for i in range(d+3):
if i in K: continue
res = 0.
for k in K:
tmp = 1
for j in K:
if k==j: continue
tmp *= i-j
res += a[k]*tmp
if abs(V[i]-res) > 0.5:
cnts[i] += 1
print(cnts.index(max(cnts)))
|
from itertools import combinations
def build(X, Y):
A = []
for x in X:
res = 1
for xi in X:
if x == xi:
continue
res *= x - xi
A.append(Y[x] / res)
return A
def calc(X, A, x):
base = 1
for xi in X:
base *= i - xi
return sum(base / (i - x) * a for x, a in zip(X, A))
while 1:
d = int(eval(input()))
if d == 0:
break
N = d+3
Y = [float(eval(input())) for i in range(N)]
cnts = [0]*N
for X in combinations(list(range(N)), d+1):
U = [0]*N
for x in X:
U[x] = 1
A = build(X, Y)
for i in range(N):
if U[i]:
continue
res = calc(X, A, i)
if abs(Y[i] - res) > 0.5:
cnts[i] += 1
print((cnts.index(max(cnts))))
| 28 | 43 | 755 | 873 |
while 1:
d = eval(input())
if d == 0:
break
V = [float(input()) for i in range(d + 3)]
a = [0] * (d + 3)
cnts = [0] * (d + 3)
import itertools
for K in itertools.combinations(list(range(d + 3)), d + 1):
for k in K:
res = 1
for j in K:
if k == j:
continue
res *= k - j
a[k] = V[k] / res
for i in range(d + 3):
if i in K:
continue
res = 0.0
for k in K:
tmp = 1
for j in K:
if k == j:
continue
tmp *= i - j
res += a[k] * tmp
if abs(V[i] - res) > 0.5:
cnts[i] += 1
print(cnts.index(max(cnts)))
|
from itertools import combinations
def build(X, Y):
A = []
for x in X:
res = 1
for xi in X:
if x == xi:
continue
res *= x - xi
A.append(Y[x] / res)
return A
def calc(X, A, x):
base = 1
for xi in X:
base *= i - xi
return sum(base / (i - x) * a for x, a in zip(X, A))
while 1:
d = int(eval(input()))
if d == 0:
break
N = d + 3
Y = [float(eval(input())) for i in range(N)]
cnts = [0] * N
for X in combinations(list(range(N)), d + 1):
U = [0] * N
for x in X:
U[x] = 1
A = build(X, Y)
for i in range(N):
if U[i]:
continue
res = calc(X, A, i)
if abs(Y[i] - res) > 0.5:
cnts[i] += 1
print((cnts.index(max(cnts))))
| false | 34.883721 |
[
"+from itertools import combinations",
"+",
"+",
"+def build(X, Y):",
"+ A = []",
"+ for x in X:",
"+ res = 1",
"+ for xi in X:",
"+ if x == xi:",
"+ continue",
"+ res *= x - xi",
"+ A.append(Y[x] / res)",
"+ return A",
"+",
"+",
"+def calc(X, A, x):",
"+ base = 1",
"+ for xi in X:",
"+ base *= i - xi",
"+ return sum(base / (i - x) * a for x, a in zip(X, A))",
"+",
"+",
"- d = eval(input())",
"+ d = int(eval(input()))",
"- V = [float(input()) for i in range(d + 3)]",
"- a = [0] * (d + 3)",
"- cnts = [0] * (d + 3)",
"- import itertools",
"-",
"- for K in itertools.combinations(list(range(d + 3)), d + 1):",
"- for k in K:",
"- res = 1",
"- for j in K:",
"- if k == j:",
"- continue",
"- res *= k - j",
"- a[k] = V[k] / res",
"- for i in range(d + 3):",
"- if i in K:",
"+ N = d + 3",
"+ Y = [float(eval(input())) for i in range(N)]",
"+ cnts = [0] * N",
"+ for X in combinations(list(range(N)), d + 1):",
"+ U = [0] * N",
"+ for x in X:",
"+ U[x] = 1",
"+ A = build(X, Y)",
"+ for i in range(N):",
"+ if U[i]:",
"- res = 0.0",
"- for k in K:",
"- tmp = 1",
"- for j in K:",
"- if k == j:",
"- continue",
"- tmp *= i - j",
"- res += a[k] * tmp",
"- if abs(V[i] - res) > 0.5:",
"+ res = calc(X, A, i)",
"+ if abs(Y[i] - res) > 0.5:",
"- print(cnts.index(max(cnts)))",
"+ print((cnts.index(max(cnts))))"
] | false | 0.1064 | 0.111929 | 0.950603 |
[
"s720684662",
"s871793891"
] |
u971091945
|
p02572
|
python
|
s968223633
|
s772987112
| 148 | 127 | 31,428 | 31,520 |
Accepted
|
Accepted
| 14.19 |
n = int(eval(input()))
a = list(map(int, input().split()))
su = sum(a)
ans = 0
for i in range(n-1):
su -= a[i]
ans += (a[i]*su)
ans %= 10**9+7
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
su = sum(a)
ans = 0
for i in range(n-1):
su -= a[i]
ans += (a[i]*su)
print((ans%(10**9+7)))
| 12 | 10 | 173 | 161 |
n = int(eval(input()))
a = list(map(int, input().split()))
su = sum(a)
ans = 0
for i in range(n - 1):
su -= a[i]
ans += a[i] * su
ans %= 10**9 + 7
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
su = sum(a)
ans = 0
for i in range(n - 1):
su -= a[i]
ans += a[i] * su
print((ans % (10**9 + 7)))
| false | 16.666667 |
[
"- ans %= 10**9 + 7",
"-print(ans)",
"+print((ans % (10**9 + 7)))"
] | false | 0.041268 | 0.041702 | 0.989586 |
[
"s968223633",
"s772987112"
] |
u401487574
|
p02892
|
python
|
s929971612
|
s570957696
| 100 | 91 | 74,052 | 68,992 |
Accepted
|
Accepted
| 9 |
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
g = [[] for i in range(n)]
for i in range(n):
S =input()
for j in range(i+1,n):
if S[j]=="1":
g[i].append(j)
g[j].append(i)
visited=[False]*n
def bfs(s):
que = collections.deque()
que.append(s)
visited[s]=True
ls=[s]
while que:
s = que.popleft()
for node in g[s]:
if not visited[node]:
visited[node]=True
que.append(node)
ls.append(node)
return ls
def bfs2(s):
vis = [False]*n
cnts=[0]*n
que = collections.deque()
cnt=1
que.append((s,cnt))
vis[s]=True
cnts[s]=1
while que:
s,cnt = que.popleft()
for node in g[s]:
if not vis[node]:
vis[node]=True
cnts[node]=cnt+1
que.append((node,cnt+1))
else:
if (cnts[node]+cnt)%2==0:
print(-1)
exit()
return cnt
#print(g)
ans = 0
for i in range(n):
if not visited[i]:
ls = bfs(i)
#print(ans,ls)
tmp = 0
for node in ls:
tmp = max(bfs2(node),tmp)
ans+=tmp
print(ans)
|
import collections
n = int(eval(input()))
g = [[] for i in range(n)]
for i in range(n):
S =eval(input())
for j in range(i+1,n):
if S[j]=="1":
g[i].append(j)
g[j].append(i)
def bfs(s):
vis = [False]*n
cnts=[0]*n
que = collections.deque()
cnt=1
que.append((s,cnt))
vis[s]=True
cnts[s]=1
while que:
s,cnt = que.popleft()
for node in g[s]:
if not vis[node]:
vis[node]=True
cnts[node]=cnt+1
que.append((node,cnt+1))
else:
if (cnts[node]+cnt)%2==0:
print((-1))
exit()
return cnt
ans = 0
for node in range(n):
ans = max(bfs(node),ans)
print(ans)
| 63 | 34 | 1,521 | 783 |
ma = lambda: map(int, input().split())
lma = lambda: list(map(int, input().split()))
tma = lambda: tuple(map(int, input().split()))
ni = lambda: int(input())
yn = lambda fl: print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
g = [[] for i in range(n)]
for i in range(n):
S = input()
for j in range(i + 1, n):
if S[j] == "1":
g[i].append(j)
g[j].append(i)
visited = [False] * n
def bfs(s):
que = collections.deque()
que.append(s)
visited[s] = True
ls = [s]
while que:
s = que.popleft()
for node in g[s]:
if not visited[node]:
visited[node] = True
que.append(node)
ls.append(node)
return ls
def bfs2(s):
vis = [False] * n
cnts = [0] * n
que = collections.deque()
cnt = 1
que.append((s, cnt))
vis[s] = True
cnts[s] = 1
while que:
s, cnt = que.popleft()
for node in g[s]:
if not vis[node]:
vis[node] = True
cnts[node] = cnt + 1
que.append((node, cnt + 1))
else:
if (cnts[node] + cnt) % 2 == 0:
print(-1)
exit()
return cnt
# print(g)
ans = 0
for i in range(n):
if not visited[i]:
ls = bfs(i)
# print(ans,ls)
tmp = 0
for node in ls:
tmp = max(bfs2(node), tmp)
ans += tmp
print(ans)
|
import collections
n = int(eval(input()))
g = [[] for i in range(n)]
for i in range(n):
S = eval(input())
for j in range(i + 1, n):
if S[j] == "1":
g[i].append(j)
g[j].append(i)
def bfs(s):
vis = [False] * n
cnts = [0] * n
que = collections.deque()
cnt = 1
que.append((s, cnt))
vis[s] = True
cnts[s] = 1
while que:
s, cnt = que.popleft()
for node in g[s]:
if not vis[node]:
vis[node] = True
cnts[node] = cnt + 1
que.append((node, cnt + 1))
else:
if (cnts[node] + cnt) % 2 == 0:
print((-1))
exit()
return cnt
ans = 0
for node in range(n):
ans = max(bfs(node), ans)
print(ans)
| false | 46.031746 |
[
"-ma = lambda: map(int, input().split())",
"-lma = lambda: list(map(int, input().split()))",
"-tma = lambda: tuple(map(int, input().split()))",
"-ni = lambda: int(input())",
"-yn = lambda fl: print(\"Yes\") if fl else print(\"No\")",
"-import math",
"-import itertools",
"-import heapq as hq",
"-n = ni()",
"+n = int(eval(input()))",
"- S = input()",
"+ S = eval(input())",
"-visited = [False] * n",
"- que = collections.deque()",
"- que.append(s)",
"- visited[s] = True",
"- ls = [s]",
"- while que:",
"- s = que.popleft()",
"- for node in g[s]:",
"- if not visited[node]:",
"- visited[node] = True",
"- que.append(node)",
"- ls.append(node)",
"- return ls",
"-",
"-",
"-def bfs2(s):",
"- print(-1)",
"+ print((-1))",
"-# print(g)",
"-for i in range(n):",
"- if not visited[i]:",
"- ls = bfs(i)",
"- # print(ans,ls)",
"- tmp = 0",
"- for node in ls:",
"- tmp = max(bfs2(node), tmp)",
"- ans += tmp",
"+for node in range(n):",
"+ ans = max(bfs(node), ans)"
] | false | 0.045328 | 0.152608 | 0.297026 |
[
"s929971612",
"s570957696"
] |
u498487134
|
p02833
|
python
|
s580865735
|
s263465436
| 209 | 66 | 38,384 | 62,124 |
Accepted
|
Accepted
| 68.42 |
N = int(eval(input()))
ans=0
if N%2==1:
print(ans)
else:
for i in range(1,40):
a = 2*pow(5,i)
ans+=(N//a)
print(ans)
|
import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
if N%2==1:
print((0))
exit()
ans=0
for i in range(1,100):
a=2*pow(5,i)
ans+=N//a
print(ans)
main()
| 10 | 26 | 156 | 408 |
N = int(eval(input()))
ans = 0
if N % 2 == 1:
print(ans)
else:
for i in range(1, 40):
a = 2 * pow(5, i)
ans += N // a
print(ans)
|
import sys
input = sys.stdin.readline
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
mod = 10**9 + 7
N = I()
if N % 2 == 1:
print((0))
exit()
ans = 0
for i in range(1, 100):
a = 2 * pow(5, i)
ans += N // a
print(ans)
main()
| false | 61.538462 |
[
"-N = int(eval(input()))",
"-ans = 0",
"-if N % 2 == 1:",
"- print(ans)",
"-else:",
"- for i in range(1, 40):",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def main():",
"+ mod = 10**9 + 7",
"+ N = I()",
"+ if N % 2 == 1:",
"+ print((0))",
"+ exit()",
"+ ans = 0",
"+ for i in range(1, 100):",
"+",
"+",
"+main()"
] | false | 0.038241 | 0.046732 | 0.818295 |
[
"s580865735",
"s263465436"
] |
u761529120
|
p03426
|
python
|
s915306282
|
s172735456
| 1,106 | 388 | 57,692 | 56,536 |
Accepted
|
Accepted
| 64.92 |
def main():
H, W, D = list(map(int, input().split()))
field = [list(map(int, input().split())) for _ in range(H)]
c = [0] * (H * W)
for i in range(H):
for j in range(W):
c[field[i][j] - 1] = (i, j)
d = [0] * (H * W)
for l in range(H * W - D):
i, j = c[l]
x, y = c[l + D]
d[l+D] = d[l] + abs(x - i) + abs(y - j)
Q = int(eval(input()))
for _ in range(Q):
L, R = list(map(int, input().split()))
print((d[R-1]-d[L-1]))
main()
|
import sys
input = sys.stdin.readline
def main():
H, W, D = list(map(int, input().split()))
A = list(list(map(int, input().split())) for _ in range(H))
Q = int(eval(input()))
B = [(0,0)] * (H * W + 5)
for h in range(H):
for w in range(W):
B[A[h][w]] = (h+1, w+1)
C = [0] * (H * W + 5)
for i in range(H * W + 1):
if i // D == 0:
continue
tmp = abs(B[i][0] - B[i-D][0]) + abs(B[i][1] - B[i-D][1])
C[i] = tmp + C[i - D]
for _ in range(Q):
L, R = list(map(int, input().split()))
print((C[R] - C[L]))
if __name__ == "__main__":
main()
| 22 | 27 | 527 | 651 |
def main():
H, W, D = list(map(int, input().split()))
field = [list(map(int, input().split())) for _ in range(H)]
c = [0] * (H * W)
for i in range(H):
for j in range(W):
c[field[i][j] - 1] = (i, j)
d = [0] * (H * W)
for l in range(H * W - D):
i, j = c[l]
x, y = c[l + D]
d[l + D] = d[l] + abs(x - i) + abs(y - j)
Q = int(eval(input()))
for _ in range(Q):
L, R = list(map(int, input().split()))
print((d[R - 1] - d[L - 1]))
main()
|
import sys
input = sys.stdin.readline
def main():
H, W, D = list(map(int, input().split()))
A = list(list(map(int, input().split())) for _ in range(H))
Q = int(eval(input()))
B = [(0, 0)] * (H * W + 5)
for h in range(H):
for w in range(W):
B[A[h][w]] = (h + 1, w + 1)
C = [0] * (H * W + 5)
for i in range(H * W + 1):
if i // D == 0:
continue
tmp = abs(B[i][0] - B[i - D][0]) + abs(B[i][1] - B[i - D][1])
C[i] = tmp + C[i - D]
for _ in range(Q):
L, R = list(map(int, input().split()))
print((C[R] - C[L]))
if __name__ == "__main__":
main()
| false | 18.518519 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"- field = [list(map(int, input().split())) for _ in range(H)]",
"- c = [0] * (H * W)",
"- for i in range(H):",
"- for j in range(W):",
"- c[field[i][j] - 1] = (i, j)",
"- d = [0] * (H * W)",
"- for l in range(H * W - D):",
"- i, j = c[l]",
"- x, y = c[l + D]",
"- d[l + D] = d[l] + abs(x - i) + abs(y - j)",
"+ A = list(list(map(int, input().split())) for _ in range(H))",
"+ B = [(0, 0)] * (H * W + 5)",
"+ for h in range(H):",
"+ for w in range(W):",
"+ B[A[h][w]] = (h + 1, w + 1)",
"+ C = [0] * (H * W + 5)",
"+ for i in range(H * W + 1):",
"+ if i // D == 0:",
"+ continue",
"+ tmp = abs(B[i][0] - B[i - D][0]) + abs(B[i][1] - B[i - D][1])",
"+ C[i] = tmp + C[i - D]",
"- print((d[R - 1] - d[L - 1]))",
"+ print((C[R] - C[L]))",
"-main()",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.034361 | 0.057804 | 0.594439 |
[
"s915306282",
"s172735456"
] |
u790710233
|
p03240
|
python
|
s018822666
|
s306179279
| 540 | 27 | 3,064 | 3,064 |
Accepted
|
Accepted
| 95 |
n = int(eval(input()))
dots = []
for _ in range(n):
x, y, h = list(map(int, input().split()))
dots.append((x, y, h))
x_, y_, h_ = sorted(dots, key=lambda x: x[2], reverse=True)[1]
for cx in range(101):
for cy in range(101):
H = h_+abs(x_ - cx) + abs(y_ - cy)
ans = []
for x, y, h in dots:
if max(H - abs(x-cx)-abs(y-cy), 0) == h:
ans.append((cx, cy, H))
if len(ans) == n:
print((*ans[0]))
exit()
|
n = int(eval(input()))
xyh = [list(map(int, input().split())) for _ in range(n)]
x_, y_, h_ = sorted(xyh, key=lambda x: x[2], reverse=True)[1]
for cx in range(101):
for cy in range(101):
H = h_+abs(x_ - cx) + abs(y_ - cy)
for x, y, h in xyh:
if max(H - abs(x-cx)-abs(y-cy), 0) != h:
break
else:
print((cx, cy, H))
exit()
| 21 | 13 | 502 | 405 |
n = int(eval(input()))
dots = []
for _ in range(n):
x, y, h = list(map(int, input().split()))
dots.append((x, y, h))
x_, y_, h_ = sorted(dots, key=lambda x: x[2], reverse=True)[1]
for cx in range(101):
for cy in range(101):
H = h_ + abs(x_ - cx) + abs(y_ - cy)
ans = []
for x, y, h in dots:
if max(H - abs(x - cx) - abs(y - cy), 0) == h:
ans.append((cx, cy, H))
if len(ans) == n:
print((*ans[0]))
exit()
|
n = int(eval(input()))
xyh = [list(map(int, input().split())) for _ in range(n)]
x_, y_, h_ = sorted(xyh, key=lambda x: x[2], reverse=True)[1]
for cx in range(101):
for cy in range(101):
H = h_ + abs(x_ - cx) + abs(y_ - cy)
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 | 38.095238 |
[
"-dots = []",
"-for _ in range(n):",
"- x, y, h = list(map(int, input().split()))",
"- dots.append((x, y, h))",
"-x_, y_, h_ = sorted(dots, key=lambda x: x[2], reverse=True)[1]",
"+xyh = [list(map(int, input().split())) for _ in range(n)]",
"+x_, y_, h_ = sorted(xyh, key=lambda x: x[2], reverse=True)[1]",
"- ans = []",
"- for x, y, h in dots:",
"- if max(H - abs(x - cx) - abs(y - cy), 0) == h:",
"- ans.append((cx, cy, H))",
"- if len(ans) == n:",
"- print((*ans[0]))",
"+ for x, y, h in xyh:",
"+ if max(H - abs(x - cx) - abs(y - cy), 0) != h:",
"+ break",
"+ else:",
"+ print((cx, cy, H))"
] | false | 0.16027 | 0.03678 | 4.357596 |
[
"s018822666",
"s306179279"
] |
u251515715
|
p03309
|
python
|
s352728407
|
s949389970
| 718 | 324 | 137,088 | 104,092 |
Accepted
|
Accepted
| 54.87 |
n=int(eval(input()))
a=list(map(int,input().split()))
b_low=-1*(10**10)
b_high=10**10
b_low_d=sum([abs(a[i]-(b_low+2+i)) for i in range(n)])-sum([abs(a[i]-(b_low+1+i)) for i in range(n)])
b_high_d=sum([abs(a[i]-(b_high+2+i)) for i in range(n)])-sum([abs(a[i]-(b_high+1+i)) for i in range(n)])
while b_high-b_low>10:
b_tmp=(b_low+b_high)//2
b_tmp_d=sum([abs(a[i]-(b_tmp+2+i)) for i in range(n)])-sum([abs(a[i]-(b_tmp+1+i)) for i in range(n)])
if b_tmp_d>0:
b_high=b_tmp
else:
b_low=b_tmp
ans=10**20
for j in range(b_low,b_high):
ans=min(ans,sum([abs(a[i]-(j+2+i)) for i in range(n)]))
print(ans)
|
n=int(eval(input()))
a=list(map(int,input().split()))
arr=sorted([a[i]-i-1 for i in range(n)])
if len(arr)%2==0:
tmp=[arr[len(arr)//2-1],arr[len(arr)//2]]
else:
tmp=[arr[len(arr)//2]]
ans=10**20
for b in tmp:
ans=min(ans,sum([abs(a[i]-b-i-1) for i in range(n)]))
print(ans)
| 21 | 14 | 630 | 289 |
n = int(eval(input()))
a = list(map(int, input().split()))
b_low = -1 * (10**10)
b_high = 10**10
b_low_d = sum([abs(a[i] - (b_low + 2 + i)) for i in range(n)]) - sum(
[abs(a[i] - (b_low + 1 + i)) for i in range(n)]
)
b_high_d = sum([abs(a[i] - (b_high + 2 + i)) for i in range(n)]) - sum(
[abs(a[i] - (b_high + 1 + i)) for i in range(n)]
)
while b_high - b_low > 10:
b_tmp = (b_low + b_high) // 2
b_tmp_d = sum([abs(a[i] - (b_tmp + 2 + i)) for i in range(n)]) - sum(
[abs(a[i] - (b_tmp + 1 + i)) for i in range(n)]
)
if b_tmp_d > 0:
b_high = b_tmp
else:
b_low = b_tmp
ans = 10**20
for j in range(b_low, b_high):
ans = min(ans, sum([abs(a[i] - (j + 2 + i)) for i in range(n)]))
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
arr = sorted([a[i] - i - 1 for i in range(n)])
if len(arr) % 2 == 0:
tmp = [arr[len(arr) // 2 - 1], arr[len(arr) // 2]]
else:
tmp = [arr[len(arr) // 2]]
ans = 10**20
for b in tmp:
ans = min(ans, sum([abs(a[i] - b - i - 1) for i in range(n)]))
print(ans)
| false | 33.333333 |
[
"-b_low = -1 * (10**10)",
"-b_high = 10**10",
"-b_low_d = sum([abs(a[i] - (b_low + 2 + i)) for i in range(n)]) - sum(",
"- [abs(a[i] - (b_low + 1 + i)) for i in range(n)]",
"-)",
"-b_high_d = sum([abs(a[i] - (b_high + 2 + i)) for i in range(n)]) - sum(",
"- [abs(a[i] - (b_high + 1 + i)) for i in range(n)]",
"-)",
"-while b_high - b_low > 10:",
"- b_tmp = (b_low + b_high) // 2",
"- b_tmp_d = sum([abs(a[i] - (b_tmp + 2 + i)) for i in range(n)]) - sum(",
"- [abs(a[i] - (b_tmp + 1 + i)) for i in range(n)]",
"- )",
"- if b_tmp_d > 0:",
"- b_high = b_tmp",
"- else:",
"- b_low = b_tmp",
"+arr = sorted([a[i] - i - 1 for i in range(n)])",
"+if len(arr) % 2 == 0:",
"+ tmp = [arr[len(arr) // 2 - 1], arr[len(arr) // 2]]",
"+else:",
"+ tmp = [arr[len(arr) // 2]]",
"-for j in range(b_low, b_high):",
"- ans = min(ans, sum([abs(a[i] - (j + 2 + i)) for i in range(n)]))",
"+for b in tmp:",
"+ ans = min(ans, sum([abs(a[i] - b - i - 1) for i in range(n)]))"
] | false | 0.04041 | 0.057916 | 0.697735 |
[
"s352728407",
"s949389970"
] |
u102461423
|
p02644
|
python
|
s078966519
|
s318409482
| 1,277 | 862 | 224,916 | 145,144 |
Accepted
|
Accepted
| 32.5 |
import sys
import numpy as np
from numba import njit
from heapq import heappop, heappush
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit('(b1[:],i8,i8,i8,i8,i8)', cache=True)
def main(C, H, W, S, T, K):
INF = 10**18
N = H * W
q = [5 * S]
dist = np.full((5 * N), INF, np.int64)
dist[5 * S] = 0
move = [0, 1, -1, W, -W]
B = 5 * N + 10
while q:
x = heappop(q)
dist_x, x = divmod(x, B)
if dist_x > dist[x]:
continue
v, d = divmod(x, 5)
if d == 0:
# どちらかに進む
for i in range(1, 5):
w = v + move[i]
y = 5 * w + i
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
else:
# 直進する
if dist_x % K != 0:
w = v + move[d]
y = 5 * w + d
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
# 止まって向きを変える権利を得る
y = 5 * v
dist_y = dist_x + (-dist_x) % K
if dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
x = dist[5 * T]
if x == INF:
return -1
return dist[5 * T] // K
H, W, K = list(map(int, readline().split()))
x1, y1, x2, y2 = list(map(int, readline().split()))
C = np.zeros((H + 2, W + 2), np.bool_)
C[1:-1, 1:-1] = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W] == b'.'
C = C.ravel()
H += 2
W += 2
S = W * x1 + y1
T = W * x2 + y2
print((main(C, H, W, S, T, K)))
|
import sys
import numpy as np
from heapq import heappop, heappush
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(C, H, W, S, T, K):
INF = 10**18
N = H * W
q = [5 * S]
dist = np.full((5 * N), INF, np.int64)
dist[5 * S] = 0
move = [0, 1, -1, W, -W]
B = 5 * N + 10
while q:
x = heappop(q)
dist_x, x = divmod(x, B)
if dist_x > dist[x]:
continue
v, d = divmod(x, 5)
if d == 0:
# どちらかに進む
for i in range(1, 5):
w = v + move[i]
y = 5 * w + i
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
else:
# 直進する
if dist_x % K != 0:
w = v + move[d]
y = 5 * w + d
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
# 止まって向きを変える権利を得る
y = 5 * v
dist_y = dist_x + (-dist_x) % K
if dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
x = dist[5 * T]
if x == INF:
return -1
return dist[5 * T] // K
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', '(b1[:],i8,i8,i8,i8,i8)')(main)
cc.compile()
exit()
from my_module import main
H, W, K = list(map(int, readline().split()))
x1, y1, x2, y2 = list(map(int, readline().split()))
C = np.zeros((H + 2, W + 2), np.bool_)
C[1:-1, 1:-1] = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W] == b'.'
C = C.ravel()
H += 2
W += 2
S = W * x1 + y1
T = W * x2 + y2
print((main(C, H, W, S, T, K)))
| 66 | 72 | 1,816 | 1,956 |
import sys
import numpy as np
from numba import njit
from heapq import heappop, heappush
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit("(b1[:],i8,i8,i8,i8,i8)", cache=True)
def main(C, H, W, S, T, K):
INF = 10**18
N = H * W
q = [5 * S]
dist = np.full((5 * N), INF, np.int64)
dist[5 * S] = 0
move = [0, 1, -1, W, -W]
B = 5 * N + 10
while q:
x = heappop(q)
dist_x, x = divmod(x, B)
if dist_x > dist[x]:
continue
v, d = divmod(x, 5)
if d == 0:
# どちらかに進む
for i in range(1, 5):
w = v + move[i]
y = 5 * w + i
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
else:
# 直進する
if dist_x % K != 0:
w = v + move[d]
y = 5 * w + d
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
# 止まって向きを変える権利を得る
y = 5 * v
dist_y = dist_x + (-dist_x) % K
if dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
x = dist[5 * T]
if x == INF:
return -1
return dist[5 * T] // K
H, W, K = list(map(int, readline().split()))
x1, y1, x2, y2 = list(map(int, readline().split()))
C = np.zeros((H + 2, W + 2), np.bool_)
C[1:-1, 1:-1] = np.frombuffer(read(), "S1").reshape(H, -1)[:, :W] == b"."
C = C.ravel()
H += 2
W += 2
S = W * x1 + y1
T = W * x2 + y2
print((main(C, H, W, S, T, K)))
|
import sys
import numpy as np
from heapq import heappop, heappush
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(C, H, W, S, T, K):
INF = 10**18
N = H * W
q = [5 * S]
dist = np.full((5 * N), INF, np.int64)
dist[5 * S] = 0
move = [0, 1, -1, W, -W]
B = 5 * N + 10
while q:
x = heappop(q)
dist_x, x = divmod(x, B)
if dist_x > dist[x]:
continue
v, d = divmod(x, 5)
if d == 0:
# どちらかに進む
for i in range(1, 5):
w = v + move[i]
y = 5 * w + i
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
else:
# 直進する
if dist_x % K != 0:
w = v + move[d]
y = 5 * w + d
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
# 止まって向きを変える権利を得る
y = 5 * v
dist_y = dist_x + (-dist_x) % K
if dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
x = dist[5 * T]
if x == INF:
return -1
return dist[5 * T] // K
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("my_module")
cc.export("main", "(b1[:],i8,i8,i8,i8,i8)")(main)
cc.compile()
exit()
from my_module import main
H, W, K = list(map(int, readline().split()))
x1, y1, x2, y2 = list(map(int, readline().split()))
C = np.zeros((H + 2, W + 2), np.bool_)
C[1:-1, 1:-1] = np.frombuffer(read(), "S1").reshape(H, -1)[:, :W] == b"."
C = C.ravel()
H += 2
W += 2
S = W * x1 + y1
T = W * x2 + y2
print((main(C, H, W, S, T, K)))
| false | 8.333333 |
[
"-from numba import njit",
"-@njit(\"(b1[:],i8,i8,i8,i8,i8)\", cache=True)",
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ from numba.pycc import CC",
"+",
"+ cc = CC(\"my_module\")",
"+ cc.export(\"main\", \"(b1[:],i8,i8,i8,i8,i8)\")(main)",
"+ cc.compile()",
"+ exit()",
"+from my_module import main",
"+"
] | false | 0.308141 | 0.318105 | 0.968678 |
[
"s078966519",
"s318409482"
] |
u075012704
|
p03007
|
python
|
s152988788
|
s577562504
| 284 | 199 | 23,208 | 25,200 |
Accepted
|
Accepted
| 29.93 |
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
M = A[-1]
m = A[0]
ans = []
for i, a in enumerate(A[1:-1]):
if a > 0:
ans.append([m, a])
m -= a
else:
ans.append([M, a])
M -= a
print((M - m))
ans.append([M, m])
for a1, a2 in ans:
print((a1, a2))
|
from collections import deque
N = int(eval(input()))
A = deque(sorted(list(map(int, input().split()))))
MAX, MIN = A.pop(), A.popleft()
ans = []
while len(A):
if A[0] < 0:
x, y = MAX, A.popleft()
ans.append([MAX, y])
MAX = MAX - y
else:
x, y = MIN, A.popleft()
ans.append([x, y])
MIN = MIN - y
ans.append([MAX, MIN])
print((MAX - MIN))
for x, y in ans:
print((x, y))
| 19 | 20 | 319 | 438 |
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
M = A[-1]
m = A[0]
ans = []
for i, a in enumerate(A[1:-1]):
if a > 0:
ans.append([m, a])
m -= a
else:
ans.append([M, a])
M -= a
print((M - m))
ans.append([M, m])
for a1, a2 in ans:
print((a1, a2))
|
from collections import deque
N = int(eval(input()))
A = deque(sorted(list(map(int, input().split()))))
MAX, MIN = A.pop(), A.popleft()
ans = []
while len(A):
if A[0] < 0:
x, y = MAX, A.popleft()
ans.append([MAX, y])
MAX = MAX - y
else:
x, y = MIN, A.popleft()
ans.append([x, y])
MIN = MIN - y
ans.append([MAX, MIN])
print((MAX - MIN))
for x, y in ans:
print((x, y))
| false | 5 |
[
"+from collections import deque",
"+",
"-A = sorted(list(map(int, input().split())))",
"-M = A[-1]",
"-m = A[0]",
"+A = deque(sorted(list(map(int, input().split()))))",
"+MAX, MIN = A.pop(), A.popleft()",
"-for i, a in enumerate(A[1:-1]):",
"- if a > 0:",
"- ans.append([m, a])",
"- m -= a",
"+while len(A):",
"+ if A[0] < 0:",
"+ x, y = MAX, A.popleft()",
"+ ans.append([MAX, y])",
"+ MAX = MAX - y",
"- ans.append([M, a])",
"- M -= a",
"-print((M - m))",
"-ans.append([M, m])",
"-for a1, a2 in ans:",
"- print((a1, a2))",
"+ x, y = MIN, A.popleft()",
"+ ans.append([x, y])",
"+ MIN = MIN - y",
"+ans.append([MAX, MIN])",
"+print((MAX - MIN))",
"+for x, y in ans:",
"+ print((x, y))"
] | false | 0.077 | 0.055733 | 1.381579 |
[
"s152988788",
"s577562504"
] |
u540631540
|
p02953
|
python
|
s159265857
|
s433091635
| 127 | 73 | 14,252 | 14,252 |
Accepted
|
Accepted
| 42.52 |
n = int(eval(input()))
h = [int(i) for i in input().split()]
x = True
c = 0
for i in range(n):
if i > 0 and h[i - 1] - h[i] >= 2:
x = False
break
elif i > 0 and h[i - 1] - h[i] == 1:
c += 1
elif i > 0 and h[i] > h[i - 1] and c == 1:
c = 0
if c == 2:
x = False
break
if x:
print("Yes")
else:
print("No")
|
n = int(eval(input()))
h = [int(i) for i in input().split()]
for i in range(n - 1, 0, -1):
d = h[i - 1] - h[i]
if d > 1:
print("No")
break
if d == 1:
h[i - 1] -= 1
else:
print("Yes")
| 19 | 11 | 386 | 226 |
n = int(eval(input()))
h = [int(i) for i in input().split()]
x = True
c = 0
for i in range(n):
if i > 0 and h[i - 1] - h[i] >= 2:
x = False
break
elif i > 0 and h[i - 1] - h[i] == 1:
c += 1
elif i > 0 and h[i] > h[i - 1] and c == 1:
c = 0
if c == 2:
x = False
break
if x:
print("Yes")
else:
print("No")
|
n = int(eval(input()))
h = [int(i) for i in input().split()]
for i in range(n - 1, 0, -1):
d = h[i - 1] - h[i]
if d > 1:
print("No")
break
if d == 1:
h[i - 1] -= 1
else:
print("Yes")
| false | 42.105263 |
[
"-x = True",
"-c = 0",
"-for i in range(n):",
"- if i > 0 and h[i - 1] - h[i] >= 2:",
"- x = False",
"+for i in range(n - 1, 0, -1):",
"+ d = h[i - 1] - h[i]",
"+ if d > 1:",
"+ print(\"No\")",
"- elif i > 0 and h[i - 1] - h[i] == 1:",
"- c += 1",
"- elif i > 0 and h[i] > h[i - 1] and c == 1:",
"- c = 0",
"- if c == 2:",
"- x = False",
"- break",
"-if x:",
"+ if d == 1:",
"+ h[i - 1] -= 1",
"+else:",
"-else:",
"- print(\"No\")"
] | false | 0.035325 | 0.058213 | 0.606829 |
[
"s159265857",
"s433091635"
] |
u124498235
|
p02659
|
python
|
s873372713
|
s593826696
| 26 | 22 | 10,028 | 9,156 |
Accepted
|
Accepted
| 15.38 |
from decimal import Decimal
a, b = list(map(Decimal, input().split()))
print((int(a*b)))
|
a, b = list(map(str, input().split()))
a = int(a)
b = int(b.replace(".",""))
print(((a*b)//100))
| 3 | 4 | 83 | 92 |
from decimal import Decimal
a, b = list(map(Decimal, input().split()))
print((int(a * b)))
|
a, b = list(map(str, input().split()))
a = int(a)
b = int(b.replace(".", ""))
print(((a * b) // 100))
| false | 25 |
[
"-from decimal import Decimal",
"-",
"-a, b = list(map(Decimal, input().split()))",
"-print((int(a * b)))",
"+a, b = list(map(str, input().split()))",
"+a = int(a)",
"+b = int(b.replace(\".\", \"\"))",
"+print(((a * b) // 100))"
] | false | 0.039181 | 0.036462 | 1.074574 |
[
"s873372713",
"s593826696"
] |
u225388820
|
p03363
|
python
|
s356764127
|
s930827013
| 200 | 168 | 36,372 | 41,488 |
Accepted
|
Accepted
| 16 |
n=int(eval(input()))
a=list(map(int,input().split()))
a=[0]+a
for i in range(1,n+1):
a[i]+=a[i-1]
#print(a)
dic={}
for i in a:
if i in dic:
dic[i]+=1
else:
dic[i]=1
ans=0
for i in list(dic.values()):
#print(i)
ans+=i*(i-1)//2
print(ans)
|
import itertools
n=int(eval(input()))
a=list(map(int,input().split()))
b=[0]+[i for i in itertools.accumulate(a)]
dic={}
for i in b:
if i in dic:
dic[i]+=1
else:
dic[i]=1
ans=0
for i in list(dic.values()):
ans+=i*(i-1)//2
print(ans)
| 17 | 14 | 276 | 261 |
n = int(eval(input()))
a = list(map(int, input().split()))
a = [0] + a
for i in range(1, n + 1):
a[i] += a[i - 1]
# print(a)
dic = {}
for i in a:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
ans = 0
for i in list(dic.values()):
# print(i)
ans += i * (i - 1) // 2
print(ans)
|
import itertools
n = int(eval(input()))
a = list(map(int, input().split()))
b = [0] + [i for i in itertools.accumulate(a)]
dic = {}
for i in b:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
ans = 0
for i in list(dic.values()):
ans += i * (i - 1) // 2
print(ans)
| false | 17.647059 |
[
"+import itertools",
"+",
"-a = [0] + a",
"-for i in range(1, n + 1):",
"- a[i] += a[i - 1]",
"-# print(a)",
"+b = [0] + [i for i in itertools.accumulate(a)]",
"-for i in a:",
"+for i in b:",
"- # print(i)"
] | false | 0.040778 | 0.048455 | 0.841577 |
[
"s356764127",
"s930827013"
] |
u315600877
|
p03469
|
python
|
s654121393
|
s830512695
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
S=eval(input())
S=S.replace("7","8",1)
print(S)
|
S=eval(input())
print((S[:3]+"8"+S[4:]))
| 3 | 2 | 43 | 33 |
S = eval(input())
S = S.replace("7", "8", 1)
print(S)
|
S = eval(input())
print((S[:3] + "8" + S[4:]))
| false | 33.333333 |
[
"-S = S.replace(\"7\", \"8\", 1)",
"-print(S)",
"+print((S[:3] + \"8\" + S[4:]))"
] | false | 0.057622 | 0.061103 | 0.94303 |
[
"s654121393",
"s830512695"
] |
u403301154
|
p02990
|
python
|
s874720891
|
s392293920
| 219 | 50 | 56,144 | 8,344 |
Accepted
|
Accepted
| 77.17 |
n, k = list(map(int, input().split()))
MAX = 2*10**5+1
MOD = 10**9+7
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]
def comb_build(n):
fact[0] = inv[0] = invfact[0] = 1
fact[1] = inv[1] = invfact[1] = 1
for i in range(2, n):
fact[i] = fact[i-1]*i%MOD
inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
invfact[i] = invfact[i-1]*inv[i]%MOD
def nCk(n, k):
if n<k or n<0 or k<0:
return 0
return (((fact[n]*invfact[k])%MOD)*invfact[n-k])%MOD
comb_build(2010)
for i in range(1, k+1):
if i>n-k+1:
print((0))
else:
print(((nCk(k-1, i-1)*nCk(n-(k-1), i))%MOD))
|
n, k = list(map(int, input().split()))
MAX = 2*10**5+1
MOD = 10**9+7
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]
def comb_build(n):
fact[0] = inv[0] = invfact[0] = 1
fact[1] = inv[1] = invfact[1] = 1
for i in range(2, n):
fact[i] = fact[i-1]*i%MOD
inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
invfact[i] = invfact[i-1]*inv[i]%MOD
def nCk(n, k):
if n<k or n<0 or k<0:
return 0
return (((fact[n]*invfact[k])%MOD)*invfact[n-k])%MOD
comb_build(2010)
for i in range(1, k+1):
print(((nCk(k-1, i-1)*nCk(n-k+1, i))%MOD))
| 28 | 25 | 652 | 610 |
n, k = list(map(int, input().split()))
MAX = 2 * 10**5 + 1
MOD = 10**9 + 7
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]
def comb_build(n):
fact[0] = inv[0] = invfact[0] = 1
fact[1] = inv[1] = invfact[1] = 1
for i in range(2, n):
fact[i] = fact[i - 1] * i % MOD
inv[i] = inv[MOD % i] * (MOD - MOD // i) % MOD
invfact[i] = invfact[i - 1] * inv[i] % MOD
def nCk(n, k):
if n < k or n < 0 or k < 0:
return 0
return (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD
comb_build(2010)
for i in range(1, k + 1):
if i > n - k + 1:
print((0))
else:
print(((nCk(k - 1, i - 1) * nCk(n - (k - 1), i)) % MOD))
|
n, k = list(map(int, input().split()))
MAX = 2 * 10**5 + 1
MOD = 10**9 + 7
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]
def comb_build(n):
fact[0] = inv[0] = invfact[0] = 1
fact[1] = inv[1] = invfact[1] = 1
for i in range(2, n):
fact[i] = fact[i - 1] * i % MOD
inv[i] = inv[MOD % i] * (MOD - MOD // i) % MOD
invfact[i] = invfact[i - 1] * inv[i] % MOD
def nCk(n, k):
if n < k or n < 0 or k < 0:
return 0
return (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD
comb_build(2010)
for i in range(1, k + 1):
print(((nCk(k - 1, i - 1) * nCk(n - k + 1, i)) % MOD))
| false | 10.714286 |
[
"- if i > n - k + 1:",
"- print((0))",
"- else:",
"- print(((nCk(k - 1, i - 1) * nCk(n - (k - 1), i)) % MOD))",
"+ print(((nCk(k - 1, i - 1) * nCk(n - k + 1, i)) % MOD))"
] | false | 0.148678 | 0.074591 | 1.993245 |
[
"s874720891",
"s392293920"
] |
u612975321
|
p02839
|
python
|
s837043052
|
s871000845
| 131 | 93 | 89,588 | 26,408 |
Accepted
|
Accepted
| 29.01 |
h, w = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
ab = [[0]*w for i in range(h)]
for ch in range(h):
for cw in range(w):
ab[ch][cw] = abs(a[ch][cw] - b[ch][cw])
ab0 = ab[0][0]
size = 80*(h+w)
dp = [[0]*w for hh in range(h)]
dp[0][0] |= 2**(size + ab0)
dp[0][0] |= 2**(size - ab0)
for ch in range(h):
for cw in range(w):
if ch < h-1:
dp[ch+1][cw] |= dp[ch][cw] << ab[ch+1][cw]
dp[ch+1][cw] |= dp[ch][cw] >> ab[ch+1][cw]
if cw < w-1:
dp[ch][cw+1] |= dp[ch][cw] << ab[ch][cw+1]
dp[ch][cw+1] |= dp[ch][cw] >> ab[ch][cw+1]
a = dp[h-1][w-1]>>size
m = a&(-a)
print((m.bit_length()-1))
|
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
h, w = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
ab = [[0]*w for i in range(h)]
for ch in range(h):
for cw in range(w):
ab[ch][cw] = abs(a[ch][cw] - b[ch][cw])
ab0 = ab[0][0]
size = 80*(h+w)
dp = [[0]*w for hh in range(h)]
dp[0][0] |= 2**(size + ab0)
dp[0][0] |= 2**(size - ab0)
for ch in range(h):
for cw in range(w):
if ch < h-1:
dp[ch+1][cw] |= dp[ch][cw] << ab[ch+1][cw]
dp[ch+1][cw] |= dp[ch][cw] >> ab[ch+1][cw]
if cw < w-1:
dp[ch][cw+1] |= dp[ch][cw] << ab[ch][cw+1]
dp[ch][cw+1] |= dp[ch][cw] >> ab[ch][cw+1]
a = dp[h-1][w-1]>>size
m = a&(-a)
print((m.bit_length()-1))
| 26 | 30 | 775 | 854 |
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
ab = [[0] * w for i in range(h)]
for ch in range(h):
for cw in range(w):
ab[ch][cw] = abs(a[ch][cw] - b[ch][cw])
ab0 = ab[0][0]
size = 80 * (h + w)
dp = [[0] * w for hh in range(h)]
dp[0][0] |= 2 ** (size + ab0)
dp[0][0] |= 2 ** (size - ab0)
for ch in range(h):
for cw in range(w):
if ch < h - 1:
dp[ch + 1][cw] |= dp[ch][cw] << ab[ch + 1][cw]
dp[ch + 1][cw] |= dp[ch][cw] >> ab[ch + 1][cw]
if cw < w - 1:
dp[ch][cw + 1] |= dp[ch][cw] << ab[ch][cw + 1]
dp[ch][cw + 1] |= dp[ch][cw] >> ab[ch][cw + 1]
a = dp[h - 1][w - 1] >> size
m = a & (-a)
print((m.bit_length() - 1))
|
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
ab = [[0] * w for i in range(h)]
for ch in range(h):
for cw in range(w):
ab[ch][cw] = abs(a[ch][cw] - b[ch][cw])
ab0 = ab[0][0]
size = 80 * (h + w)
dp = [[0] * w for hh in range(h)]
dp[0][0] |= 2 ** (size + ab0)
dp[0][0] |= 2 ** (size - ab0)
for ch in range(h):
for cw in range(w):
if ch < h - 1:
dp[ch + 1][cw] |= dp[ch][cw] << ab[ch + 1][cw]
dp[ch + 1][cw] |= dp[ch][cw] >> ab[ch + 1][cw]
if cw < w - 1:
dp[ch][cw + 1] |= dp[ch][cw] << ab[ch][cw + 1]
dp[ch][cw + 1] |= dp[ch][cw] >> ab[ch][cw + 1]
a = dp[h - 1][w - 1] >> size
m = a & (-a)
print((m.bit_length() - 1))
| false | 13.333333 |
[
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+input = sys.stdin.buffer.readline"
] | false | 0.094209 | 0.107436 | 0.876882 |
[
"s837043052",
"s871000845"
] |
u620084012
|
p02642
|
python
|
s046875257
|
s463978509
| 190 | 128 | 105,944 | 106,004 |
Accepted
|
Accepted
| 32.63 |
N = int(eval(input()))
A = list(map(int,input().split()))
U = [0]*(10**6+1)
for e in A:
U[e] += 1
ans = 0
for k in range(1,max(A)+1):
if U[k] == 1:
ans += 1
if U[k] > 0:
for l in range(2*k,10**6+1,k):
if U[l] > 0:
U[l] += 1
print(ans)
|
N = int(eval(input()))
A = list(map(int,input().split()))
m = max(A)
U = [0]*(m+1)
for e in A:
U[e] += 1
ans = 0
for k in range(1,m+1):
if U[k] == 1:
ans += 1
if U[k] > 0:
for l in range(2*k,m+1,k):
if U[l] > 0:
U[l] += 1
print(ans)
| 14 | 15 | 298 | 297 |
N = int(eval(input()))
A = list(map(int, input().split()))
U = [0] * (10**6 + 1)
for e in A:
U[e] += 1
ans = 0
for k in range(1, max(A) + 1):
if U[k] == 1:
ans += 1
if U[k] > 0:
for l in range(2 * k, 10**6 + 1, k):
if U[l] > 0:
U[l] += 1
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
m = max(A)
U = [0] * (m + 1)
for e in A:
U[e] += 1
ans = 0
for k in range(1, m + 1):
if U[k] == 1:
ans += 1
if U[k] > 0:
for l in range(2 * k, m + 1, k):
if U[l] > 0:
U[l] += 1
print(ans)
| false | 6.666667 |
[
"-U = [0] * (10**6 + 1)",
"+m = max(A)",
"+U = [0] * (m + 1)",
"-for k in range(1, max(A) + 1):",
"+for k in range(1, m + 1):",
"- for l in range(2 * k, 10**6 + 1, k):",
"+ for l in range(2 * k, m + 1, k):"
] | false | 0.246085 | 0.036708 | 6.703783 |
[
"s046875257",
"s463978509"
] |
u826188728
|
p02901
|
python
|
s504760462
|
s564980598
| 926 | 548 | 3,188 | 3,188 |
Accepted
|
Accepted
| 40.82 |
n, m = list(map(int, input().split()))
p = 2 ** n
inf = 10 ** 9
dp = [inf] * p
dp[0] = 0
for i in range(m):
a, b = list(map(int, input().split()))
c = sum([2 ** (int(j) - 1) for j in list(input().split())])
for k in range(p):
if dp[k|c] > dp[k] + a:
dp[k|c] = dp[k] + a
if dp[-1] == inf:
print((-1))
else:
print((dp[-1]))
|
def main():
N,M = list(map(int, input().split()))
inf = 10**9
p = 2**N
dp = [inf] * p
dp[0] = 0
for i in range(M):
a,b = list(map(int, input().split()))
c = sum([2**(int(j)-1) for j in list(input().split())])
for k in range(p):
if dp[k|c] > dp[k] + a:
dp[k|c] = dp[k] + a
if dp[-1] == inf:
print((-1))
else:
print((dp[-1]))
if __name__ == "__main__":
main()
| 16 | 20 | 347 | 471 |
n, m = list(map(int, input().split()))
p = 2**n
inf = 10**9
dp = [inf] * p
dp[0] = 0
for i in range(m):
a, b = list(map(int, input().split()))
c = sum([2 ** (int(j) - 1) for j in list(input().split())])
for k in range(p):
if dp[k | c] > dp[k] + a:
dp[k | c] = dp[k] + a
if dp[-1] == inf:
print((-1))
else:
print((dp[-1]))
|
def main():
N, M = list(map(int, input().split()))
inf = 10**9
p = 2**N
dp = [inf] * p
dp[0] = 0
for i in range(M):
a, b = list(map(int, input().split()))
c = sum([2 ** (int(j) - 1) for j in list(input().split())])
for k in range(p):
if dp[k | c] > dp[k] + a:
dp[k | c] = dp[k] + a
if dp[-1] == inf:
print((-1))
else:
print((dp[-1]))
if __name__ == "__main__":
main()
| false | 20 |
[
"-n, m = list(map(int, input().split()))",
"-p = 2**n",
"-inf = 10**9",
"-dp = [inf] * p",
"-dp[0] = 0",
"-for i in range(m):",
"- a, b = list(map(int, input().split()))",
"- c = sum([2 ** (int(j) - 1) for j in list(input().split())])",
"- for k in range(p):",
"- if dp[k | c] > dp[k] + a:",
"- dp[k | c] = dp[k] + a",
"-if dp[-1] == inf:",
"- print((-1))",
"-else:",
"- print((dp[-1]))",
"+def main():",
"+ N, M = list(map(int, input().split()))",
"+ inf = 10**9",
"+ p = 2**N",
"+ dp = [inf] * p",
"+ dp[0] = 0",
"+ for i in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ c = sum([2 ** (int(j) - 1) for j in list(input().split())])",
"+ for k in range(p):",
"+ if dp[k | c] > dp[k] + a:",
"+ dp[k | c] = dp[k] + a",
"+ if dp[-1] == inf:",
"+ print((-1))",
"+ else:",
"+ print((dp[-1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.07606 | 0.04582 | 1.659995 |
[
"s504760462",
"s564980598"
] |
u004423772
|
p03416
|
python
|
s320333108
|
s168779816
| 81 | 56 | 3,060 | 3,064 |
Accepted
|
Accepted
| 30.86 |
A, B = list(map(int, input().split(' ')))
def is_palindromic(n):
sep_idx = len(n) // 2
if n[:sep_idx] == n[sep_idx+1:][::-1]:
return True
return False
count = 0
for n in range(A, B+1):
n_str = str(n)
if is_palindromic(n_str):
count += 1
print(count)
|
A, B = list(map(int, input().split(' ')))
def is_palindromic(n):
s, t = n % 10, (n // 10000) % 10
u, v = (n // 10) % 10, (n // 1000) % 10
if s == t and u == v:
return True
return False
count = 0
for n in range(A, B+1):
if is_palindromic(n):
count += 1
print(count)
| 14 | 14 | 294 | 309 |
A, B = list(map(int, input().split(" ")))
def is_palindromic(n):
sep_idx = len(n) // 2
if n[:sep_idx] == n[sep_idx + 1 :][::-1]:
return True
return False
count = 0
for n in range(A, B + 1):
n_str = str(n)
if is_palindromic(n_str):
count += 1
print(count)
|
A, B = list(map(int, input().split(" ")))
def is_palindromic(n):
s, t = n % 10, (n // 10000) % 10
u, v = (n // 10) % 10, (n // 1000) % 10
if s == t and u == v:
return True
return False
count = 0
for n in range(A, B + 1):
if is_palindromic(n):
count += 1
print(count)
| false | 0 |
[
"- sep_idx = len(n) // 2",
"- if n[:sep_idx] == n[sep_idx + 1 :][::-1]:",
"+ s, t = n % 10, (n // 10000) % 10",
"+ u, v = (n // 10) % 10, (n // 1000) % 10",
"+ if s == t and u == v:",
"- n_str = str(n)",
"- if is_palindromic(n_str):",
"+ if is_palindromic(n):"
] | false | 0.236543 | 0.044031 | 5.372181 |
[
"s320333108",
"s168779816"
] |
u379959788
|
p02744
|
python
|
s479659639
|
s855518635
| 255 | 200 | 4,412 | 4,412 |
Accepted
|
Accepted
| 21.57 |
# D
N = int(eval(input()))
al = [chr(ord('a') + i) for i in range(26)]
def dfs(S, i):
if len(S) == N:
yield ''.join(S)
return
for j in range(i):
for w in dfs(S + [al[j]], i):
yield w
for w in dfs(S + [al[i]], i + 1):
yield w
for w in dfs([], 0):
print(w)
|
# D
N = int(eval(input()))
al = [chr(ord('a') + i) for i in range(26)]
def dfs(S, i):
if len(S) == N:
yield S
return
for j in range(i):
for w in dfs(S + al[j], i):
yield w
for w in dfs(S + al[i], i + 1):
yield w
for w in dfs('', 0):
print(w)
| 17 | 17 | 327 | 314 |
# D
N = int(eval(input()))
al = [chr(ord("a") + i) for i in range(26)]
def dfs(S, i):
if len(S) == N:
yield "".join(S)
return
for j in range(i):
for w in dfs(S + [al[j]], i):
yield w
for w in dfs(S + [al[i]], i + 1):
yield w
for w in dfs([], 0):
print(w)
|
# D
N = int(eval(input()))
al = [chr(ord("a") + i) for i in range(26)]
def dfs(S, i):
if len(S) == N:
yield S
return
for j in range(i):
for w in dfs(S + al[j], i):
yield w
for w in dfs(S + al[i], i + 1):
yield w
for w in dfs("", 0):
print(w)
| false | 0 |
[
"- yield \"\".join(S)",
"+ yield S",
"- for w in dfs(S + [al[j]], i):",
"+ for w in dfs(S + al[j], i):",
"- for w in dfs(S + [al[i]], i + 1):",
"+ for w in dfs(S + al[i], i + 1):",
"-for w in dfs([], 0):",
"+for w in dfs(\"\", 0):"
] | false | 0.129906 | 0.035212 | 3.689211 |
[
"s479659639",
"s855518635"
] |
u412255932
|
p03835
|
python
|
s321927426
|
s850535417
| 1,781 | 258 | 2,940 | 66,468 |
Accepted
|
Accepted
| 85.51 |
K, S = list(map(int, input().split()))
count = 0
for i in range(K+1):
for j in range(K+1):
if 0 <= S - i - j and S - i - j <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
res = 0
for X in range(min(S, K), -1, -1):
for Y in range(min(K, S - X), -1, -1):
if 0 <= S - X - Y <= K:
res += 1
print(res)
| 7 | 9 | 176 | 192 |
K, S = list(map(int, input().split()))
count = 0
for i in range(K + 1):
for j in range(K + 1):
if 0 <= S - i - j and S - i - j <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
res = 0
for X in range(min(S, K), -1, -1):
for Y in range(min(K, S - X), -1, -1):
if 0 <= S - X - Y <= K:
res += 1
print(res)
| false | 22.222222 |
[
"-count = 0",
"-for i in range(K + 1):",
"- for j in range(K + 1):",
"- if 0 <= S - i - j and S - i - j <= K:",
"- count += 1",
"-print(count)",
"+res = 0",
"+for X in range(min(S, K), -1, -1):",
"+ for Y in range(min(K, S - X), -1, -1):",
"+ if 0 <= S - X - Y <= K:",
"+ res += 1",
"+print(res)"
] | false | 0.04653 | 0.044974 | 1.034602 |
[
"s321927426",
"s850535417"
] |
u312025627
|
p02582
|
python
|
s160476941
|
s654605659
| 96 | 64 | 61,664 | 61,772 |
Accepted
|
Accepted
| 33.33 |
def main():
S = eval(input())
if S == "RRR":
print((3))
elif "RR" in S:
print((2))
elif "R" in S:
print((1))
else:
print((0))
if __name__ == '__main__':
main()
|
def main():
S = eval(input())
if "RRR" == S:
print((3))
elif "RR" in S:
print((2))
elif "R" in S:
print((1))
else:
print((0))
if __name__ == '__main__':
main()
| 14 | 14 | 217 | 217 |
def main():
S = eval(input())
if S == "RRR":
print((3))
elif "RR" in S:
print((2))
elif "R" in S:
print((1))
else:
print((0))
if __name__ == "__main__":
main()
|
def main():
S = eval(input())
if "RRR" == S:
print((3))
elif "RR" in S:
print((2))
elif "R" in S:
print((1))
else:
print((0))
if __name__ == "__main__":
main()
| false | 0 |
[
"- if S == \"RRR\":",
"+ if \"RRR\" == S:"
] | false | 0.082954 | 0.085595 | 0.969138 |
[
"s160476941",
"s654605659"
] |
u460737328
|
p03000
|
python
|
s106106537
|
s921919299
| 20 | 18 | 3,060 | 3,064 |
Accepted
|
Accepted
| 10 |
n, x = list(map(int, input().split()))
ls = list(map(int, input().split()))
count = 0
prev = 0
now = 0
for l in ls:
now = prev + l
if now <= x:
count += 1
else:
break
prev += l
print((count + 1))
|
N, X = list(map(int, input().split()))
L = list(map(int, input().split()))
d, res = 0, 1
for l in L:
d += l
if d <= X:
res += 1
else:
break
print(res)
| 15 | 11 | 235 | 184 |
n, x = list(map(int, input().split()))
ls = list(map(int, input().split()))
count = 0
prev = 0
now = 0
for l in ls:
now = prev + l
if now <= x:
count += 1
else:
break
prev += l
print((count + 1))
|
N, X = list(map(int, input().split()))
L = list(map(int, input().split()))
d, res = 0, 1
for l in L:
d += l
if d <= X:
res += 1
else:
break
print(res)
| false | 26.666667 |
[
"-n, x = list(map(int, input().split()))",
"-ls = list(map(int, input().split()))",
"-count = 0",
"-prev = 0",
"-now = 0",
"-for l in ls:",
"- now = prev + l",
"- if now <= x:",
"- count += 1",
"+N, X = list(map(int, input().split()))",
"+L = list(map(int, input().split()))",
"+d, res = 0, 1",
"+for l in L:",
"+ d += l",
"+ if d <= X:",
"+ res += 1",
"- prev += l",
"-print((count + 1))",
"+print(res)"
] | false | 0.037499 | 0.038892 | 0.964192 |
[
"s106106537",
"s921919299"
] |
u752907799
|
p02838
|
python
|
s725246630
|
s789576415
| 1,261 | 1,140 | 49,320 | 49,168 |
Accepted
|
Accepted
| 9.6 |
N,*A=list(map(int,open(0).read().split()))
print((sum((b:=1<<i)*(z:=sum(1 for a in A if a&b==0))*(N-z)%(mod:=10**9+7) for i in range(60))%mod))
|
N,*A=list(map(int,open(0).read().split()))
print((sum((b:=1<<i)*(N-(z:=sum(1 for a in A if a&b)))*z%(m:=10**9+7) for i in range(60))%m))
| 2 | 2 | 137 | 129 |
N, *A = list(map(int, open(0).read().split()))
print(
(
sum(
(b := 1 << i)
* (z := sum(1 for a in A if a & b == 0))
* (N - z)
% (mod := 10**9 + 7)
for i in range(60)
)
% mod
)
)
|
N, *A = list(map(int, open(0).read().split()))
print(
(
sum(
(b := 1 << i)
* (N - (z := sum(1 for a in A if a & b)))
* z
% (m := 10**9 + 7)
for i in range(60)
)
% m
)
)
| false | 0 |
[
"- * (z := sum(1 for a in A if a & b == 0))",
"- * (N - z)",
"- % (mod := 10**9 + 7)",
"+ * (N - (z := sum(1 for a in A if a & b)))",
"+ * z",
"+ % (m := 10**9 + 7)",
"- % mod",
"+ % m"
] | false | 0.050485 | 0.047933 | 1.053249 |
[
"s725246630",
"s789576415"
] |
u945181840
|
p03457
|
python
|
s421168999
|
s169706195
| 423 | 242 | 28,148 | 35,904 |
Accepted
|
Accepted
| 42.79 |
N = int(eval(input()))
txy = [[0, 0, 0]]
txy.extend([list(map(int, input().split())) for i in range(N)])
for i in range(N):
time = txy[i + 1][0] - txy[i][0]
length = abs(txy[i + 1][1] - txy[i][1]) + abs(txy[i + 1][2] - txy[i][2])
if time >= length and time % 2 == length % 2:
continue
else:
print('No')
exit()
print('Yes')
|
import sys
import numpy as np
read = sys.stdin.read
def main():
N, *txy = list(map(int, read().split()))
t = np.array([0] + txy[::3], np.int64)
x = np.array([0] + txy[1::3], np.int64)
y = np.array([0] + txy[2::3], np.int64)
time = t[1:] - t[:-1]
length = np.abs(y[1:] - y[:-1]) + np.abs(x[1:] - x[:-1])
if np.any((time < length) | (time % 2 != length % 2)):
print('No')
else:
print('Yes')
if __name__ == '__main__':
main()
| 13 | 21 | 369 | 494 |
N = int(eval(input()))
txy = [[0, 0, 0]]
txy.extend([list(map(int, input().split())) for i in range(N)])
for i in range(N):
time = txy[i + 1][0] - txy[i][0]
length = abs(txy[i + 1][1] - txy[i][1]) + abs(txy[i + 1][2] - txy[i][2])
if time >= length and time % 2 == length % 2:
continue
else:
print("No")
exit()
print("Yes")
|
import sys
import numpy as np
read = sys.stdin.read
def main():
N, *txy = list(map(int, read().split()))
t = np.array([0] + txy[::3], np.int64)
x = np.array([0] + txy[1::3], np.int64)
y = np.array([0] + txy[2::3], np.int64)
time = t[1:] - t[:-1]
length = np.abs(y[1:] - y[:-1]) + np.abs(x[1:] - x[:-1])
if np.any((time < length) | (time % 2 != length % 2)):
print("No")
else:
print("Yes")
if __name__ == "__main__":
main()
| false | 38.095238 |
[
"-N = int(eval(input()))",
"-txy = [[0, 0, 0]]",
"-txy.extend([list(map(int, input().split())) for i in range(N)])",
"-for i in range(N):",
"- time = txy[i + 1][0] - txy[i][0]",
"- length = abs(txy[i + 1][1] - txy[i][1]) + abs(txy[i + 1][2] - txy[i][2])",
"- if time >= length and time % 2 == length % 2:",
"- continue",
"+import sys",
"+import numpy as np",
"+",
"+read = sys.stdin.read",
"+",
"+",
"+def main():",
"+ N, *txy = list(map(int, read().split()))",
"+ t = np.array([0] + txy[::3], np.int64)",
"+ x = np.array([0] + txy[1::3], np.int64)",
"+ y = np.array([0] + txy[2::3], np.int64)",
"+ time = t[1:] - t[:-1]",
"+ length = np.abs(y[1:] - y[:-1]) + np.abs(x[1:] - x[:-1])",
"+ if np.any((time < length) | (time % 2 != length % 2)):",
"+ print(\"No\")",
"- print(\"No\")",
"- exit()",
"-print(\"Yes\")",
"+ print(\"Yes\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.036825 | 0.245982 | 0.149706 |
[
"s421168999",
"s169706195"
] |
u413165887
|
p02803
|
python
|
s789173444
|
s131715723
| 1,487 | 446 | 13,008 | 3,316 |
Accepted
|
Accepted
| 70.01 |
from collections import deque
import numpy as np
h, w = list(map(int,input().split()))
s = [eval(input()) for _ in range(h)]
result = []
for xx in range(h):
for yy in range(w):
if s[xx][yy]==".":
visit = np.array([np.array([-1 for _ in range(w)]) for __ in range(h)])
visit[xx][yy] = 0
q = deque([[xx,yy]])
while q:
x, y = q.popleft()
for i in [-1, 1]:
if 0 <= x+i and x+i < h:
if s[x+i][y] != "#" and visit[x+i][y] < 0:
visit[x+i][y] = visit[x][y]+1
q.append([x+i, y])
if 0 <= y+i and y+i < w:
if s[x][y+i] != "#" and visit[x][y+i] < 0:
visit[x][y+i] = visit[x][y]+1
q.append([x, y+i])
result.append(max(visit.flatten()))
print((max(result)))
|
from collections import deque
h, w = list(map(int,input().split()))
s = [eval(input()) for _ in range(h)]
result = []
for xx in range(h):
for yy in range(w):
if s[xx][yy]==".":
visit = [[-1 for _ in range(w)] for __ in range(h)]
visit[xx][yy] = 0
q = deque([[xx,yy]])
while q:
x, y = q.popleft()
for i in [-1, 1]:
if 0 <= x+i and x+i < h:
if s[x+i][y] != "#" and visit[x+i][y] < 0:
visit[x+i][y] = visit[x][y]+1
q.append([x+i, y])
if 0 <= y+i and y+i < w:
if s[x][y+i] != "#" and visit[x][y+i] < 0:
visit[x][y+i] = visit[x][y]+1
q.append([x, y+i])
result.append(max([max(i) for i in visit]))
print((max(result)))
| 25 | 24 | 958 | 926 |
from collections import deque
import numpy as np
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
result = []
for xx in range(h):
for yy in range(w):
if s[xx][yy] == ".":
visit = np.array([np.array([-1 for _ in range(w)]) for __ in range(h)])
visit[xx][yy] = 0
q = deque([[xx, yy]])
while q:
x, y = q.popleft()
for i in [-1, 1]:
if 0 <= x + i and x + i < h:
if s[x + i][y] != "#" and visit[x + i][y] < 0:
visit[x + i][y] = visit[x][y] + 1
q.append([x + i, y])
if 0 <= y + i and y + i < w:
if s[x][y + i] != "#" and visit[x][y + i] < 0:
visit[x][y + i] = visit[x][y] + 1
q.append([x, y + i])
result.append(max(visit.flatten()))
print((max(result)))
|
from collections import deque
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
result = []
for xx in range(h):
for yy in range(w):
if s[xx][yy] == ".":
visit = [[-1 for _ in range(w)] for __ in range(h)]
visit[xx][yy] = 0
q = deque([[xx, yy]])
while q:
x, y = q.popleft()
for i in [-1, 1]:
if 0 <= x + i and x + i < h:
if s[x + i][y] != "#" and visit[x + i][y] < 0:
visit[x + i][y] = visit[x][y] + 1
q.append([x + i, y])
if 0 <= y + i and y + i < w:
if s[x][y + i] != "#" and visit[x][y + i] < 0:
visit[x][y + i] = visit[x][y] + 1
q.append([x, y + i])
result.append(max([max(i) for i in visit]))
print((max(result)))
| false | 4 |
[
"-import numpy as np",
"- visit = np.array([np.array([-1 for _ in range(w)]) for __ in range(h)])",
"+ visit = [[-1 for _ in range(w)] for __ in range(h)]",
"- result.append(max(visit.flatten()))",
"+ result.append(max([max(i) for i in visit]))"
] | false | 0.269041 | 0.037036 | 7.264342 |
[
"s789173444",
"s131715723"
] |
u319589470
|
p03161
|
python
|
s888725428
|
s992559867
| 1,892 | 225 | 22,836 | 85,520 |
Accepted
|
Accepted
| 88.11 |
import numpy as np
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp = np.zeros(n,dtype = int)
h = np.array(h)
for i in range(1,n):
start = max(0, i-k)
dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[-1]))
|
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
def MI(): return list(map(int,input().split()))
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
n,k = MI()
h = [0]+ LI()
#h[i]はi番目の高さ
#0-indexedにしておくと考えにくいので1-indexedにしておく
#dp[i]は足場iにいくのに必要な最小コスト
dp = [10**15]*(n+1)
#これも1-indexedにしておく
dp[1] = 0
#2番目の足場に移るのは1番目の足場からいくしかないのでわけて考える
#最初蛙は足場1にいるため最小コストは0としておく
for i in range(2,n+1):
for j in range(1,k+1):
if i - j >= 0:
dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
print((dp[n]))
| 9 | 20 | 249 | 549 |
import numpy as np
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = np.zeros(n, dtype=int)
h = np.array(h)
for i in range(1, n):
start = max(0, i - k)
dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[-1]))
|
def I():
return int(eval(input()))
def LI():
return list(map(int, input().split()))
def MI():
return list(map(int, input().split()))
def LLI(n):
return [list(map(int, input().split())) for _ in range(n)]
n, k = MI()
h = [0] + LI()
# h[i]はi番目の高さ
# 0-indexedにしておくと考えにくいので1-indexedにしておく
# dp[i]は足場iにいくのに必要な最小コスト
dp = [10**15] * (n + 1)
# これも1-indexedにしておく
dp[1] = 0
# 2番目の足場に移るのは1番目の足場からいくしかないのでわけて考える
# 最初蛙は足場1にいるため最小コストは0としておく
for i in range(2, n + 1):
for j in range(1, k + 1):
if i - j >= 0:
dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i])
print((dp[n]))
| false | 55 |
[
"-import numpy as np",
"+def I():",
"+ return int(eval(input()))",
"-n, k = list(map(int, input().split()))",
"-h = list(map(int, input().split()))",
"-dp = np.zeros(n, dtype=int)",
"-h = np.array(h)",
"-for i in range(1, n):",
"- start = max(0, i - k)",
"- dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))",
"-print((dp[-1]))",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LLI(n):",
"+ return [list(map(int, input().split())) for _ in range(n)]",
"+",
"+",
"+n, k = MI()",
"+h = [0] + LI()",
"+# h[i]はi番目の高さ",
"+# 0-indexedにしておくと考えにくいので1-indexedにしておく",
"+# dp[i]は足場iにいくのに必要な最小コスト",
"+dp = [10**15] * (n + 1)",
"+# これも1-indexedにしておく",
"+dp[1] = 0",
"+# 2番目の足場に移るのは1番目の足場からいくしかないのでわけて考える",
"+# 最初蛙は足場1にいるため最小コストは0としておく",
"+for i in range(2, n + 1):",
"+ for j in range(1, k + 1):",
"+ if i - j >= 0:",
"+ dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i])",
"+print((dp[n]))"
] | false | 0.242514 | 0.085955 | 2.821414 |
[
"s888725428",
"s992559867"
] |
u268318377
|
p02630
|
python
|
s444466329
|
s338885102
| 370 | 341 | 33,788 | 33,832 |
Accepted
|
Accepted
| 7.84 |
#import numpy as np
from collections import Counter
from time import time
import sys
readline = sys.stdin.buffer.readline
N = int(eval(input()))
A = list(map(int, input().split()))
#A = np.random.randint(1, 10 ** 5 + 1, 10 ** 5)
S = sum(A)
C = Counter(A)
Q = int(eval(input()))
#Q = 10 ** 5
ans = []
s = time()
for _ in range(Q):
b, c = list(map(int, input().split()))
#b, c = np.random.randint(1, 10 ** 5 + 1, 2)
#b, c = 2, 5
count = C[b]
S = S + (c - b) * count
C[c] += count
C[b] = 0
ans.append(S)
print(('\n'.join(map(str, ans))))
#print('time: ', time() - s)
|
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
S = sum(A)
C = Counter(A)
ans = []
for _ in range(Q):
b, c = list(map(int, input().split()))
count = C[b]
S += (c - b) * count
C[b], C[c] = 0, C[c] + count
ans.append(S)
print(('\n'.join(map(str, ans))))
| 35 | 19 | 623 | 340 |
# import numpy as np
from collections import Counter
from time import time
import sys
readline = sys.stdin.buffer.readline
N = int(eval(input()))
A = list(map(int, input().split()))
# A = np.random.randint(1, 10 ** 5 + 1, 10 ** 5)
S = sum(A)
C = Counter(A)
Q = int(eval(input()))
# Q = 10 ** 5
ans = []
s = time()
for _ in range(Q):
b, c = list(map(int, input().split()))
# b, c = np.random.randint(1, 10 ** 5 + 1, 2)
# b, c = 2, 5
count = C[b]
S = S + (c - b) * count
C[c] += count
C[b] = 0
ans.append(S)
print(("\n".join(map(str, ans))))
# print('time: ', time() - s)
|
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
S = sum(A)
C = Counter(A)
ans = []
for _ in range(Q):
b, c = list(map(int, input().split()))
count = C[b]
S += (c - b) * count
C[b], C[c] = 0, C[c] + count
ans.append(S)
print(("\n".join(map(str, ans))))
| false | 45.714286 |
[
"-# import numpy as np",
"-from time import time",
"-import sys",
"-readline = sys.stdin.buffer.readline",
"-# A = np.random.randint(1, 10 ** 5 + 1, 10 ** 5)",
"+Q = int(eval(input()))",
"-Q = int(eval(input()))",
"-# Q = 10 ** 5",
"-s = time()",
"- # b, c = np.random.randint(1, 10 ** 5 + 1, 2)",
"- # b, c = 2, 5",
"- S = S + (c - b) * count",
"- C[c] += count",
"- C[b] = 0",
"+ S += (c - b) * count",
"+ C[b], C[c] = 0, C[c] + count",
"-# print('time: ', time() - s)"
] | false | 0.044319 | 0.044191 | 1.002908 |
[
"s444466329",
"s338885102"
] |
u634046173
|
p03001
|
python
|
s295315718
|
s226328826
| 65 | 60 | 61,784 | 61,824 |
Accepted
|
Accepted
| 7.69 |
W,H,X,Y = list(map(int,input().split()))
if W/2 == X and H/2 == Y:
f = 1
else:
f = 0
print((W*H/2, f))
|
W,H,X,Y = list(map(int,input().split()))
if W == X*2 and H == Y*2:
f = 1
else:
f = 0
print((W*H/2, f))
| 6 | 6 | 108 | 108 |
W, H, X, Y = list(map(int, input().split()))
if W / 2 == X and H / 2 == Y:
f = 1
else:
f = 0
print((W * H / 2, f))
|
W, H, X, Y = list(map(int, input().split()))
if W == X * 2 and H == Y * 2:
f = 1
else:
f = 0
print((W * H / 2, f))
| false | 0 |
[
"-if W / 2 == X and H / 2 == Y:",
"+if W == X * 2 and H == Y * 2:"
] | false | 0.037618 | 0.091837 | 0.409614 |
[
"s295315718",
"s226328826"
] |
u026788530
|
p02990
|
python
|
s742377302
|
s529228460
| 992 | 239 | 20,852 | 27,148 |
Accepted
|
Accepted
| 75.91 |
MOD = 10**9+7
lim = 200000
inv_t = [-1 for i in range(lim+1)]
factrial = [-1 for i in range(lim+1)]
factrial_inv = [-1 for i in range(lim+1)]
def set_inv(max=lim):
inv_t[0] = 0
for i in range(1, max):
inv_t[i] == mod_inv(i)
def mod_inv(x, mod=MOD):
y, u, v, _x = mod, 1, 0, x
while y:
t = _x//y
_x -= t*y
_x, y = y, _x
u -= t*v
u, v = v, u
u %= mod
if u < 0:
u += mod
return u
def mod_pow(a, n, mod=MOD):
res = 1
while n:
if n & 1:
res = res*a % mod
a = a*a % mod
n >>= 1
return res
def set_factrial(max=lim, mod=MOD):
c = 1
factrial[0] = factrial_inv[0] = 1
for i in range(1, max):
c *= i
c %= mod
factrial[i] = c
factrial_inv[i] = mod_inv(c, mod)
def comb(a, b, mod=MOD):
if a < b:
return 0
if factrial[0] == -1:
set_factrial()
return (factrial[a]*factrial_inv[b]*factrial_inv[a-b]) % mod
n, k = [int(_) for _ in input().split()]
for i in range(k):
print((comb(n-k+1, i+1)*comb(k-1, i) % MOD))
|
MOD = 10**9+7
lim = 200000
inv_t = [-1 for i in range(lim+1)]
factrial = [-1 for i in range(lim+1)]
factrial_inv = [-1 for i in range(lim+1)]
def mod_inv(x, mod=MOD):
y, u, v, _x = mod, 1, 0, x
while y:
t = _x//y
_x -= t*y
_x, y = y, _x
u -= t*v
u, v = v, u
u %= mod
if u < 0:
u += mod
return u
def mod_pow(a, n, mod=MOD):
res = 1
while n:
if n & 1:
res = res*a % mod
a = a*a % mod
n >>= 1
return res
def COMinit(max=lim, mod=MOD):
factrial[0] = factrial_inv[0] = 1
factrial[1] = factrial_inv[1] = 1
inv_t[0] = inv_t[1] = 1
for i in range(2, max):
factrial[i] = factrial[i-1]*i % mod
inv_t[i] = mod-inv_t[mod % i]*(mod//i) % mod
factrial_inv[i] = factrial_inv[i-1]*inv_t[i] % mod
def comb(a, b, mod=MOD):
if a < b:
return 0
if factrial[0] == -1:
COMinit()
return (factrial[a]*factrial_inv[b]*factrial_inv[a-b]) % mod
n, k = [int(_) for _ in input().split()]
for i in range(k):
print((comb(n-k+1, i+1)*comb(k-1, i) % MOD))
| 59 | 52 | 1,173 | 1,169 |
MOD = 10**9 + 7
lim = 200000
inv_t = [-1 for i in range(lim + 1)]
factrial = [-1 for i in range(lim + 1)]
factrial_inv = [-1 for i in range(lim + 1)]
def set_inv(max=lim):
inv_t[0] = 0
for i in range(1, max):
inv_t[i] == mod_inv(i)
def mod_inv(x, mod=MOD):
y, u, v, _x = mod, 1, 0, x
while y:
t = _x // y
_x -= t * y
_x, y = y, _x
u -= t * v
u, v = v, u
u %= mod
if u < 0:
u += mod
return u
def mod_pow(a, n, mod=MOD):
res = 1
while n:
if n & 1:
res = res * a % mod
a = a * a % mod
n >>= 1
return res
def set_factrial(max=lim, mod=MOD):
c = 1
factrial[0] = factrial_inv[0] = 1
for i in range(1, max):
c *= i
c %= mod
factrial[i] = c
factrial_inv[i] = mod_inv(c, mod)
def comb(a, b, mod=MOD):
if a < b:
return 0
if factrial[0] == -1:
set_factrial()
return (factrial[a] * factrial_inv[b] * factrial_inv[a - b]) % mod
n, k = [int(_) for _ in input().split()]
for i in range(k):
print((comb(n - k + 1, i + 1) * comb(k - 1, i) % MOD))
|
MOD = 10**9 + 7
lim = 200000
inv_t = [-1 for i in range(lim + 1)]
factrial = [-1 for i in range(lim + 1)]
factrial_inv = [-1 for i in range(lim + 1)]
def mod_inv(x, mod=MOD):
y, u, v, _x = mod, 1, 0, x
while y:
t = _x // y
_x -= t * y
_x, y = y, _x
u -= t * v
u, v = v, u
u %= mod
if u < 0:
u += mod
return u
def mod_pow(a, n, mod=MOD):
res = 1
while n:
if n & 1:
res = res * a % mod
a = a * a % mod
n >>= 1
return res
def COMinit(max=lim, mod=MOD):
factrial[0] = factrial_inv[0] = 1
factrial[1] = factrial_inv[1] = 1
inv_t[0] = inv_t[1] = 1
for i in range(2, max):
factrial[i] = factrial[i - 1] * i % mod
inv_t[i] = mod - inv_t[mod % i] * (mod // i) % mod
factrial_inv[i] = factrial_inv[i - 1] * inv_t[i] % mod
def comb(a, b, mod=MOD):
if a < b:
return 0
if factrial[0] == -1:
COMinit()
return (factrial[a] * factrial_inv[b] * factrial_inv[a - b]) % mod
n, k = [int(_) for _ in input().split()]
for i in range(k):
print((comb(n - k + 1, i + 1) * comb(k - 1, i) % MOD))
| false | 11.864407 |
[
"-",
"-",
"-def set_inv(max=lim):",
"- inv_t[0] = 0",
"- for i in range(1, max):",
"- inv_t[i] == mod_inv(i)",
"-def set_factrial(max=lim, mod=MOD):",
"- c = 1",
"+def COMinit(max=lim, mod=MOD):",
"- for i in range(1, max):",
"- c *= i",
"- c %= mod",
"- factrial[i] = c",
"- factrial_inv[i] = mod_inv(c, mod)",
"+ factrial[1] = factrial_inv[1] = 1",
"+ inv_t[0] = inv_t[1] = 1",
"+ for i in range(2, max):",
"+ factrial[i] = factrial[i - 1] * i % mod",
"+ inv_t[i] = mod - inv_t[mod % i] * (mod // i) % mod",
"+ factrial_inv[i] = factrial_inv[i - 1] * inv_t[i] % mod",
"- set_factrial()",
"+ COMinit()"
] | false | 1.498953 | 0.558794 | 2.682477 |
[
"s742377302",
"s529228460"
] |
u513081876
|
p03681
|
python
|
s801632395
|
s084593016
| 704 | 47 | 5,192 | 3,060 |
Accepted
|
Accepted
| 93.32 |
from math import factorial
N, M = list(map(int, input().split()))
if abs(N-M) >= 2:
print((0))
elif abs(N-M) == 1:
print(((factorial(N)*factorial(M)) % (10**9+7)))
elif abs(N-M) == 0:
print(((factorial(N)*factorial(M)*2) % (10**9+7)))
|
N, M = list(map(int, input().split()))
ans = 0
def fac(n):
ans = 1
for i in range(1, n+1):
ans *= i
ans %= (10**9+7)
return ans
if abs(N-M) >= 2:
ans = 0
else:
if N == M:
ans = fac(N) * fac(M) * 2 % (10**9+7)
else:
ans = fac(N) * fac(M) % (10**9 + 7)
print(ans)
| 9 | 19 | 243 | 332 |
from math import factorial
N, M = list(map(int, input().split()))
if abs(N - M) >= 2:
print((0))
elif abs(N - M) == 1:
print(((factorial(N) * factorial(M)) % (10**9 + 7)))
elif abs(N - M) == 0:
print(((factorial(N) * factorial(M) * 2) % (10**9 + 7)))
|
N, M = list(map(int, input().split()))
ans = 0
def fac(n):
ans = 1
for i in range(1, n + 1):
ans *= i
ans %= 10**9 + 7
return ans
if abs(N - M) >= 2:
ans = 0
else:
if N == M:
ans = fac(N) * fac(M) * 2 % (10**9 + 7)
else:
ans = fac(N) * fac(M) % (10**9 + 7)
print(ans)
| false | 52.631579 |
[
"-from math import factorial",
"+N, M = list(map(int, input().split()))",
"+ans = 0",
"-N, M = list(map(int, input().split()))",
"+",
"+def fac(n):",
"+ ans = 1",
"+ for i in range(1, n + 1):",
"+ ans *= i",
"+ ans %= 10**9 + 7",
"+ return ans",
"+",
"+",
"- print((0))",
"-elif abs(N - M) == 1:",
"- print(((factorial(N) * factorial(M)) % (10**9 + 7)))",
"-elif abs(N - M) == 0:",
"- print(((factorial(N) * factorial(M) * 2) % (10**9 + 7)))",
"+ ans = 0",
"+else:",
"+ if N == M:",
"+ ans = fac(N) * fac(M) * 2 % (10**9 + 7)",
"+ else:",
"+ ans = fac(N) * fac(M) % (10**9 + 7)",
"+print(ans)"
] | false | 0.039768 | 0.038039 | 1.045472 |
[
"s801632395",
"s084593016"
] |
u608088992
|
p03627
|
python
|
s224885964
|
s560385843
| 111 | 76 | 17,960 | 17,988 |
Accepted
|
Accepted
| 31.53 |
def solve():
N = int(eval(input()))
A = [int(a) for a in input().split()]
A.sort()
Adict = dict()
for i, a in enumerate(A):
if a in Adict: Adict[a] += 1
else: Adict[a] = 1
rect = 0
ri = -1
for i in reversed(list(range(N))):
if Adict[A[i]] >= 4:
rect = A[i] ** 2
break
if Adict[A[i]] >= 2:
rect = A[i]
ri = i
break
if ri > -1:
for i in reversed(list(range(ri))):
if Adict[A[i]] >= 2 and A[i] != rect:
rect *= A[i]
break
print(rect)
if __name__ == "__main__":
solve()
|
import sys
from heapq import heapify, heappop, heappush
def solve():
input = sys.stdin.readline
N = int(eval(input()))
A = [int(a) for a in input().split()]
Anum = dict()
for a in A:
if a in Anum: Anum[a] += 1
else: Anum[a] = 1
q = [0, 0]
for key in Anum:
if Anum[key] >= 2: q.append(-key)
if Anum[key] >= 4: q.append(-key)
heapify(q)
x = heappop(q)
y = heappop(q)
print((x * y))
return 0
if __name__ == "__main__":
solve()
| 29 | 25 | 667 | 529 |
def solve():
N = int(eval(input()))
A = [int(a) for a in input().split()]
A.sort()
Adict = dict()
for i, a in enumerate(A):
if a in Adict:
Adict[a] += 1
else:
Adict[a] = 1
rect = 0
ri = -1
for i in reversed(list(range(N))):
if Adict[A[i]] >= 4:
rect = A[i] ** 2
break
if Adict[A[i]] >= 2:
rect = A[i]
ri = i
break
if ri > -1:
for i in reversed(list(range(ri))):
if Adict[A[i]] >= 2 and A[i] != rect:
rect *= A[i]
break
print(rect)
if __name__ == "__main__":
solve()
|
import sys
from heapq import heapify, heappop, heappush
def solve():
input = sys.stdin.readline
N = int(eval(input()))
A = [int(a) for a in input().split()]
Anum = dict()
for a in A:
if a in Anum:
Anum[a] += 1
else:
Anum[a] = 1
q = [0, 0]
for key in Anum:
if Anum[key] >= 2:
q.append(-key)
if Anum[key] >= 4:
q.append(-key)
heapify(q)
x = heappop(q)
y = heappop(q)
print((x * y))
return 0
if __name__ == "__main__":
solve()
| false | 13.793103 |
[
"+import sys",
"+from heapq import heapify, heappop, heappush",
"+",
"+",
"+ input = sys.stdin.readline",
"- A.sort()",
"- Adict = dict()",
"- for i, a in enumerate(A):",
"- if a in Adict:",
"- Adict[a] += 1",
"+ Anum = dict()",
"+ for a in A:",
"+ if a in Anum:",
"+ Anum[a] += 1",
"- Adict[a] = 1",
"- rect = 0",
"- ri = -1",
"- for i in reversed(list(range(N))):",
"- if Adict[A[i]] >= 4:",
"- rect = A[i] ** 2",
"- break",
"- if Adict[A[i]] >= 2:",
"- rect = A[i]",
"- ri = i",
"- break",
"- if ri > -1:",
"- for i in reversed(list(range(ri))):",
"- if Adict[A[i]] >= 2 and A[i] != rect:",
"- rect *= A[i]",
"- break",
"- print(rect)",
"+ Anum[a] = 1",
"+ q = [0, 0]",
"+ for key in Anum:",
"+ if Anum[key] >= 2:",
"+ q.append(-key)",
"+ if Anum[key] >= 4:",
"+ q.append(-key)",
"+ heapify(q)",
"+ x = heappop(q)",
"+ y = heappop(q)",
"+ print((x * y))",
"+ return 0"
] | false | 0.040906 | 0.043542 | 0.939458 |
[
"s224885964",
"s560385843"
] |
u709799578
|
p02887
|
python
|
s173506241
|
s898258341
| 55 | 30 | 3,316 | 4,644 |
Accepted
|
Accepted
| 45.45 |
n = int(eval(input()))
s = eval(input())
ans = s[:1]
for i in range(1, n):
if ans[-1:] != s[i]:
ans += s[i]
print((len(ans)))
|
import itertools
n = int(eval(input()))
s = list(eval(input()))
ans = [k for k, v in itertools.groupby(s)]
print((len(ans)))
| 7 | 5 | 129 | 114 |
n = int(eval(input()))
s = eval(input())
ans = s[:1]
for i in range(1, n):
if ans[-1:] != s[i]:
ans += s[i]
print((len(ans)))
|
import itertools
n = int(eval(input()))
s = list(eval(input()))
ans = [k for k, v in itertools.groupby(s)]
print((len(ans)))
| false | 28.571429 |
[
"+import itertools",
"+",
"-s = eval(input())",
"-ans = s[:1]",
"-for i in range(1, n):",
"- if ans[-1:] != s[i]:",
"- ans += s[i]",
"+s = list(eval(input()))",
"+ans = [k for k, v in itertools.groupby(s)]"
] | false | 0.040968 | 0.040705 | 1.006464 |
[
"s173506241",
"s898258341"
] |
u254871849
|
p03762
|
python
|
s962902154
|
s517806428
| 235 | 215 | 20,672 | 37,364 |
Accepted
|
Accepted
| 8.51 |
# 予めsx, syを全て計算しておく
# このとき漸化式を使えば毎回全ての話を求める必要がない
mod = int(1e9+7)
n, m = [int(num) for num in input().split()]
x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]
sx = [0] * n
sx[0] = x[0]
for i in range(n-1):
sx[i+1] = sx[i] + x[i+1]
sxd = 0
for i in range(n-1):
sxd += ((sx[n-1] - sx[i]) - x[i] * ((n-1) - (i+1) + 1)) #% mod
sy = [0] * m
sy[0] = y[0]
for k in range(m-1):
sy[k+1] = sy[k] + y[k+1]
syd = 0
for k in range(m-1):
syd += ((sy[m-1] - sy[k]) - y[k] * ((m-1) - (k+1) + 1)) #% mod
ans = ((sxd % mod) * (syd % mod)) % mod
print(ans)
|
import sys
import numpy as np
MOD = 10 ** 9 + 7
I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, m = I[:2]
x = I[2:2+n]
y = I[2+n:]
def main():
sx = np.cumsum(x) % MOD
sy = np.cumsum(y) % MOD
sdx = np.sum((sx[n-1] - sx[:n-1]) - x[:n-1] * ((n-1) - np.arange(n-1))) % MOD
sdy = np.sum((sy[m-1] - sy[:m-1]) - y[:m-1] * ((m-1) - np.arange(m-1))) % MOD
ans = sdx * sdy % MOD
return ans
if __name__ == '__main__':
ans = main()
print(ans)
| 29 | 23 | 618 | 501 |
# 予めsx, syを全て計算しておく
# このとき漸化式を使えば毎回全ての話を求める必要がない
mod = int(1e9 + 7)
n, m = [int(num) for num in input().split()]
x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]
sx = [0] * n
sx[0] = x[0]
for i in range(n - 1):
sx[i + 1] = sx[i] + x[i + 1]
sxd = 0
for i in range(n - 1):
sxd += (sx[n - 1] - sx[i]) - x[i] * ((n - 1) - (i + 1) + 1) #% mod
sy = [0] * m
sy[0] = y[0]
for k in range(m - 1):
sy[k + 1] = sy[k] + y[k + 1]
syd = 0
for k in range(m - 1):
syd += (sy[m - 1] - sy[k]) - y[k] * ((m - 1) - (k + 1) + 1) #% mod
ans = ((sxd % mod) * (syd % mod)) % mod
print(ans)
|
import sys
import numpy as np
MOD = 10**9 + 7
I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, m = I[:2]
x = I[2 : 2 + n]
y = I[2 + n :]
def main():
sx = np.cumsum(x) % MOD
sy = np.cumsum(y) % MOD
sdx = (
np.sum((sx[n - 1] - sx[: n - 1]) - x[: n - 1] * ((n - 1) - np.arange(n - 1)))
% MOD
)
sdy = (
np.sum((sy[m - 1] - sy[: m - 1]) - y[: m - 1] * ((m - 1) - np.arange(m - 1)))
% MOD
)
ans = sdx * sdy % MOD
return ans
if __name__ == "__main__":
ans = main()
print(ans)
| false | 20.689655 |
[
"-# 予めsx, syを全て計算しておく",
"-# このとき漸化式を使えば毎回全ての話を求める必要がない",
"-mod = int(1e9 + 7)",
"-n, m = [int(num) for num in input().split()]",
"-x = [int(x) for x in input().split()]",
"-y = [int(y) for y in input().split()]",
"-sx = [0] * n",
"-sx[0] = x[0]",
"-for i in range(n - 1):",
"- sx[i + 1] = sx[i] + x[i + 1]",
"-sxd = 0",
"-for i in range(n - 1):",
"- sxd += (sx[n - 1] - sx[i]) - x[i] * ((n - 1) - (i + 1) + 1) #% mod",
"-sy = [0] * m",
"-sy[0] = y[0]",
"-for k in range(m - 1):",
"- sy[k + 1] = sy[k] + y[k + 1]",
"-syd = 0",
"-for k in range(m - 1):",
"- syd += (sy[m - 1] - sy[k]) - y[k] * ((m - 1) - (k + 1) + 1) #% mod",
"-ans = ((sxd % mod) * (syd % mod)) % mod",
"-print(ans)",
"+import sys",
"+import numpy as np",
"+",
"+MOD = 10**9 + 7",
"+I = np.array(sys.stdin.read().split(), dtype=np.int64)",
"+n, m = I[:2]",
"+x = I[2 : 2 + n]",
"+y = I[2 + n :]",
"+",
"+",
"+def main():",
"+ sx = np.cumsum(x) % MOD",
"+ sy = np.cumsum(y) % MOD",
"+ sdx = (",
"+ np.sum((sx[n - 1] - sx[: n - 1]) - x[: n - 1] * ((n - 1) - np.arange(n - 1)))",
"+ % MOD",
"+ )",
"+ sdy = (",
"+ np.sum((sy[m - 1] - sy[: m - 1]) - y[: m - 1] * ((m - 1) - np.arange(m - 1)))",
"+ % MOD",
"+ )",
"+ ans = sdx * sdy % MOD",
"+ return ans",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ ans = main()",
"+ print(ans)"
] | false | 0.050269 | 0.19695 | 0.255236 |
[
"s962902154",
"s517806428"
] |
u786020649
|
p03476
|
python
|
s272970538
|
s742388111
| 278 | 137 | 24,784 | 32,968 |
Accepted
|
Accepted
| 50.72 |
q=int(eval(input()))
lr=[tuple(map(int,input().split())) for _ in range(q)]
def main():
n=10**5
ansl=[]
sieve=[1]*(n+1)
sieve[0],sieve[1]=0,0
for i in range(2,n):
if sieve[i]:
sieve[2*i::i]=[0 for _ in range(2*i,n+1,i)]
ans=[0]*(n+1)
for i in range(3,n):
if sieve[i]==1 and sieve[(i+1)//2]==1:
ans[i]=ans[i-1]+1
else:
ans[i]=ans[i-1]
for e in lr:
print((ans[e[1]]-ans[e[0]-1]))
if __name__=='__main__':
main()
|
import sys
from itertools import accumulate
readline=sys.stdin.readline
read=sys.stdin.read
def main():
q,*lr=list(map(int,read().split()))
n=10**5
ansl=[]
sieve=[1]*(n+1)
sieve[0],sieve[1]=0,0
for i in range(2,n):
if sieve[i]:
sieve[2*i::i]=[0 for _ in range(2*i,n+1,i)]
ans=[0]*(n+1)
for i in range(3,n):
if sieve[i]==1 and sieve[(i+1)//2]==1:
#ans[i]=1
ans[i]=ans[i-1]+1
else:
ans[i]=ans[i-1]
#ans=list(accumulate(ans))
for l,r in zip(*[iter(lr)]*2):
print((ans[r]-ans[l-1]))
if __name__=='__main__':
main()
| 23 | 29 | 478 | 599 |
q = int(eval(input()))
lr = [tuple(map(int, input().split())) for _ in range(q)]
def main():
n = 10**5
ansl = []
sieve = [1] * (n + 1)
sieve[0], sieve[1] = 0, 0
for i in range(2, n):
if sieve[i]:
sieve[2 * i :: i] = [0 for _ in range(2 * i, n + 1, i)]
ans = [0] * (n + 1)
for i in range(3, n):
if sieve[i] == 1 and sieve[(i + 1) // 2] == 1:
ans[i] = ans[i - 1] + 1
else:
ans[i] = ans[i - 1]
for e in lr:
print((ans[e[1]] - ans[e[0] - 1]))
if __name__ == "__main__":
main()
|
import sys
from itertools import accumulate
readline = sys.stdin.readline
read = sys.stdin.read
def main():
q, *lr = list(map(int, read().split()))
n = 10**5
ansl = []
sieve = [1] * (n + 1)
sieve[0], sieve[1] = 0, 0
for i in range(2, n):
if sieve[i]:
sieve[2 * i :: i] = [0 for _ in range(2 * i, n + 1, i)]
ans = [0] * (n + 1)
for i in range(3, n):
if sieve[i] == 1 and sieve[(i + 1) // 2] == 1:
# ans[i]=1
ans[i] = ans[i - 1] + 1
else:
ans[i] = ans[i - 1]
# ans=list(accumulate(ans))
for l, r in zip(*[iter(lr)] * 2):
print((ans[r] - ans[l - 1]))
if __name__ == "__main__":
main()
| false | 20.689655 |
[
"-q = int(eval(input()))",
"-lr = [tuple(map(int, input().split())) for _ in range(q)]",
"+import sys",
"+from itertools import accumulate",
"+",
"+readline = sys.stdin.readline",
"+read = sys.stdin.read",
"+ q, *lr = list(map(int, read().split()))",
"+ # ans[i]=1",
"- for e in lr:",
"- print((ans[e[1]] - ans[e[0] - 1]))",
"+ # ans=list(accumulate(ans))",
"+ for l, r in zip(*[iter(lr)] * 2):",
"+ print((ans[r] - ans[l - 1]))"
] | false | 0.115243 | 0.137238 | 0.83973 |
[
"s272970538",
"s742388111"
] |
u687053495
|
p02793
|
python
|
s894209994
|
s933213146
| 1,896 | 698 | 5,596 | 14,476 |
Accepted
|
Accepted
| 63.19 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
from fractions import gcd
from functools import reduce
L = A[0]
for i in range(1,N):
L=(L*A[i])//gcd(L,A[i])
ans = 0
for i in range(N):
ans += (L // A[i])
print((ans % mod))
|
# エラトステネスを素因数分解とlcm
N = int(eval(input()))
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
def inverse(a): #aに対し、a**(mod-2)、つまり逆元を返す
T=[a]
while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
T.append(T[-1]**2%mod)
b=bin(mod-2) #mod-2を2進数表記にする
ans=1
for i in range(len(b)-2):
if int(b[-i-1])==1:
ans=ans*T[i]%mod
return ans
def eratosthenes(n): #エラストテネスの篩(最大の素因数を格納した配列)
A = [0] * n
A[0], A[1] = -1, -1
for i in range(2, n):
if A[i] == 0:
j = i
while j < n:
A[j] = i
j += i
return A
E = eratosthenes(10**6+5)
l = {}
for a in A:
now = a
f = [] #素因数格納配列
while now > 1:
f.append(E[now])
now //= E[now]
chk = 0
for p in f:
if chk == p: #同じ素因数が複数あるときに飛ばす
continue
chk = p
if p in list(l.keys()): #辞書に素因数がある場合、個数の多いほう
l[p] = max(l[p], f.count(p))
else: #辞書にない場合新規追加
l[p] = f.count(p)
lcm = 1
for k in l:
for i in range(l[k]):
lcm= lcm * k % mod
s = 0
for i in range(N):
s += lcm * inverse(A[i]) % mod
s %= mod
print(s)
| 21 | 61 | 312 | 1,141 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
from fractions import gcd
from functools import reduce
L = A[0]
for i in range(1, N):
L = (L * A[i]) // gcd(L, A[i])
ans = 0
for i in range(N):
ans += L // A[i]
print((ans % mod))
|
# エラトステネスを素因数分解とlcm
N = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
def inverse(a): # aに対し、a**(mod-2)、つまり逆元を返す
T = [a]
while 2 ** (len(T)) < mod: # a**1,a**2.a**4,a**8,...を計算しておく
T.append(T[-1] ** 2 % mod)
b = bin(mod - 2) # mod-2を2進数表記にする
ans = 1
for i in range(len(b) - 2):
if int(b[-i - 1]) == 1:
ans = ans * T[i] % mod
return ans
def eratosthenes(n): # エラストテネスの篩(最大の素因数を格納した配列)
A = [0] * n
A[0], A[1] = -1, -1
for i in range(2, n):
if A[i] == 0:
j = i
while j < n:
A[j] = i
j += i
return A
E = eratosthenes(10**6 + 5)
l = {}
for a in A:
now = a
f = [] # 素因数格納配列
while now > 1:
f.append(E[now])
now //= E[now]
chk = 0
for p in f:
if chk == p: # 同じ素因数が複数あるときに飛ばす
continue
chk = p
if p in list(l.keys()): # 辞書に素因数がある場合、個数の多いほう
l[p] = max(l[p], f.count(p))
else: # 辞書にない場合新規追加
l[p] = f.count(p)
lcm = 1
for k in l:
for i in range(l[k]):
lcm = lcm * k % mod
s = 0
for i in range(N):
s += lcm * inverse(A[i]) % mod
s %= mod
print(s)
| false | 65.57377 |
[
"-import sys",
"-",
"-input = sys.stdin.readline",
"+# エラトステネスを素因数分解とlcm",
"-from fractions import gcd",
"-from functools import reduce",
"-L = A[0]",
"-for i in range(1, N):",
"- L = (L * A[i]) // gcd(L, A[i])",
"-ans = 0",
"+",
"+def inverse(a): # aに対し、a**(mod-2)、つまり逆元を返す",
"+ T = [a]",
"+ while 2 ** (len(T)) < mod: # a**1,a**2.a**4,a**8,...を計算しておく",
"+ T.append(T[-1] ** 2 % mod)",
"+ b = bin(mod - 2) # mod-2を2進数表記にする",
"+ ans = 1",
"+ for i in range(len(b) - 2):",
"+ if int(b[-i - 1]) == 1:",
"+ ans = ans * T[i] % mod",
"+ return ans",
"+",
"+",
"+def eratosthenes(n): # エラストテネスの篩(最大の素因数を格納した配列)",
"+ A = [0] * n",
"+ A[0], A[1] = -1, -1",
"+ for i in range(2, n):",
"+ if A[i] == 0:",
"+ j = i",
"+ while j < n:",
"+ A[j] = i",
"+ j += i",
"+ return A",
"+",
"+",
"+E = eratosthenes(10**6 + 5)",
"+l = {}",
"+for a in A:",
"+ now = a",
"+ f = [] # 素因数格納配列",
"+ while now > 1:",
"+ f.append(E[now])",
"+ now //= E[now]",
"+ chk = 0",
"+ for p in f:",
"+ if chk == p: # 同じ素因数が複数あるときに飛ばす",
"+ continue",
"+ chk = p",
"+ if p in list(l.keys()): # 辞書に素因数がある場合、個数の多いほう",
"+ l[p] = max(l[p], f.count(p))",
"+ else: # 辞書にない場合新規追加",
"+ l[p] = f.count(p)",
"+lcm = 1",
"+for k in l:",
"+ for i in range(l[k]):",
"+ lcm = lcm * k % mod",
"+s = 0",
"- ans += L // A[i]",
"-print((ans % mod))",
"+ s += lcm * inverse(A[i]) % mod",
"+ s %= mod",
"+print(s)"
] | false | 0.046201 | 1.106247 | 0.041764 |
[
"s894209994",
"s933213146"
] |
u608088992
|
p03054
|
python
|
s367312081
|
s269332257
| 357 | 178 | 19,424 | 3,888 |
Accepted
|
Accepted
| 50.14 |
H, W, N = list(map(int, input().split()))
sr, sc = list(map(int, input().split()))
S = eval(input())
T = eval(input())
up = [0] * (N+1)
down = [0] * (N+1)
right = [0] * (N+1)
left = [0] * (N+1)
maxU, maxD, maxR, maxL = 0, 0, 0, 0
for i in range(N):
if S[i] == "L":
left[i+1] = left[i] + 1
right[i+1] = right[i]
up[i+1] = up[i]
down[i+1] = down[i]
maxL = max(maxL, left[i+1])
elif S[i] == "R":
right[i+1] = right[i] + 1
up[i+1] = up[i]
down[i+1] = down[i]
left[i+1] = left[i]
maxR = max(maxR, right[i+1])
elif S[i] == "U":
up[i+1] = up[i] + 1
right[i+1] = right[i]
down[i+1] = down[i]
left[i+1] = left[i]
maxU = max(maxU, up[i+1])
else:
down[i+1] = down[i] + 1
right[i+1] = right[i]
up[i+1] = up[i]
left[i+1] = left[i]
maxD = max(maxD, down[i+1])
if T[i] == "L":
right[i+1] = max(right[i+1] - 1, -sc + 1)
elif T[i] == "R":
left[i+1] = max(left[i+1] - 1, sc - W)
elif T[i] == "U":
down[i+1] = max(down[i+1] - 1, -sr + 1)
else:
up[i+1] = max(up[i+1] - 1, sr - H)
if sr + maxD > H or sr - maxU <= 0 or sc + maxR > W or sc - maxL <= 0:
print("NO")
else: print("YES")
|
import sys
def solve():
input = sys.stdin.readline
H, W, N = list(map(int, input().split()))
s, r = list(map(int, input().split()))
S = input().strip("\n")
T = input().strip("\n")
Lb, Rb, Ub, Db = -1, W, -1, H
for i in reversed(list(range(N))):
if i != N - 1:
if T[i] == "L": Rb = min(Rb + 1, W)
elif T[i] == "R": Lb = max(Lb - 1, -1)
elif T[i] == "U": Db = min(Db + 1, H)
elif T[i] == "D": Ub = max(Ub - 1, 0)
if S[i] == "L": Lb = Lb + 1
elif S[i] == "R": Rb = Rb - 1
elif S[i] == "U": Ub = Ub + 1
elif S[i] == "D": Db = Db - 1
if Lb >= W - 1 or Rb <= 0 or Ub >= H - 1 or Db <= 0:
print("NO")
break
else:
if Lb < r - 1 < Rb and Ub < s - 1 < Db: print("YES")
else: print("NO")
#print(Lb, Rb, Ub, Db)
return 0
if __name__ == "__main__":
solve()
| 50 | 34 | 1,327 | 948 |
H, W, N = list(map(int, input().split()))
sr, sc = list(map(int, input().split()))
S = eval(input())
T = eval(input())
up = [0] * (N + 1)
down = [0] * (N + 1)
right = [0] * (N + 1)
left = [0] * (N + 1)
maxU, maxD, maxR, maxL = 0, 0, 0, 0
for i in range(N):
if S[i] == "L":
left[i + 1] = left[i] + 1
right[i + 1] = right[i]
up[i + 1] = up[i]
down[i + 1] = down[i]
maxL = max(maxL, left[i + 1])
elif S[i] == "R":
right[i + 1] = right[i] + 1
up[i + 1] = up[i]
down[i + 1] = down[i]
left[i + 1] = left[i]
maxR = max(maxR, right[i + 1])
elif S[i] == "U":
up[i + 1] = up[i] + 1
right[i + 1] = right[i]
down[i + 1] = down[i]
left[i + 1] = left[i]
maxU = max(maxU, up[i + 1])
else:
down[i + 1] = down[i] + 1
right[i + 1] = right[i]
up[i + 1] = up[i]
left[i + 1] = left[i]
maxD = max(maxD, down[i + 1])
if T[i] == "L":
right[i + 1] = max(right[i + 1] - 1, -sc + 1)
elif T[i] == "R":
left[i + 1] = max(left[i + 1] - 1, sc - W)
elif T[i] == "U":
down[i + 1] = max(down[i + 1] - 1, -sr + 1)
else:
up[i + 1] = max(up[i + 1] - 1, sr - H)
if sr + maxD > H or sr - maxU <= 0 or sc + maxR > W or sc - maxL <= 0:
print("NO")
else:
print("YES")
|
import sys
def solve():
input = sys.stdin.readline
H, W, N = list(map(int, input().split()))
s, r = list(map(int, input().split()))
S = input().strip("\n")
T = input().strip("\n")
Lb, Rb, Ub, Db = -1, W, -1, H
for i in reversed(list(range(N))):
if i != N - 1:
if T[i] == "L":
Rb = min(Rb + 1, W)
elif T[i] == "R":
Lb = max(Lb - 1, -1)
elif T[i] == "U":
Db = min(Db + 1, H)
elif T[i] == "D":
Ub = max(Ub - 1, 0)
if S[i] == "L":
Lb = Lb + 1
elif S[i] == "R":
Rb = Rb - 1
elif S[i] == "U":
Ub = Ub + 1
elif S[i] == "D":
Db = Db - 1
if Lb >= W - 1 or Rb <= 0 or Ub >= H - 1 or Db <= 0:
print("NO")
break
else:
if Lb < r - 1 < Rb and Ub < s - 1 < Db:
print("YES")
else:
print("NO")
# print(Lb, Rb, Ub, Db)
return 0
if __name__ == "__main__":
solve()
| false | 32 |
[
"-H, W, N = list(map(int, input().split()))",
"-sr, sc = list(map(int, input().split()))",
"-S = eval(input())",
"-T = eval(input())",
"-up = [0] * (N + 1)",
"-down = [0] * (N + 1)",
"-right = [0] * (N + 1)",
"-left = [0] * (N + 1)",
"-maxU, maxD, maxR, maxL = 0, 0, 0, 0",
"-for i in range(N):",
"- if S[i] == \"L\":",
"- left[i + 1] = left[i] + 1",
"- right[i + 1] = right[i]",
"- up[i + 1] = up[i]",
"- down[i + 1] = down[i]",
"- maxL = max(maxL, left[i + 1])",
"- elif S[i] == \"R\":",
"- right[i + 1] = right[i] + 1",
"- up[i + 1] = up[i]",
"- down[i + 1] = down[i]",
"- left[i + 1] = left[i]",
"- maxR = max(maxR, right[i + 1])",
"- elif S[i] == \"U\":",
"- up[i + 1] = up[i] + 1",
"- right[i + 1] = right[i]",
"- down[i + 1] = down[i]",
"- left[i + 1] = left[i]",
"- maxU = max(maxU, up[i + 1])",
"+import sys",
"+",
"+",
"+def solve():",
"+ input = sys.stdin.readline",
"+ H, W, N = list(map(int, input().split()))",
"+ s, r = list(map(int, input().split()))",
"+ S = input().strip(\"\\n\")",
"+ T = input().strip(\"\\n\")",
"+ Lb, Rb, Ub, Db = -1, W, -1, H",
"+ for i in reversed(list(range(N))):",
"+ if i != N - 1:",
"+ if T[i] == \"L\":",
"+ Rb = min(Rb + 1, W)",
"+ elif T[i] == \"R\":",
"+ Lb = max(Lb - 1, -1)",
"+ elif T[i] == \"U\":",
"+ Db = min(Db + 1, H)",
"+ elif T[i] == \"D\":",
"+ Ub = max(Ub - 1, 0)",
"+ if S[i] == \"L\":",
"+ Lb = Lb + 1",
"+ elif S[i] == \"R\":",
"+ Rb = Rb - 1",
"+ elif S[i] == \"U\":",
"+ Ub = Ub + 1",
"+ elif S[i] == \"D\":",
"+ Db = Db - 1",
"+ if Lb >= W - 1 or Rb <= 0 or Ub >= H - 1 or Db <= 0:",
"+ print(\"NO\")",
"+ break",
"- down[i + 1] = down[i] + 1",
"- right[i + 1] = right[i]",
"- up[i + 1] = up[i]",
"- left[i + 1] = left[i]",
"- maxD = max(maxD, down[i + 1])",
"- if T[i] == \"L\":",
"- right[i + 1] = max(right[i + 1] - 1, -sc + 1)",
"- elif T[i] == \"R\":",
"- left[i + 1] = max(left[i + 1] - 1, sc - W)",
"- elif T[i] == \"U\":",
"- down[i + 1] = max(down[i + 1] - 1, -sr + 1)",
"- else:",
"- up[i + 1] = max(up[i + 1] - 1, sr - H)",
"-if sr + maxD > H or sr - maxU <= 0 or sc + maxR > W or sc - maxL <= 0:",
"- print(\"NO\")",
"-else:",
"- print(\"YES\")",
"+ if Lb < r - 1 < Rb and Ub < s - 1 < Db:",
"+ print(\"YES\")",
"+ else:",
"+ print(\"NO\")",
"+ # print(Lb, Rb, Ub, Db)",
"+ return 0",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.143763 | 0.079213 | 1.814891 |
[
"s367312081",
"s269332257"
] |
u119148115
|
p02756
|
python
|
s104895874
|
s687441326
| 609 | 134 | 36,700 | 100,892 |
Accepted
|
Accepted
| 78 |
S = list(eval(input()))
Q = int(eval(input()))
Query = [list(input().split()) for i in range(Q)]
from collections import deque
q = deque(S)
r = 0 #反転の有無
for i in range(Q):
if Query[i][0] == '1':
r = 1-r
else:
if (r + int(Query[i][1])) % 2 == 1:
q.appendleft(Query[i][2])
else:
q.append(Query[i][2])
A = list(q)
if r % 2 == 1:
A.reverse()
ans = ''
for i in range(len(A)):
ans += A[i]
print(ans)
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
S = LS2()
r = 0
left,right = [],[]
Q = I()
for i in range(Q):
A = LS()
if A[0] == '1':
r = 1-r
else:
f,c = A[1],A[2]
if (r == 0 and f == '1') or (r == 1 and f == '2'):
left.append(c)
else:
right.append(c)
if r == 0:
left.reverse()
print((''.join(left+S+right)))
else:
S.reverse()
right.reverse()
print((''.join(right+S+left)))
| 29 | 37 | 482 | 931 |
S = list(eval(input()))
Q = int(eval(input()))
Query = [list(input().split()) for i in range(Q)]
from collections import deque
q = deque(S)
r = 0 # 反転の有無
for i in range(Q):
if Query[i][0] == "1":
r = 1 - r
else:
if (r + int(Query[i][1])) % 2 == 1:
q.appendleft(Query[i][2])
else:
q.append(Query[i][2])
A = list(q)
if r % 2 == 1:
A.reverse()
ans = ""
for i in range(len(A)):
ans += A[i]
print(ans)
|
import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
S = LS2()
r = 0
left, right = [], []
Q = I()
for i in range(Q):
A = LS()
if A[0] == "1":
r = 1 - r
else:
f, c = A[1], A[2]
if (r == 0 and f == "1") or (r == 1 and f == "2"):
left.append(c)
else:
right.append(c)
if r == 0:
left.reverse()
print(("".join(left + S + right)))
else:
S.reverse()
right.reverse()
print(("".join(right + S + left)))
| false | 21.621622 |
[
"-S = list(eval(input()))",
"-Q = int(eval(input()))",
"-Query = [list(input().split()) for i in range(Q)]",
"-from collections import deque",
"+import sys",
"-q = deque(S)",
"-r = 0 # 反転の有無",
"+sys.setrecursionlimit(10**7)",
"+",
"+",
"+def I():",
"+ return int(sys.stdin.readline().rstrip())",
"+",
"+",
"+def MI():",
"+ return list(map(int, sys.stdin.readline().rstrip().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"+",
"+",
"+def LI2():",
"+ return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"+",
"+",
"+def S():",
"+ return sys.stdin.readline().rstrip()",
"+",
"+",
"+def LS():",
"+ return list(sys.stdin.readline().rstrip().split()) # 空白あり",
"+",
"+",
"+def LS2():",
"+ return list(sys.stdin.readline().rstrip()) # 空白なし",
"+",
"+",
"+S = LS2()",
"+r = 0",
"+left, right = [], []",
"+Q = I()",
"- if Query[i][0] == \"1\":",
"+ A = LS()",
"+ if A[0] == \"1\":",
"- if (r + int(Query[i][1])) % 2 == 1:",
"- q.appendleft(Query[i][2])",
"+ f, c = A[1], A[2]",
"+ if (r == 0 and f == \"1\") or (r == 1 and f == \"2\"):",
"+ left.append(c)",
"- q.append(Query[i][2])",
"-A = list(q)",
"-if r % 2 == 1:",
"- A.reverse()",
"-ans = \"\"",
"-for i in range(len(A)):",
"- ans += A[i]",
"-print(ans)",
"+ right.append(c)",
"+if r == 0:",
"+ left.reverse()",
"+ print((\"\".join(left + S + right)))",
"+else:",
"+ S.reverse()",
"+ right.reverse()",
"+ print((\"\".join(right + S + left)))"
] | false | 0.037352 | 0.036807 | 1.014801 |
[
"s104895874",
"s687441326"
] |
u077291787
|
p02787
|
python
|
s290933770
|
s056983444
| 290 | 262 | 39,920 | 39,792 |
Accepted
|
Accepted
| 9.66 |
# E - Crested Ibis vs Monster
def main():
INF = 1 << 30
H, N, *AB = list(map(int, open(0).read().split()))
dp = [INF] * (H + 10001) # dp[i] := min magic points to decrease monster's health by i
dp[0] = 0
for i in range(H):
for a, b in zip(*[iter(AB)] * 2):
dp[i + a] = min(dp[i + a], dp[i] + b)
print((min(dp[H:])))
if __name__ == "__main__":
main()
|
# E - Crested Ibis vs Monster
def main():
INF = 1 << 30
H, N, *AB = list(map(int, open(0).read().split()))
dp = [INF] * (H + 10001) # dp[i] := min magic points to decrease monster's health by i
dp[0] = 0
for a, b in zip(*[iter(AB)] * 2):
for i in range(H):
dp[i + a] = min(dp[i + a], dp[i] + b)
print((min(dp[H:])))
if __name__ == "__main__":
main()
| 15 | 15 | 408 | 408 |
# E - Crested Ibis vs Monster
def main():
INF = 1 << 30
H, N, *AB = list(map(int, open(0).read().split()))
dp = [INF] * (
H + 10001
) # dp[i] := min magic points to decrease monster's health by i
dp[0] = 0
for i in range(H):
for a, b in zip(*[iter(AB)] * 2):
dp[i + a] = min(dp[i + a], dp[i] + b)
print((min(dp[H:])))
if __name__ == "__main__":
main()
|
# E - Crested Ibis vs Monster
def main():
INF = 1 << 30
H, N, *AB = list(map(int, open(0).read().split()))
dp = [INF] * (
H + 10001
) # dp[i] := min magic points to decrease monster's health by i
dp[0] = 0
for a, b in zip(*[iter(AB)] * 2):
for i in range(H):
dp[i + a] = min(dp[i + a], dp[i] + b)
print((min(dp[H:])))
if __name__ == "__main__":
main()
| false | 0 |
[
"- for i in range(H):",
"- for a, b in zip(*[iter(AB)] * 2):",
"+ for a, b in zip(*[iter(AB)] * 2):",
"+ for i in range(H):"
] | false | 0.25389 | 0.088319 | 2.874699 |
[
"s290933770",
"s056983444"
] |
u731368968
|
p02684
|
python
|
s299620802
|
s619246769
| 928 | 126 | 247,748 | 32,376 |
Accepted
|
Accepted
| 86.42 |
N, K = list(map(int, input().split()))
A = [[-1] * (N + 1) for i in range(100)]
A[0] = [0] + list(map(int, input().split()))
# nowから2**i先まで移動したとこ
def double(now, i):
global A
if A[i][now] != -1:
return A[i][now]
# nowから2**(i-1)移動して、そこからさらに2**(i-1)移動する
A[i][now] = double(double(now, i - 1), i - 1)
return A[i][now]
# nowからk移動した場所を求める
def rec(now, k):
if k == 0:
return now
log2k = len(bin(k)) - 3
return rec(double(now, log2k), k - 2 ** log2k)
print((rec(1, K)))
|
n, k = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
# 訪問順
B = [1]
# 訪問済み
C = [False] * (n + 1)
C[1] = True
while True:
B.append(A[B[-1]])
if C[B[-1]]:
break
C[B[-1]] = True
s = B.index(B[-1])
if k < s:
print((B[k]))
exit()
B = B[B.index(B[-1]):-1]
print((B[(k - s) % len(B)]))
| 23 | 25 | 530 | 354 |
N, K = list(map(int, input().split()))
A = [[-1] * (N + 1) for i in range(100)]
A[0] = [0] + list(map(int, input().split()))
# nowから2**i先まで移動したとこ
def double(now, i):
global A
if A[i][now] != -1:
return A[i][now]
# nowから2**(i-1)移動して、そこからさらに2**(i-1)移動する
A[i][now] = double(double(now, i - 1), i - 1)
return A[i][now]
# nowからk移動した場所を求める
def rec(now, k):
if k == 0:
return now
log2k = len(bin(k)) - 3
return rec(double(now, log2k), k - 2**log2k)
print((rec(1, K)))
|
n, k = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
# 訪問順
B = [1]
# 訪問済み
C = [False] * (n + 1)
C[1] = True
while True:
B.append(A[B[-1]])
if C[B[-1]]:
break
C[B[-1]] = True
s = B.index(B[-1])
if k < s:
print((B[k]))
exit()
B = B[B.index(B[-1]) : -1]
print((B[(k - s) % len(B)]))
| false | 8 |
[
"-N, K = list(map(int, input().split()))",
"-A = [[-1] * (N + 1) for i in range(100)]",
"-A[0] = [0] + list(map(int, input().split()))",
"-# nowから2**i先まで移動したとこ",
"-def double(now, i):",
"- global A",
"- if A[i][now] != -1:",
"- return A[i][now]",
"- # nowから2**(i-1)移動して、そこからさらに2**(i-1)移動する",
"- A[i][now] = double(double(now, i - 1), i - 1)",
"- return A[i][now]",
"-",
"-",
"-# nowからk移動した場所を求める",
"-def rec(now, k):",
"- if k == 0:",
"- return now",
"- log2k = len(bin(k)) - 3",
"- return rec(double(now, log2k), k - 2**log2k)",
"-",
"-",
"-print((rec(1, K)))",
"+n, k = list(map(int, input().split()))",
"+A = [0] + list(map(int, input().split()))",
"+# 訪問順",
"+B = [1]",
"+# 訪問済み",
"+C = [False] * (n + 1)",
"+C[1] = True",
"+while True:",
"+ B.append(A[B[-1]])",
"+ if C[B[-1]]:",
"+ break",
"+ C[B[-1]] = True",
"+s = B.index(B[-1])",
"+if k < s:",
"+ print((B[k]))",
"+ exit()",
"+B = B[B.index(B[-1]) : -1]",
"+print((B[(k - s) % len(B)]))"
] | false | 0.085517 | 0.045573 | 1.876492 |
[
"s299620802",
"s619246769"
] |
u761320129
|
p03470
|
python
|
s232024321
|
s184032228
| 227 | 17 | 3,700 | 2,940 |
Accepted
|
Accepted
| 92.51 |
from collections import Counter
N = int(eval(input()))
src = [int(eval(input())) for i in range(N)]
ctr = Counter(src)
print((len(list(ctr.items()))))
|
N = int(eval(input()))
src = [int(eval(input())) for i in range(N)]
print((len(set(src))))
| 5 | 3 | 135 | 78 |
from collections import Counter
N = int(eval(input()))
src = [int(eval(input())) for i in range(N)]
ctr = Counter(src)
print((len(list(ctr.items()))))
|
N = int(eval(input()))
src = [int(eval(input())) for i in range(N)]
print((len(set(src))))
| false | 40 |
[
"-from collections import Counter",
"-",
"-ctr = Counter(src)",
"-print((len(list(ctr.items()))))",
"+print((len(set(src))))"
] | false | 0.034129 | 0.034108 | 1.000611 |
[
"s232024321",
"s184032228"
] |
u497596438
|
p03323
|
python
|
s599637525
|
s966004152
| 188 | 164 | 38,256 | 38,256 |
Accepted
|
Accepted
| 12.77 |
#S=input()
#N=int(input())
A,B=list(map(int,input().split()))
if A<=8 and B<=8:
print("Yay!")
else:
print(":(")
|
A,B=list(map(int,input().split()))
if A<9 and B<9:
print("Yay!")
else:
print(":(")
| 7 | 5 | 119 | 89 |
# S=input()
# N=int(input())
A, B = list(map(int, input().split()))
if A <= 8 and B <= 8:
print("Yay!")
else:
print(":(")
|
A, B = list(map(int, input().split()))
if A < 9 and B < 9:
print("Yay!")
else:
print(":(")
| false | 28.571429 |
[
"-# S=input()",
"-# N=int(input())",
"-if A <= 8 and B <= 8:",
"+if A < 9 and B < 9:"
] | false | 0.043433 | 0.04443 | 0.977561 |
[
"s599637525",
"s966004152"
] |
u257974487
|
p02786
|
python
|
s538547764
|
s673125479
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
hp = int(eval(input()))
if hp == 0:
print((1))
exit()
attack = 0
monster = 1
p = 1
for i in range(999):
if hp == 0:
break
else:
attack += 1
hp = hp // 2
print((2 ** attack - 1))
|
hp = int(eval(input()))
attack = 0
monster = 1
p = 1
for i in range(999):
if hp == 0:
break
else:
attack += 1
hp = hp // 2
print((2 ** attack - 1))
| 17 | 13 | 227 | 186 |
hp = int(eval(input()))
if hp == 0:
print((1))
exit()
attack = 0
monster = 1
p = 1
for i in range(999):
if hp == 0:
break
else:
attack += 1
hp = hp // 2
print((2**attack - 1))
|
hp = int(eval(input()))
attack = 0
monster = 1
p = 1
for i in range(999):
if hp == 0:
break
else:
attack += 1
hp = hp // 2
print((2**attack - 1))
| false | 23.529412 |
[
"-if hp == 0:",
"- print((1))",
"- exit()"
] | false | 0.05115 | 0.050416 | 1.014556 |
[
"s538547764",
"s673125479"
] |
u063596417
|
p03435
|
python
|
s585729244
|
s693429434
| 73 | 64 | 62,212 | 62,104 |
Accepted
|
Accepted
| 12.33 |
c = [[int(cn) for cn in input().split()] for _ in range(3)]
max_val = max(c[0])
ans = 'No'
for a1 in range(max_val + 1):
b = [c[0][i] - a1 for i in range(3)]
correct = True
for i in range(2):
ai_cand = []
for j in range(3):
cand = c[i + 1][j] - b[j]
correct = cand >= 0
if correct:
ai_cand.append(cand)
else:
break
if correct:
correct = ai_cand[0] == ai_cand[1] and ai_cand[1] == ai_cand[2]
if not correct:
break
else:
break
if correct:
ans = 'Yes'
break
print(ans)
|
c = [[int(cn) for cn in input().split()] for _ in range(3)]
max_val = max(c[0])
ans = 'No'
for a1 in range(max_val + 1):
b = [c[0][i] - a1 for i in range(3)]
correct = True
for i in range(2):
ai_cand = []
for j in range(3):
cand = c[i + 1][j] - b[j]
correct = cand >= 0
if correct:
ai_cand.append(cand)
else:
break
correct = correct and (ai_cand[0] == ai_cand[1] and ai_cand[1] == ai_cand[2])
if not correct:
break
if correct:
ans = 'Yes'
break
print(ans)
| 25 | 22 | 588 | 555 |
c = [[int(cn) for cn in input().split()] for _ in range(3)]
max_val = max(c[0])
ans = "No"
for a1 in range(max_val + 1):
b = [c[0][i] - a1 for i in range(3)]
correct = True
for i in range(2):
ai_cand = []
for j in range(3):
cand = c[i + 1][j] - b[j]
correct = cand >= 0
if correct:
ai_cand.append(cand)
else:
break
if correct:
correct = ai_cand[0] == ai_cand[1] and ai_cand[1] == ai_cand[2]
if not correct:
break
else:
break
if correct:
ans = "Yes"
break
print(ans)
|
c = [[int(cn) for cn in input().split()] for _ in range(3)]
max_val = max(c[0])
ans = "No"
for a1 in range(max_val + 1):
b = [c[0][i] - a1 for i in range(3)]
correct = True
for i in range(2):
ai_cand = []
for j in range(3):
cand = c[i + 1][j] - b[j]
correct = cand >= 0
if correct:
ai_cand.append(cand)
else:
break
correct = correct and (ai_cand[0] == ai_cand[1] and ai_cand[1] == ai_cand[2])
if not correct:
break
if correct:
ans = "Yes"
break
print(ans)
| false | 12 |
[
"- if correct:",
"- correct = ai_cand[0] == ai_cand[1] and ai_cand[1] == ai_cand[2]",
"- if not correct:",
"- break",
"- else:",
"+ correct = correct and (ai_cand[0] == ai_cand[1] and ai_cand[1] == ai_cand[2])",
"+ if not correct:"
] | false | 0.036863 | 0.039422 | 0.935091 |
[
"s585729244",
"s693429434"
] |
u223663729
|
p02736
|
python
|
s067979056
|
s565785636
| 423 | 341 | 20,460 | 13,636 |
Accepted
|
Accepted
| 19.39 |
N=int(eval(input()))
A=[int(a)-1 for a in eval(input())]
r=1 if 1 in A else 2
print((sum([1 if A[i]&r and (N-1&i)==i else 0 for i in range(N)])%2*r))
|
N=int(eval(input()));A=[int(a)-1 for a in eval(input())];print((sum([A[i] for i in range(N) if N-1&i==i])%(4>>int(1 in A))))
| 4 | 1 | 138 | 110 |
N = int(eval(input()))
A = [int(a) - 1 for a in eval(input())]
r = 1 if 1 in A else 2
print((sum([1 if A[i] & r and (N - 1 & i) == i else 0 for i in range(N)]) % 2 * r))
|
N = int(eval(input()))
A = [int(a) - 1 for a in eval(input())]
print((sum([A[i] for i in range(N) if N - 1 & i == i]) % (4 >> int(1 in A))))
| false | 75 |
[
"-r = 1 if 1 in A else 2",
"-print((sum([1 if A[i] & r and (N - 1 & i) == i else 0 for i in range(N)]) % 2 * r))",
"+print((sum([A[i] for i in range(N) if N - 1 & i == i]) % (4 >> int(1 in A))))"
] | false | 0.045612 | 0.038333 | 1.189899 |
[
"s067979056",
"s565785636"
] |
u729133443
|
p03260
|
python
|
s506017335
|
s084068909
| 19 | 17 | 3,316 | 2,940 |
Accepted
|
Accepted
| 10.53 |
a,b=list(map(int,input().split()))
if a*b%2:print('Yes')
else:print('No')
|
print(('NYoe s'[eval(input().replace(' ','*'))%2::2]))
| 3 | 1 | 69 | 52 |
a, b = list(map(int, input().split()))
if a * b % 2:
print("Yes")
else:
print("No")
|
print(("NYoe s"[eval(input().replace(" ", "*")) % 2 :: 2]))
| false | 66.666667 |
[
"-a, b = list(map(int, input().split()))",
"-if a * b % 2:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+print((\"NYoe s\"[eval(input().replace(\" \", \"*\")) % 2 :: 2]))"
] | false | 0.059766 | 0.159802 | 0.374002 |
[
"s506017335",
"s084068909"
] |
u623819879
|
p02680
|
python
|
s875143620
|
s331350555
| 2,750 | 2,396 | 551,336 | 551,312 |
Accepted
|
Accepted
| 12.87 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=(f,F),(f,-F),;H=(F,f),(-F,f),
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);V,U,v=[[[0]*-~K for i in r(L+1)]for _ in r(3)]
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]-=1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]-=1
for i in r(L):
for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];a=0
while q:
x,y=q.pop();v[y][x]=1;a+=(s[x]-s[x+1])*(t[y]-t[y+1])
for e,f in(-1,0),(1,0),(0,1),(0,-1),:
c=x+e;d=y+f
if 1-v[d][c]and U[(f>0)+y][x]*f+V[y][(e>0)+x]*e==0:q+=[(c,d)];v[d][c]=1
print(([a,'INF'][a>F]))
|
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=(f,F),(f,-F),;H=(F,f),(-F,f),
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=sorted(set(X));l=len(s);return{s[i]:i for i in r(l)},s,l
h,s,K=g(X);w,t,L=g(Y);V,U,v=[[[0]*-~K for i in r(L+1)]for _ in r(3)]
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]-=1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]-=1
for i in r(L):
for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];a=0
while q:
x,y=q.pop();v[y][x]=1;a+=(s[x]-s[x+1])*(t[y]-t[y+1])
for e,f in(-1,0),(1,0),(0,1),(0,-1),:
c=x+e;d=y+f
if 1-v[d][c]and U[(f>0)+y][x]*f+V[y][(e>0)+x]*e==0:q+=[(c,d)];v[d][c]=1
print(([a,'INF'][a>F]))
| 16 | 16 | 762 | 752 |
I = lambda: list(map(int, input().split()))
F = 1e21
r = range
n, m = I()
f = [-F, F]
X = [0] + f
Y = X[:]
R = (
(f, F),
(f, -F),
)
H = (
(F, f),
(-F, f),
)
for i in r(n):
*a, c = I()
R += ((a, c),)
Y += (c,)
X += a
for i in r(m):
a, *b = I()
H += ((a, b),)
X += (a,)
Y += b
def g(X):
s = dict(enumerate(sorted(set(X))))
return {s[i]: i for i in s}, s, len(s)
h, s, K = g(X)
w, t, L = g(Y)
V, U, v = [[[0] * -~K for i in r(L + 1)] for _ in r(3)]
for (a, b), c in R:
U[w[c]][h[a]] += 1
U[w[c]][h[b]] -= 1
for d, (e, f) in H:
V[w[e]][h[d]] += 1
V[w[f]][h[d]] -= 1
for i in r(L):
for j in r(K):
U[i][j + 1] += U[i][j]
V[i + 1][j] += V[i][j]
q = [(h[0], w[0])]
a = 0
while q:
x, y = q.pop()
v[y][x] = 1
a += (s[x] - s[x + 1]) * (t[y] - t[y + 1])
for e, f in (
(-1, 0),
(1, 0),
(0, 1),
(0, -1),
):
c = x + e
d = y + f
if 1 - v[d][c] and U[(f > 0) + y][x] * f + V[y][(e > 0) + x] * e == 0:
q += [(c, d)]
v[d][c] = 1
print(([a, "INF"][a > F]))
|
I = lambda: list(map(int, input().split()))
F = 1e21
r = range
n, m = I()
f = [-F, F]
X = [0] + f
Y = X[:]
R = (
(f, F),
(f, -F),
)
H = (
(F, f),
(-F, f),
)
for i in r(n):
*a, c = I()
R += ((a, c),)
Y += (c,)
X += a
for i in r(m):
a, *b = I()
H += ((a, b),)
X += (a,)
Y += b
def g(X):
s = sorted(set(X))
l = len(s)
return {s[i]: i for i in r(l)}, s, l
h, s, K = g(X)
w, t, L = g(Y)
V, U, v = [[[0] * -~K for i in r(L + 1)] for _ in r(3)]
for (a, b), c in R:
U[w[c]][h[a]] += 1
U[w[c]][h[b]] -= 1
for d, (e, f) in H:
V[w[e]][h[d]] += 1
V[w[f]][h[d]] -= 1
for i in r(L):
for j in r(K):
U[i][j + 1] += U[i][j]
V[i + 1][j] += V[i][j]
q = [(h[0], w[0])]
a = 0
while q:
x, y = q.pop()
v[y][x] = 1
a += (s[x] - s[x + 1]) * (t[y] - t[y + 1])
for e, f in (
(-1, 0),
(1, 0),
(0, 1),
(0, -1),
):
c = x + e
d = y + f
if 1 - v[d][c] and U[(f > 0) + y][x] * f + V[y][(e > 0) + x] * e == 0:
q += [(c, d)]
v[d][c] = 1
print(([a, "INF"][a > F]))
| false | 0 |
[
"- s = dict(enumerate(sorted(set(X))))",
"- return {s[i]: i for i in s}, s, len(s)",
"+ s = sorted(set(X))",
"+ l = len(s)",
"+ return {s[i]: i for i in r(l)}, s, l"
] | false | 0.099636 | 0.037967 | 2.624258 |
[
"s875143620",
"s331350555"
] |
u678167152
|
p02713
|
python
|
s829124913
|
s413590096
| 187 | 59 | 67,764 | 64,608 |
Accepted
|
Accepted
| 68.45 |
import math
k = int(eval(input()))
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
m = math.gcd(a, b)
for c in range(1, k+1):
ans += math.gcd(m, c)
print(ans)
|
K = int(eval(input()))
from math import gcd
sum_gcd = [0]*K
for i in range(1,K+1):
c = 0
for j in range(1,K+1):
c += gcd(i,j)
sum_gcd[i-1] = c
ans = 0
for a in range(1,K+1):
for b in range(1,K+1):
ans += sum_gcd[gcd(a,b)-1]
print(ans)
| 11 | 15 | 197 | 276 |
import math
k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
m = math.gcd(a, b)
for c in range(1, k + 1):
ans += math.gcd(m, c)
print(ans)
|
K = int(eval(input()))
from math import gcd
sum_gcd = [0] * K
for i in range(1, K + 1):
c = 0
for j in range(1, K + 1):
c += gcd(i, j)
sum_gcd[i - 1] = c
ans = 0
for a in range(1, K + 1):
for b in range(1, K + 1):
ans += sum_gcd[gcd(a, b) - 1]
print(ans)
| false | 26.666667 |
[
"-import math",
"+K = int(eval(input()))",
"+from math import gcd",
"-k = int(eval(input()))",
"+sum_gcd = [0] * K",
"+for i in range(1, K + 1):",
"+ c = 0",
"+ for j in range(1, K + 1):",
"+ c += gcd(i, j)",
"+ sum_gcd[i - 1] = c",
"-for a in range(1, k + 1):",
"- for b in range(1, k + 1):",
"- m = math.gcd(a, b)",
"- for c in range(1, k + 1):",
"- ans += math.gcd(m, c)",
"+for a in range(1, K + 1):",
"+ for b in range(1, K + 1):",
"+ ans += sum_gcd[gcd(a, b) - 1]"
] | false | 0.115075 | 0.08135 | 1.41457 |
[
"s829124913",
"s413590096"
] |
u703950586
|
p03215
|
python
|
s752977760
|
s960190386
| 510 | 396 | 71,544 | 67,832 |
Accepted
|
Accepted
| 22.35 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N,K = LI()
A = LI()
sa = list(itertools.accumulate([0]+A))
b = []
for i in range(N):
for j in range(i+1,N+1):
b.append(sa[j]-sa[i])
b.sort(reverse=True)
max_b = (max(b)).bit_length()
mask = 0
for i in range(max_b-1,-1,-1):
bit = 2**i
cnt = 0
for x in b:
if x & mask == mask:
cnt += (x & bit > 0)
if cnt >= K:
mask += bit
print (mask)
|
import sys,queue,math,copy,itertools,bisect,collections,heapq
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,K = LI()
A = LI()
sa = list(itertools.accumulate([0]+A))
b = []
for i in range(N):
for j in range(i+1,N+1):
b.append(sa[j]-sa[i])
#b.sort(reverse=True)
max_b = max(b).bit_length()
mask = 0
for i in range(max_b-1,-1,-1):
bit = 2**i
cnt = 0
for x in b:
if x & mask == mask:
cnt += (x & bit > 0)
if cnt >= K:
mask += bit
print (mask)
| 32 | 24 | 712 | 537 |
import sys, queue, math, copy, itertools, bisect, collections, heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda: [int(x) for x in sys.stdin.readline().split()]
_LI = lambda: [int(x) - 1 for x in sys.stdin.readline().split()]
NI = lambda: int(sys.stdin.readline())
N, K = LI()
A = LI()
sa = list(itertools.accumulate([0] + A))
b = []
for i in range(N):
for j in range(i + 1, N + 1):
b.append(sa[j] - sa[i])
b.sort(reverse=True)
max_b = (max(b)).bit_length()
mask = 0
for i in range(max_b - 1, -1, -1):
bit = 2**i
cnt = 0
for x in b:
if x & mask == mask:
cnt += x & bit > 0
if cnt >= K:
mask += bit
print(mask)
|
import sys, queue, math, copy, itertools, bisect, collections, heapq
LI = lambda: [int(x) for x in sys.stdin.readline().split()]
N, K = LI()
A = LI()
sa = list(itertools.accumulate([0] + A))
b = []
for i in range(N):
for j in range(i + 1, N + 1):
b.append(sa[j] - sa[i])
# b.sort(reverse=True)
max_b = max(b).bit_length()
mask = 0
for i in range(max_b - 1, -1, -1):
bit = 2**i
cnt = 0
for x in b:
if x & mask == mask:
cnt += x & bit > 0
if cnt >= K:
mask += bit
print(mask)
| false | 25 |
[
"-sys.setrecursionlimit(10**7)",
"-INF = 10**18",
"-MOD = 10**9 + 7",
"-_LI = lambda: [int(x) - 1 for x in sys.stdin.readline().split()]",
"-NI = lambda: int(sys.stdin.readline())",
"-b.sort(reverse=True)",
"-max_b = (max(b)).bit_length()",
"+# b.sort(reverse=True)",
"+max_b = max(b).bit_length()"
] | false | 0.036025 | 0.036841 | 0.977867 |
[
"s752977760",
"s960190386"
] |
u340781749
|
p02816
|
python
|
s115987911
|
s580558628
| 1,788 | 394 | 143,284 | 66,896 |
Accepted
|
Accepted
| 77.96 |
def check(ccc, ddd, e, ans):
m = 2147483647
g = 1000000007
for l in range(e):
cl = ccc[l]
if any(c != cl for c in ccc[l::e]):
return
dl = ddd[l]
if any(d != dl for d in ddd[l::e]):
return
s = 0
for c in ccc[:e]:
s = (s * g + c) % m
t = 0
for d in ddd[:e]:
t = (t * g + d) % m
u = pow(g, e, m)
for h in range(e):
if s == t:
bh = bbb[h]
ans.update(((i - h) % n, aaa[i] ^ bh) for i in range(0, n, e))
return
t = (t * g + ddd[(e + h) % n] - ddd[h] * u) % m
def solve(n, aaa, bbb):
ccc = [a1 ^ a2 for a1, a2 in zip(aaa, aaa[1:])] + [aaa[-1] ^ aaa[0]]
ddd = [b1 ^ b2 for b1, b2 in zip(bbb, bbb[1:])] + [bbb[-1] ^ bbb[0]]
ans = set()
e = 1
while e * e <= n:
if n % e != 0:
e += 1
continue
check(ccc, ddd, e, ans)
check(ccc, ddd, n // e, ans)
e += 1
return ans
n = int(eval(input()))
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ans = solve(n, aaa, bbb)
print((''.join('{} {}\n'.format(*answer) for answer in sorted(ans))))
|
def solve(n, aaa, bbb):
ccc = [a1 ^ a2 for a1, a2 in zip(aaa, aaa[1:])] + [aaa[-1] ^ aaa[0]]
ddd = [b1 ^ b2 for b1, b2 in zip(bbb, bbb[1:])] + [bbb[-1] ^ bbb[0]]
ans = []
m = 2147483647
g = 1000000007
s = 0
for c in ccc:
s = (s * g + c) % m
t = 0
for d in ddd:
t = (t * g + d) % m
u = pow(g, n, m) - 1
for i in range(n):
if s == t:
ans.append((i, aaa[i] ^ bbb[0]))
s = (s * g - ccc[i] * u) % m
ans.sort()
return ans
n = int(eval(input()))
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ans = solve(n, aaa, bbb)
print((''.join('{} {}\n'.format(*answer) for answer in ans)))
| 48 | 28 | 1,233 | 721 |
def check(ccc, ddd, e, ans):
m = 2147483647
g = 1000000007
for l in range(e):
cl = ccc[l]
if any(c != cl for c in ccc[l::e]):
return
dl = ddd[l]
if any(d != dl for d in ddd[l::e]):
return
s = 0
for c in ccc[:e]:
s = (s * g + c) % m
t = 0
for d in ddd[:e]:
t = (t * g + d) % m
u = pow(g, e, m)
for h in range(e):
if s == t:
bh = bbb[h]
ans.update(((i - h) % n, aaa[i] ^ bh) for i in range(0, n, e))
return
t = (t * g + ddd[(e + h) % n] - ddd[h] * u) % m
def solve(n, aaa, bbb):
ccc = [a1 ^ a2 for a1, a2 in zip(aaa, aaa[1:])] + [aaa[-1] ^ aaa[0]]
ddd = [b1 ^ b2 for b1, b2 in zip(bbb, bbb[1:])] + [bbb[-1] ^ bbb[0]]
ans = set()
e = 1
while e * e <= n:
if n % e != 0:
e += 1
continue
check(ccc, ddd, e, ans)
check(ccc, ddd, n // e, ans)
e += 1
return ans
n = int(eval(input()))
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ans = solve(n, aaa, bbb)
print(("".join("{} {}\n".format(*answer) for answer in sorted(ans))))
|
def solve(n, aaa, bbb):
ccc = [a1 ^ a2 for a1, a2 in zip(aaa, aaa[1:])] + [aaa[-1] ^ aaa[0]]
ddd = [b1 ^ b2 for b1, b2 in zip(bbb, bbb[1:])] + [bbb[-1] ^ bbb[0]]
ans = []
m = 2147483647
g = 1000000007
s = 0
for c in ccc:
s = (s * g + c) % m
t = 0
for d in ddd:
t = (t * g + d) % m
u = pow(g, n, m) - 1
for i in range(n):
if s == t:
ans.append((i, aaa[i] ^ bbb[0]))
s = (s * g - ccc[i] * u) % m
ans.sort()
return ans
n = int(eval(input()))
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ans = solve(n, aaa, bbb)
print(("".join("{} {}\n".format(*answer) for answer in ans)))
| false | 41.666667 |
[
"-def check(ccc, ddd, e, ans):",
"- m = 2147483647",
"- g = 1000000007",
"- for l in range(e):",
"- cl = ccc[l]",
"- if any(c != cl for c in ccc[l::e]):",
"- return",
"- dl = ddd[l]",
"- if any(d != dl for d in ddd[l::e]):",
"- return",
"- s = 0",
"- for c in ccc[:e]:",
"- s = (s * g + c) % m",
"- t = 0",
"- for d in ddd[:e]:",
"- t = (t * g + d) % m",
"- u = pow(g, e, m)",
"- for h in range(e):",
"- if s == t:",
"- bh = bbb[h]",
"- ans.update(((i - h) % n, aaa[i] ^ bh) for i in range(0, n, e))",
"- return",
"- t = (t * g + ddd[(e + h) % n] - ddd[h] * u) % m",
"-",
"-",
"- ans = set()",
"- e = 1",
"- while e * e <= n:",
"- if n % e != 0:",
"- e += 1",
"- continue",
"- check(ccc, ddd, e, ans)",
"- check(ccc, ddd, n // e, ans)",
"- e += 1",
"+ ans = []",
"+ m = 2147483647",
"+ g = 1000000007",
"+ s = 0",
"+ for c in ccc:",
"+ s = (s * g + c) % m",
"+ t = 0",
"+ for d in ddd:",
"+ t = (t * g + d) % m",
"+ u = pow(g, n, m) - 1",
"+ for i in range(n):",
"+ if s == t:",
"+ ans.append((i, aaa[i] ^ bbb[0]))",
"+ s = (s * g - ccc[i] * u) % m",
"+ ans.sort()",
"-print((\"\".join(\"{} {}\\n\".format(*answer) for answer in sorted(ans))))",
"+print((\"\".join(\"{} {}\\n\".format(*answer) for answer in ans)))"
] | false | 0.037658 | 0.036677 | 1.026745 |
[
"s115987911",
"s580558628"
] |
u155174554
|
p03416
|
python
|
s975037188
|
s432884768
| 58 | 47 | 3,060 | 3,060 |
Accepted
|
Accepted
| 18.97 |
a, b = list(map(int, input().split()))
nums = [x for x in range(a, b+1) if str(x)[0] == str(x)[-1] and str(x)[1] == str(x)[-2]]
print((len(nums)))
|
a, b = list(map(int, input().split()))
nums = []
for i in range(a, b+1):
str_i = str(i)
if str_i[0] == str_i[-1] and str_i[1] == str_i[-2]:
nums.append(i)
print((len(nums)))
| 4 | 10 | 142 | 193 |
a, b = list(map(int, input().split()))
nums = [
x for x in range(a, b + 1) if str(x)[0] == str(x)[-1] and str(x)[1] == str(x)[-2]
]
print((len(nums)))
|
a, b = list(map(int, input().split()))
nums = []
for i in range(a, b + 1):
str_i = str(i)
if str_i[0] == str_i[-1] and str_i[1] == str_i[-2]:
nums.append(i)
print((len(nums)))
| false | 60 |
[
"-nums = [",
"- x for x in range(a, b + 1) if str(x)[0] == str(x)[-1] and str(x)[1] == str(x)[-2]",
"-]",
"+nums = []",
"+for i in range(a, b + 1):",
"+ str_i = str(i)",
"+ if str_i[0] == str_i[-1] and str_i[1] == str_i[-2]:",
"+ nums.append(i)"
] | false | 0.063486 | 0.063821 | 0.994758 |
[
"s975037188",
"s432884768"
] |
u252828980
|
p02912
|
python
|
s195610984
|
s687396075
| 195 | 157 | 14,224 | 14,180 |
Accepted
|
Accepted
| 19.49 |
a,b = list(map(int,input().split()))
li = [-int(x) for x in input().split()]
import heapq
heapq.heapify(li)
for i in range(b):
c = heapq.heappop(li)
heapq.heappush(li,c/2)
li = [int(x) for x in li]
print((-sum(li)))
|
import heapq
a,b = list(map(int,input().split()))
L = list(map(int,input().split()))
L = [-x for x in L]
heapq.heapify(L)
for i in range(b):
a =heapq.heappop(L)
a= -(-a//2)
heapq.heappush(L,a)
L = [-x for x in L]
print((sum(L)))
| 9 | 13 | 223 | 246 |
a, b = list(map(int, input().split()))
li = [-int(x) for x in input().split()]
import heapq
heapq.heapify(li)
for i in range(b):
c = heapq.heappop(li)
heapq.heappush(li, c / 2)
li = [int(x) for x in li]
print((-sum(li)))
|
import heapq
a, b = list(map(int, input().split()))
L = list(map(int, input().split()))
L = [-x for x in L]
heapq.heapify(L)
for i in range(b):
a = heapq.heappop(L)
a = -(-a // 2)
heapq.heappush(L, a)
L = [-x for x in L]
print((sum(L)))
| false | 30.769231 |
[
"-a, b = list(map(int, input().split()))",
"-li = [-int(x) for x in input().split()]",
"-heapq.heapify(li)",
"+a, b = list(map(int, input().split()))",
"+L = list(map(int, input().split()))",
"+L = [-x for x in L]",
"+heapq.heapify(L)",
"- c = heapq.heappop(li)",
"- heapq.heappush(li, c / 2)",
"-li = [int(x) for x in li]",
"-print((-sum(li)))",
"+ a = heapq.heappop(L)",
"+ a = -(-a // 2)",
"+ heapq.heappush(L, a)",
"+L = [-x for x in L]",
"+print((sum(L)))"
] | false | 0.040655 | 0.073796 | 0.550913 |
[
"s195610984",
"s687396075"
] |
u863370423
|
p03556
|
python
|
s298743328
|
s010592081
| 61 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 72.13 |
import math
def is_integer(n):
try:
float(n)
except ValueError:
return False
else:
return float(n).is_integer()
l = int(eval(input()))
if is_integer(math.sqrt(l)):
print(l)
else:
for i in range(l):
l=l-1
if is_integer(math.sqrt(l)):
print(l)
break
|
import math
n=float(eval(input()))
m=math.floor(math.sqrt(n))
print((m*m))
| 19 | 4 | 346 | 69 |
import math
def is_integer(n):
try:
float(n)
except ValueError:
return False
else:
return float(n).is_integer()
l = int(eval(input()))
if is_integer(math.sqrt(l)):
print(l)
else:
for i in range(l):
l = l - 1
if is_integer(math.sqrt(l)):
print(l)
break
|
import math
n = float(eval(input()))
m = math.floor(math.sqrt(n))
print((m * m))
| false | 78.947368 |
[
"-",
"-def is_integer(n):",
"- try:",
"- float(n)",
"- except ValueError:",
"- return False",
"- else:",
"- return float(n).is_integer()",
"-",
"-",
"-l = int(eval(input()))",
"-if is_integer(math.sqrt(l)):",
"- print(l)",
"-else:",
"- for i in range(l):",
"- l = l - 1",
"- if is_integer(math.sqrt(l)):",
"- print(l)",
"- break",
"+n = float(eval(input()))",
"+m = math.floor(math.sqrt(n))",
"+print((m * m))"
] | false | 0.058423 | 0.040842 | 1.430486 |
[
"s298743328",
"s010592081"
] |
u102461423
|
p02564
|
python
|
s283862779
|
s953986878
| 2,189 | 1,384 | 176,816 | 178,436 |
Accepted
|
Accepted
| 36.77 |
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8, i8[:, :], i8[:], i8[:], i8[:], i8[:], i8[:], i8, i8, i8, i8),
cache=True)
def scc_dfs(N, G, idx, low, ord, ids, visited, now_ord, group_num, vis_i, v):
low[v] = ord[v] = now_ord
now_ord += 1
visited[vis_i], vis_i = v, vis_i + 1
for e in range(idx[v], idx[v + 1]):
to = G[e, 1]
if ord[to] == -1:
now_ord, group_num, vis_i = \
scc_dfs(N, G, idx, low, ord, ids,
visited, now_ord, group_num,
vis_i, to)
low[v] = min(low[v], low[to])
else:
low[v] = min(low[v], ord[to])
if low[v] == ord[v]:
while True:
u, vis_i = visited[vis_i - 1], vis_i - 1
ord[u] = N
ids[u] = group_num
if u == v:
break
group_num += 1
return now_ord, group_num, vis_i
@njit((i8, i8[:, :]), cache=True)
def scc(N, G):
idx = np.searchsorted(G[:, 0], np.arange(N + 1))
low = np.zeros(N, np.int64)
ord = np.zeros(N, np.int64) - 1
now_ord = 0
group_num = 0
visited, vis_i = np.empty(N, np.int64), 0
ids = np.zeros(N, np.int64)
for v in range(N):
if ord[v] == -1:
now_ord, group_num, vis_i = \
scc_dfs(N, G, idx, low, ord, ids,
visited, now_ord, group_num,
vis_i, v)
return group_num, group_num - ids - 1
def main(N, G):
n_comp, comp = scc(N, G)
ans = np.empty((N, 2), np.int64)
ans[:, 0] = np.arange(N)
ans[:, 1] = comp
ans = ans[np.argsort(ans[:, 1])]
idx = np.searchsorted(ans[:, 1], np.arange(n_comp + 1))
print(n_comp)
for c in range(n_comp):
V = ans[idx[c]:idx[c + 1], 0]
print(len(V), ' '.join(map(str, V)))
N, M = map(int, readline().split())
AB = np.array(read().split(), np.int64).reshape(-1, 2)
AB = AB[np.argsort(AB[:, 0])]
main(N, AB)
|
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8, i8[:, :], i8[:], i8[:], i8[:], i8[:], i8[:], i8, i8, i8, i8),
cache=True)
def scc_dfs(N, G, idx, low, ord, ids, visited, now_ord, group_num, vis_i, v):
low[v] = ord[v] = now_ord
now_ord += 1
visited[vis_i], vis_i = v, vis_i + 1
for e in range(idx[v], idx[v + 1]):
to = G[e, 1]
if ord[to] == -1:
now_ord, group_num, vis_i = \
scc_dfs(N, G, idx, low, ord, ids,
visited, now_ord, group_num,
vis_i, to)
low[v] = min(low[v], low[to])
else:
low[v] = min(low[v], ord[to])
if low[v] == ord[v]:
while True:
u, vis_i = visited[vis_i - 1], vis_i - 1
ord[u] = N
ids[u] = group_num
if u == v:
break
group_num += 1
return now_ord, group_num, vis_i
@njit((i8, i8[:, :]), cache=True)
def scc(N, G):
idx = np.searchsorted(G[:, 0], np.arange(N + 1))
low = np.zeros(N, np.int64)
ord = np.zeros(N, np.int64) - 1
now_ord = 0
group_num = 0
visited, vis_i = np.empty(N, np.int64), 0
ids = np.zeros(N, np.int64)
for v in range(N):
if ord[v] == -1:
now_ord, group_num, vis_i = \
scc_dfs(N, G, idx, low, ord, ids,
visited, now_ord, group_num,
vis_i, v)
return group_num, group_num - ids - 1
@njit((i8, i8[:, :]), cache=True)
def main(N, G):
n_comp, comp = scc(N, G)
ans = np.empty((N, 2), np.int64)
ans[:, 0] = np.arange(N)
ans[:, 1] = comp
ans = ans[np.argsort(ans[:, 1])]
idx = np.searchsorted(ans[:, 1], np.arange(n_comp + 1))
print(n_comp)
for c in range(n_comp):
V = ans[idx[c]:idx[c + 1], 0]
print(len(V))
for v in V:
print(v)
N, M = map(int, readline().split())
AB = np.array(read().split(), np.int64).reshape(-1, 2)
AB = AB[np.argsort(AB[:, 0])]
main(N, AB)
| 71 | 74 | 2,185 | 2,240 |
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8, i8[:, :], i8[:], i8[:], i8[:], i8[:], i8[:], i8, i8, i8, i8), cache=True)
def scc_dfs(N, G, idx, low, ord, ids, visited, now_ord, group_num, vis_i, v):
low[v] = ord[v] = now_ord
now_ord += 1
visited[vis_i], vis_i = v, vis_i + 1
for e in range(idx[v], idx[v + 1]):
to = G[e, 1]
if ord[to] == -1:
now_ord, group_num, vis_i = scc_dfs(
N, G, idx, low, ord, ids, visited, now_ord, group_num, vis_i, to
)
low[v] = min(low[v], low[to])
else:
low[v] = min(low[v], ord[to])
if low[v] == ord[v]:
while True:
u, vis_i = visited[vis_i - 1], vis_i - 1
ord[u] = N
ids[u] = group_num
if u == v:
break
group_num += 1
return now_ord, group_num, vis_i
@njit((i8, i8[:, :]), cache=True)
def scc(N, G):
idx = np.searchsorted(G[:, 0], np.arange(N + 1))
low = np.zeros(N, np.int64)
ord = np.zeros(N, np.int64) - 1
now_ord = 0
group_num = 0
visited, vis_i = np.empty(N, np.int64), 0
ids = np.zeros(N, np.int64)
for v in range(N):
if ord[v] == -1:
now_ord, group_num, vis_i = scc_dfs(
N, G, idx, low, ord, ids, visited, now_ord, group_num, vis_i, v
)
return group_num, group_num - ids - 1
def main(N, G):
n_comp, comp = scc(N, G)
ans = np.empty((N, 2), np.int64)
ans[:, 0] = np.arange(N)
ans[:, 1] = comp
ans = ans[np.argsort(ans[:, 1])]
idx = np.searchsorted(ans[:, 1], np.arange(n_comp + 1))
print(n_comp)
for c in range(n_comp):
V = ans[idx[c] : idx[c + 1], 0]
print(len(V), " ".join(map(str, V)))
N, M = map(int, readline().split())
AB = np.array(read().split(), np.int64).reshape(-1, 2)
AB = AB[np.argsort(AB[:, 0])]
main(N, AB)
|
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8, i8[:, :], i8[:], i8[:], i8[:], i8[:], i8[:], i8, i8, i8, i8), cache=True)
def scc_dfs(N, G, idx, low, ord, ids, visited, now_ord, group_num, vis_i, v):
low[v] = ord[v] = now_ord
now_ord += 1
visited[vis_i], vis_i = v, vis_i + 1
for e in range(idx[v], idx[v + 1]):
to = G[e, 1]
if ord[to] == -1:
now_ord, group_num, vis_i = scc_dfs(
N, G, idx, low, ord, ids, visited, now_ord, group_num, vis_i, to
)
low[v] = min(low[v], low[to])
else:
low[v] = min(low[v], ord[to])
if low[v] == ord[v]:
while True:
u, vis_i = visited[vis_i - 1], vis_i - 1
ord[u] = N
ids[u] = group_num
if u == v:
break
group_num += 1
return now_ord, group_num, vis_i
@njit((i8, i8[:, :]), cache=True)
def scc(N, G):
idx = np.searchsorted(G[:, 0], np.arange(N + 1))
low = np.zeros(N, np.int64)
ord = np.zeros(N, np.int64) - 1
now_ord = 0
group_num = 0
visited, vis_i = np.empty(N, np.int64), 0
ids = np.zeros(N, np.int64)
for v in range(N):
if ord[v] == -1:
now_ord, group_num, vis_i = scc_dfs(
N, G, idx, low, ord, ids, visited, now_ord, group_num, vis_i, v
)
return group_num, group_num - ids - 1
@njit((i8, i8[:, :]), cache=True)
def main(N, G):
n_comp, comp = scc(N, G)
ans = np.empty((N, 2), np.int64)
ans[:, 0] = np.arange(N)
ans[:, 1] = comp
ans = ans[np.argsort(ans[:, 1])]
idx = np.searchsorted(ans[:, 1], np.arange(n_comp + 1))
print(n_comp)
for c in range(n_comp):
V = ans[idx[c] : idx[c + 1], 0]
print(len(V))
for v in V:
print(v)
N, M = map(int, readline().split())
AB = np.array(read().split(), np.int64).reshape(-1, 2)
AB = AB[np.argsort(AB[:, 0])]
main(N, AB)
| false | 4.054054 |
[
"+@njit((i8, i8[:, :]), cache=True)",
"- print(len(V), \" \".join(map(str, V)))",
"+ print(len(V))",
"+ for v in V:",
"+ print(v)"
] | false | 0.042071 | 0.036369 | 1.156804 |
[
"s283862779",
"s953986878"
] |
u010075034
|
p03999
|
python
|
s991955257
|
s013726627
| 53 | 44 | 3,064 | 3,188 |
Accepted
|
Accepted
| 16.98 |
import itertools
def spl(s, t):
lst = list(s)
for x in reversed(t):
lst.insert(x, '+')
return eval(''.join(lst))
def main():
nums = eval(input())
length = len(nums)
total = 0
for i in range(length):
for ts in itertools.combinations(list(range(1, length)), i):
total += spl(nums, ts)
print(total)
if __name__ == '__main__':
main()
|
import itertools
def split(xs, t):
total = 0
tmp = []
for i, x in enumerate(xs):
if i in t:
total += int(''.join(tmp))
tmp = [x]
else:
tmp.append(x)
if tmp:
total += int(''.join(tmp))
return total
def main():
nums = list(eval(input()))
length = len(nums)
total = 0
for i in range(length):
for t in itertools.combinations(list(range(1, length)), i):
total += split(nums, t)
print(total)
if __name__ == '__main__':
main()
| 20 | 27 | 405 | 562 |
import itertools
def spl(s, t):
lst = list(s)
for x in reversed(t):
lst.insert(x, "+")
return eval("".join(lst))
def main():
nums = eval(input())
length = len(nums)
total = 0
for i in range(length):
for ts in itertools.combinations(list(range(1, length)), i):
total += spl(nums, ts)
print(total)
if __name__ == "__main__":
main()
|
import itertools
def split(xs, t):
total = 0
tmp = []
for i, x in enumerate(xs):
if i in t:
total += int("".join(tmp))
tmp = [x]
else:
tmp.append(x)
if tmp:
total += int("".join(tmp))
return total
def main():
nums = list(eval(input()))
length = len(nums)
total = 0
for i in range(length):
for t in itertools.combinations(list(range(1, length)), i):
total += split(nums, t)
print(total)
if __name__ == "__main__":
main()
| false | 25.925926 |
[
"-def spl(s, t):",
"- lst = list(s)",
"- for x in reversed(t):",
"- lst.insert(x, \"+\")",
"- return eval(\"\".join(lst))",
"+def split(xs, t):",
"+ total = 0",
"+ tmp = []",
"+ for i, x in enumerate(xs):",
"+ if i in t:",
"+ total += int(\"\".join(tmp))",
"+ tmp = [x]",
"+ else:",
"+ tmp.append(x)",
"+ if tmp:",
"+ total += int(\"\".join(tmp))",
"+ return total",
"- nums = eval(input())",
"+ nums = list(eval(input()))",
"- for ts in itertools.combinations(list(range(1, length)), i):",
"- total += spl(nums, ts)",
"+ for t in itertools.combinations(list(range(1, length)), i):",
"+ total += split(nums, t)"
] | false | 0.037112 | 0.080273 | 0.462322 |
[
"s991955257",
"s013726627"
] |
u652068981
|
p02639
|
python
|
s599345635
|
s073921341
| 30 | 26 | 9,084 | 9,084 |
Accepted
|
Accepted
| 13.33 |
x=list(map(int,input().split()))
print((x.index(0)+1))
|
print((input().find('0')//2+1))
| 2 | 1 | 54 | 29 |
x = list(map(int, input().split()))
print((x.index(0) + 1))
|
print((input().find("0") // 2 + 1))
| false | 50 |
[
"-x = list(map(int, input().split()))",
"-print((x.index(0) + 1))",
"+print((input().find(\"0\") // 2 + 1))"
] | false | 0.040665 | 0.0428 | 0.950131 |
[
"s599345635",
"s073921341"
] |
u198905553
|
p02959
|
python
|
s731977205
|
s667845933
| 292 | 268 | 82,020 | 82,148 |
Accepted
|
Accepted
| 8.22 |
n = int(eval(input()))
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
result = 0
for i in range(n):
if a[i] > b[i]:
result += b[i]
a[i] -= b[i]
b[i] = 0
else:
result += a[i]
b[i] -= a[i]
a[i] = 0
if a[i + 1] > b[i]:
result += b[i]
a[i + 1] -= b[i]
b[i] = 0
else:
result += a[i + 1]
b[i] -= a[i + 1]
a[i + 1] = 0
print(result)
|
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
result = 0
for i in range(N):
if B[i] >= A[i]:
result += A[i]
B[i] -= A[i]
A[i] = 0
if B[i] >= A[i+1]:
result += A[i+1]
B[i] -= A[i+1]
A[i+1] = 0
else:
result += B[i]
A[i+1] -= B[i]
B[i] = 0
else:
result += B[i]
A[i] -= B[i]
B[i] = 0
print(result)
| 22 | 28 | 441 | 533 |
n = int(eval(input()))
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
result = 0
for i in range(n):
if a[i] > b[i]:
result += b[i]
a[i] -= b[i]
b[i] = 0
else:
result += a[i]
b[i] -= a[i]
a[i] = 0
if a[i + 1] > b[i]:
result += b[i]
a[i + 1] -= b[i]
b[i] = 0
else:
result += a[i + 1]
b[i] -= a[i + 1]
a[i + 1] = 0
print(result)
|
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
result = 0
for i in range(N):
if B[i] >= A[i]:
result += A[i]
B[i] -= A[i]
A[i] = 0
if B[i] >= A[i + 1]:
result += A[i + 1]
B[i] -= A[i + 1]
A[i + 1] = 0
else:
result += B[i]
A[i + 1] -= B[i]
B[i] = 0
else:
result += B[i]
A[i] -= B[i]
B[i] = 0
print(result)
| false | 21.428571 |
[
"-n = int(eval(input()))",
"-a = [int(e) for e in input().split()]",
"-b = [int(e) for e in input().split()]",
"+N = int(eval(input()))",
"+A = list(map(int, input().split()))",
"+B = list(map(int, input().split()))",
"-for i in range(n):",
"- if a[i] > b[i]:",
"- result += b[i]",
"- a[i] -= b[i]",
"- b[i] = 0",
"+for i in range(N):",
"+ if B[i] >= A[i]:",
"+ result += A[i]",
"+ B[i] -= A[i]",
"+ A[i] = 0",
"+ if B[i] >= A[i + 1]:",
"+ result += A[i + 1]",
"+ B[i] -= A[i + 1]",
"+ A[i + 1] = 0",
"+ else:",
"+ result += B[i]",
"+ A[i + 1] -= B[i]",
"+ B[i] = 0",
"- result += a[i]",
"- b[i] -= a[i]",
"- a[i] = 0",
"- if a[i + 1] > b[i]:",
"- result += b[i]",
"- a[i + 1] -= b[i]",
"- b[i] = 0",
"- else:",
"- result += a[i + 1]",
"- b[i] -= a[i + 1]",
"- a[i + 1] = 0",
"+ result += B[i]",
"+ A[i] -= B[i]",
"+ B[i] = 0"
] | false | 0.050075 | 0.050017 | 1.001163 |
[
"s731977205",
"s667845933"
] |
u905582793
|
p03854
|
python
|
s729500994
|
s036727974
| 73 | 24 | 3,244 | 6,516 |
Accepted
|
Accepted
| 67.12 |
s=input()[::-1]
for i in range(10**5):
if s[:5]=="maerd":
s=s[5:]
elif s[:7]=="remaerd":
s=s[7:]
elif s[:5]=="esare":
s=s[5:]
elif s[:6]=="resare":
s=s[6:]
elif s=="":
print("YES")
break
else:
print("NO")
break
|
import re
s = eval(input())
if re.fullmatch(r"(dream|dreamer|erase|eraser)+",s):
print("YES")
else:
print("NO")
| 16 | 6 | 269 | 114 |
s = input()[::-1]
for i in range(10**5):
if s[:5] == "maerd":
s = s[5:]
elif s[:7] == "remaerd":
s = s[7:]
elif s[:5] == "esare":
s = s[5:]
elif s[:6] == "resare":
s = s[6:]
elif s == "":
print("YES")
break
else:
print("NO")
break
|
import re
s = eval(input())
if re.fullmatch(r"(dream|dreamer|erase|eraser)+", s):
print("YES")
else:
print("NO")
| false | 62.5 |
[
"-s = input()[::-1]",
"-for i in range(10**5):",
"- if s[:5] == \"maerd\":",
"- s = s[5:]",
"- elif s[:7] == \"remaerd\":",
"- s = s[7:]",
"- elif s[:5] == \"esare\":",
"- s = s[5:]",
"- elif s[:6] == \"resare\":",
"- s = s[6:]",
"- elif s == \"\":",
"- print(\"YES\")",
"- break",
"- else:",
"- print(\"NO\")",
"- break",
"+import re",
"+",
"+s = eval(input())",
"+if re.fullmatch(r\"(dream|dreamer|erase|eraser)+\", s):",
"+ print(\"YES\")",
"+else:",
"+ print(\"NO\")"
] | false | 0.045005 | 0.041107 | 1.094837 |
[
"s729500994",
"s036727974"
] |
u607865971
|
p02928
|
python
|
s273274490
|
s856545813
| 1,480 | 796 | 3,952 | 3,316 |
Accepted
|
Accepted
| 46.22 |
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint
# 10倍速いらしい
input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)
# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
T1 = [0] * N
T2 = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
if A[i] > A[j]:
T1[i] += 1
for i in range(N):
for j in range(0, N):
if A[i] > A[j]:
T2[i] += 1
ans = sum(T1) * K
ans %= MOD
ans += sum(T2) * K * (K - 1) // 2
ans %= MOD
print(ans)
# print(T1)
# print(T2)
|
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
z = 0
for i in range(N-1):
for j in range(i+1, N):
if A[i] > A[j]:
z += 1
y = 0
for a1 in A:
for a2 in A:
if a1 > a2:
y+=1
mod = 10**9 + 7
ans = z * (K) + y * (K) * (K-1)//2
print((ans % mod))
| 47 | 21 | 1,096 | 344 |
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint
# 10倍速いらしい
input = sys.stdin.readline
INF = float("inf")
MOD = 10**9 + 7
EPS = 10**-7
sys.setrecursionlimit(1000000)
# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
T1 = [0] * N
T2 = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
if A[i] > A[j]:
T1[i] += 1
for i in range(N):
for j in range(0, N):
if A[i] > A[j]:
T2[i] += 1
ans = sum(T1) * K
ans %= MOD
ans += sum(T2) * K * (K - 1) // 2
ans %= MOD
print(ans)
# print(T1)
# print(T2)
|
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
z = 0
for i in range(N - 1):
for j in range(i + 1, N):
if A[i] > A[j]:
z += 1
y = 0
for a1 in A:
for a2 in A:
if a1 > a2:
y += 1
mod = 10**9 + 7
ans = z * (K) + y * (K) * (K - 1) // 2
print((ans % mod))
| false | 55.319149 |
[
"-import sys, math, itertools, bisect, copy, re",
"-from collections import Counter, deque, defaultdict",
"-from itertools import accumulate, permutations, combinations, takewhile, compress, cycle",
"-from functools import reduce",
"-from math import ceil, floor, log10, log2, factorial",
"-from pprint import pprint",
"-",
"-# 10倍速いらしい",
"-input = sys.stdin.readline",
"-INF = float(\"inf\")",
"-MOD = 10**9 + 7",
"-EPS = 10**-7",
"-sys.setrecursionlimit(1000000)",
"-# N = int(input())",
"-# N,M = [int(x) for x in input().split()]",
"-# V = [[0] * 100 for _ in range(100)]",
"-# A = [int(input()) for _ in range(N)]",
"-# DP = [[0] * 100 for _ in range(100)]",
"-# DP = defaultdict(lambda: float('inf'))",
"-T1 = [0] * N",
"-T2 = [0] * N",
"+z = 0",
"- T1[i] += 1",
"-for i in range(N):",
"- for j in range(0, N):",
"- if A[i] > A[j]:",
"- T2[i] += 1",
"-ans = sum(T1) * K",
"-ans %= MOD",
"-ans += sum(T2) * K * (K - 1) // 2",
"-ans %= MOD",
"-print(ans)",
"-# print(T1)",
"-# print(T2)",
"+ z += 1",
"+y = 0",
"+for a1 in A:",
"+ for a2 in A:",
"+ if a1 > a2:",
"+ y += 1",
"+mod = 10**9 + 7",
"+ans = z * (K) + y * (K) * (K - 1) // 2",
"+print((ans % mod))"
] | false | 0.052695 | 0.036038 | 1.462223 |
[
"s273274490",
"s856545813"
] |
u620084012
|
p02779
|
python
|
s892860524
|
s282748522
| 325 | 264 | 88,916 | 91,268 |
Accepted
|
Accepted
| 18.77 |
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
for k in range(1,N):
if A[k-1] == A[k]:
print("NO")
exit(0)
print("YES")
|
N = int(eval(input()))
A = set(input().split())
if len(A) == N:
print("YES")
else:
print("NO")
| 7 | 6 | 159 | 102 |
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
for k in range(1, N):
if A[k - 1] == A[k]:
print("NO")
exit(0)
print("YES")
|
N = int(eval(input()))
A = set(input().split())
if len(A) == N:
print("YES")
else:
print("NO")
| false | 14.285714 |
[
"-A = sorted(list(map(int, input().split())))",
"-for k in range(1, N):",
"- if A[k - 1] == A[k]:",
"- print(\"NO\")",
"- exit(0)",
"-print(\"YES\")",
"+A = set(input().split())",
"+if len(A) == N:",
"+ print(\"YES\")",
"+else:",
"+ print(\"NO\")"
] | false | 0.098492 | 0.125451 | 0.7851 |
[
"s892860524",
"s282748522"
] |
u671060652
|
p02682
|
python
|
s040725866
|
s544086068
| 486 | 133 | 72,644 | 72,736 |
Accepted
|
Accepted
| 72.63 |
import itertools
import math
import fractions
import functools
a, b,c, k = list(map(int, input().split()))
sum = 0
if k <= a:
sum = k
print(sum)
quit()
elif k > a:
sum += a
k = k - a
if k <= b:
print(sum)
quit()
elif k > b:
k = k - b
sum -= k * 1
print(sum)
|
import itertools
import math
import fractions
import functools
a, b, c, k = list(map(int, input().split()))
sum = 0
if k <= a:
print(k)
quit()
else:
sum = a
k -= a
if k <= b:
print(sum)
quit()
else:
k -= b
print((sum-k))
| 25 | 19 | 317 | 260 |
import itertools
import math
import fractions
import functools
a, b, c, k = list(map(int, input().split()))
sum = 0
if k <= a:
sum = k
print(sum)
quit()
elif k > a:
sum += a
k = k - a
if k <= b:
print(sum)
quit()
elif k > b:
k = k - b
sum -= k * 1
print(sum)
|
import itertools
import math
import fractions
import functools
a, b, c, k = list(map(int, input().split()))
sum = 0
if k <= a:
print(k)
quit()
else:
sum = a
k -= a
if k <= b:
print(sum)
quit()
else:
k -= b
print((sum - k))
| false | 24 |
[
"- sum = k",
"- print(sum)",
"+ print(k)",
"-elif k > a:",
"- sum += a",
"- k = k - a",
"+else:",
"+ sum = a",
"+ k -= a",
"-elif k > b:",
"- k = k - b",
"- sum -= k * 1",
"-print(sum)",
"+else:",
"+ k -= b",
"+print((sum - k))"
] | false | 0.036805 | 0.147558 | 0.24943 |
[
"s040725866",
"s544086068"
] |
u912237403
|
p02388
|
python
|
s530181313
|
s869782243
| 20 | 10 | 4,192 | 4,196 |
Accepted
|
Accepted
| 50 |
import sys
for x in sys.stdin:
print(int(x)**3)
|
for x in map(int, input().split()):
print(int(x)**3)
| 3 | 2 | 52 | 60 |
import sys
for x in sys.stdin:
print(int(x) ** 3)
|
for x in map(int, input().split()):
print(int(x) ** 3)
| false | 33.333333 |
[
"-import sys",
"-",
"-for x in sys.stdin:",
"+for x in map(int, input().split()):"
] | false | 0.037278 | 0.040645 | 0.917146 |
[
"s530181313",
"s869782243"
] |
u638902622
|
p02720
|
python
|
s789434759
|
s815270101
| 183 | 120 | 17,004 | 19,680 |
Accepted
|
Accepted
| 34.43 |
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque
def main():
K = int(eval(input()))
cnt = 0
dq = deque(['1','2','3','4','5','6','7','8','9'])
while cnt < K:
cnt += 1
d = dq.popleft()
a = int(d[-1])
if a == 0:
dq.append(d+str(0))
dq.append(d+str(1))
elif a == 9:
dq.append(d+str(8))
dq.append(d+str(9))
else:
for i in range(a-1, a+2):
dq.append(d+str(i))
print(d)
if __name__ == '__main__':
main()
|
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque
def main():
K = int(eval(input()))
# cnt = 0
# dq = deque(['1','2','3','4','5','6','7','8','9'])
# while cnt < K:
# cnt += 1
# d = dq.popleft()
# a = int(d[-1])
# if a == 0:
# dq.append(d+str(0))
# dq.append(d+str(1))
# elif a == 9:
# dq.append(d+str(8))
# dq.append(d+str(9))
# else:
# for i in range(a-1, a+2):
# dq.append(d+str(i))
# print(d)
runrun_lst = []
def rec(num_of_digit, runrun_val):
runrun_lst.append(runrun_val)
if num_of_digit == 10: return
for i in range(-1, 2):
add = (runrun_val%10) + i
if 0 <= add <= 9: rec(num_of_digit+1, runrun_val*10+add)
for v in range(1, 10):
rec(1, v)
runrun_lst.sort()
print((runrun_lst[K-1]))
if __name__ == '__main__':
main()
| 28 | 39 | 661 | 1,070 |
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque
def main():
K = int(eval(input()))
cnt = 0
dq = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
while cnt < K:
cnt += 1
d = dq.popleft()
a = int(d[-1])
if a == 0:
dq.append(d + str(0))
dq.append(d + str(1))
elif a == 9:
dq.append(d + str(8))
dq.append(d + str(9))
else:
for i in range(a - 1, a + 2):
dq.append(d + str(i))
print(d)
if __name__ == "__main__":
main()
|
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque
def main():
K = int(eval(input()))
# cnt = 0
# dq = deque(['1','2','3','4','5','6','7','8','9'])
# while cnt < K:
# cnt += 1
# d = dq.popleft()
# a = int(d[-1])
# if a == 0:
# dq.append(d+str(0))
# dq.append(d+str(1))
# elif a == 9:
# dq.append(d+str(8))
# dq.append(d+str(9))
# else:
# for i in range(a-1, a+2):
# dq.append(d+str(i))
# print(d)
runrun_lst = []
def rec(num_of_digit, runrun_val):
runrun_lst.append(runrun_val)
if num_of_digit == 10:
return
for i in range(-1, 2):
add = (runrun_val % 10) + i
if 0 <= add <= 9:
rec(num_of_digit + 1, runrun_val * 10 + add)
for v in range(1, 10):
rec(1, v)
runrun_lst.sort()
print((runrun_lst[K - 1]))
if __name__ == "__main__":
main()
| false | 28.205128 |
[
"- cnt = 0",
"- dq = deque([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"])",
"- while cnt < K:",
"- cnt += 1",
"- d = dq.popleft()",
"- a = int(d[-1])",
"- if a == 0:",
"- dq.append(d + str(0))",
"- dq.append(d + str(1))",
"- elif a == 9:",
"- dq.append(d + str(8))",
"- dq.append(d + str(9))",
"- else:",
"- for i in range(a - 1, a + 2):",
"- dq.append(d + str(i))",
"- print(d)",
"+ # cnt = 0",
"+ # dq = deque(['1','2','3','4','5','6','7','8','9'])",
"+ # while cnt < K:",
"+ # cnt += 1",
"+ # d = dq.popleft()",
"+ # a = int(d[-1])",
"+ # if a == 0:",
"+ # dq.append(d+str(0))",
"+ # dq.append(d+str(1))",
"+ # elif a == 9:",
"+ # dq.append(d+str(8))",
"+ # dq.append(d+str(9))",
"+ # else:",
"+ # for i in range(a-1, a+2):",
"+ # dq.append(d+str(i))",
"+ # print(d)",
"+ runrun_lst = []",
"+",
"+ def rec(num_of_digit, runrun_val):",
"+ runrun_lst.append(runrun_val)",
"+ if num_of_digit == 10:",
"+ return",
"+ for i in range(-1, 2):",
"+ add = (runrun_val % 10) + i",
"+ if 0 <= add <= 9:",
"+ rec(num_of_digit + 1, runrun_val * 10 + add)",
"+",
"+ for v in range(1, 10):",
"+ rec(1, v)",
"+ runrun_lst.sort()",
"+ print((runrun_lst[K - 1]))"
] | false | 0.062693 | 0.295466 | 0.212185 |
[
"s789434759",
"s815270101"
] |
u526603504
|
p03716
|
python
|
s033223243
|
s452953224
| 784 | 703 | 120,392 | 119,976 |
Accepted
|
Accepted
| 10.33 |
from collections import deque
from heapq import heapify, heappop as pop, heappush as push
N = int(eval(input()))
a = list(map(int, input().split()))
l = a[:N]
m = deque(a[N:N*2])
r = [x * -1 for x in a[N*2:]] # 中身は負
heapify(l)
heapify(r)
ll = [sum(l)]
for em in m:
l_min = pop(l)
if l_min < em:
ll.append(ll[-1] - l_min + em)
push(l, em)
else:
ll.append(ll[-1])
push(l, l_min)
rr = [sum(r)] # 中身は負
for em in reversed(m):
r_max = pop(r) * -1
if r_max > em:
rr.append(rr[-1] + r_max - em)
push(r, em * -1)
else:
rr.append(rr[-1])
push(r, r_max * -1)
print((max(a + b for a, b in zip(ll, reversed(rr)))))
|
from heapq import heapify, heappop as pop, heappush as push
N = int(eval(input()))
a = list(map(int, input().split()))
l = a[:N]
m = a[N:N*2]
r = [x * -1 for x in a[N*2:]] # 中身は負
heapify(l)
heapify(r)
ll = [sum(l)]
for em in m:
l_min = pop(l)
if l_min < em:
ll.append(ll[-1] - l_min + em)
push(l, em)
else:
ll.append(ll[-1])
push(l, l_min)
rr = [sum(r)] # 中身は負
for em in reversed(m):
r_max = pop(r) * -1
if r_max > em:
rr.append(rr[-1] + r_max - em)
push(r, em * -1)
else:
rr.append(rr[-1])
push(r, r_max * -1)
print((max(a + b for a, b in zip(ll, reversed(rr)))))
| 34 | 33 | 720 | 683 |
from collections import deque
from heapq import heapify, heappop as pop, heappush as push
N = int(eval(input()))
a = list(map(int, input().split()))
l = a[:N]
m = deque(a[N : N * 2])
r = [x * -1 for x in a[N * 2 :]] # 中身は負
heapify(l)
heapify(r)
ll = [sum(l)]
for em in m:
l_min = pop(l)
if l_min < em:
ll.append(ll[-1] - l_min + em)
push(l, em)
else:
ll.append(ll[-1])
push(l, l_min)
rr = [sum(r)] # 中身は負
for em in reversed(m):
r_max = pop(r) * -1
if r_max > em:
rr.append(rr[-1] + r_max - em)
push(r, em * -1)
else:
rr.append(rr[-1])
push(r, r_max * -1)
print((max(a + b for a, b in zip(ll, reversed(rr)))))
|
from heapq import heapify, heappop as pop, heappush as push
N = int(eval(input()))
a = list(map(int, input().split()))
l = a[:N]
m = a[N : N * 2]
r = [x * -1 for x in a[N * 2 :]] # 中身は負
heapify(l)
heapify(r)
ll = [sum(l)]
for em in m:
l_min = pop(l)
if l_min < em:
ll.append(ll[-1] - l_min + em)
push(l, em)
else:
ll.append(ll[-1])
push(l, l_min)
rr = [sum(r)] # 中身は負
for em in reversed(m):
r_max = pop(r) * -1
if r_max > em:
rr.append(rr[-1] + r_max - em)
push(r, em * -1)
else:
rr.append(rr[-1])
push(r, r_max * -1)
print((max(a + b for a, b in zip(ll, reversed(rr)))))
| false | 2.941176 |
[
"-from collections import deque",
"-m = deque(a[N : N * 2])",
"+m = a[N : N * 2]"
] | false | 0.040579 | 0.041709 | 0.972898 |
[
"s033223243",
"s452953224"
] |
u711539583
|
p03045
|
python
|
s187197085
|
s657177330
| 1,790 | 829 | 71,268 | 67,120 |
Accepted
|
Accepted
| 53.69 |
import sys
from collections import deque
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
memo = set(list(range(n)))
E = [[] for i in range(n)]
for i in range(m):
x, y, z = list(map(int, input().split()))
E[x-1].append(y-1)
E[y-1].append(x-1)
def dfs(cur, pre):
stack = deque([[cur, pre]])
while stack:
cur, pre = stack.pop()
memo.discard(cur)
for e in E[cur]:
if e != pre and e in memo:
stack.append([e, cur])
ans = 0
for i in range(n):
if i in memo:
dfs(i, -1)
ans += 1
print(ans)
|
import sys
from collections import deque
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
memo = [1 for _ in range(n)]
E = [[] for _ in range(n)]
for i in range(m):
x, y, z = list(map(int, input().split()))
E[x-1].append(y-1)
E[y-1].append(x-1)
def dfs(cur, pre):
stack = deque([[cur, pre]])
while stack:
cur, pre = stack.pop()
memo[cur] = 0
for e in E[cur]:
if e != pre and memo[e]:
stack.append([e, cur])
ans = 0
for i in range(n):
if memo[i]:
dfs(i, -1)
ans += 1
print(ans)
| 25 | 25 | 633 | 627 |
import sys
from collections import deque
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
memo = set(list(range(n)))
E = [[] for i in range(n)]
for i in range(m):
x, y, z = list(map(int, input().split()))
E[x - 1].append(y - 1)
E[y - 1].append(x - 1)
def dfs(cur, pre):
stack = deque([[cur, pre]])
while stack:
cur, pre = stack.pop()
memo.discard(cur)
for e in E[cur]:
if e != pre and e in memo:
stack.append([e, cur])
ans = 0
for i in range(n):
if i in memo:
dfs(i, -1)
ans += 1
print(ans)
|
import sys
from collections import deque
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
memo = [1 for _ in range(n)]
E = [[] for _ in range(n)]
for i in range(m):
x, y, z = list(map(int, input().split()))
E[x - 1].append(y - 1)
E[y - 1].append(x - 1)
def dfs(cur, pre):
stack = deque([[cur, pre]])
while stack:
cur, pre = stack.pop()
memo[cur] = 0
for e in E[cur]:
if e != pre and memo[e]:
stack.append([e, cur])
ans = 0
for i in range(n):
if memo[i]:
dfs(i, -1)
ans += 1
print(ans)
| false | 0 |
[
"-memo = set(list(range(n)))",
"-E = [[] for i in range(n)]",
"+memo = [1 for _ in range(n)]",
"+E = [[] for _ in range(n)]",
"- memo.discard(cur)",
"+ memo[cur] = 0",
"- if e != pre and e in memo:",
"+ if e != pre and memo[e]:",
"- if i in memo:",
"+ if memo[i]:"
] | false | 0.072525 | 0.052073 | 1.392759 |
[
"s187197085",
"s657177330"
] |
u303059352
|
p03807
|
python
|
s712496264
|
s179005021
| 51 | 40 | 14,108 | 11,104 |
Accepted
|
Accepted
| 21.57 |
eval(input());print((["YES","NO"][sum([1 if i%2 else 0 for i in list(map(int,input().split()))])%2]))
|
eval(input());print((["YES","NO"][sum(map(int,input().split()))%2]))
| 1 | 1 | 93 | 60 |
eval(input())
print(
(
["YES", "NO"][
sum([1 if i % 2 else 0 for i in list(map(int, input().split()))]) % 2
]
)
)
|
eval(input())
print((["YES", "NO"][sum(map(int, input().split())) % 2]))
| false | 0 |
[
"-print(",
"- (",
"- [\"YES\", \"NO\"][",
"- sum([1 if i % 2 else 0 for i in list(map(int, input().split()))]) % 2",
"- ]",
"- )",
"-)",
"+print(([\"YES\", \"NO\"][sum(map(int, input().split())) % 2]))"
] | false | 0.036681 | 0.037253 | 0.984665 |
[
"s712496264",
"s179005021"
] |
u503228842
|
p03837
|
python
|
s902427927
|
s523025346
| 503 | 293 | 48,604 | 48,300 |
Accepted
|
Accepted
| 41.75 |
N,M = list(map(int,input().split()))
inf = float('inf')
D = [[inf]*N for _ in range(N)]
for i in range(N):
D[i][i] = 0
edges = []
for _ in range(M):
a,b,c = list(map(int,input().split()))
a -= 1
b -= 1
D[a][b] = c
D[b][a] = c
edges.append([a,b,c])
for k in range(N):
for i in range(N):
for j in range(N):
D[i][j] = min(D[i][j],D[i][k] + D[k][j])
# for i in range(N):
# print(D[i])
ans = 0
for e in edges:
used = False
for s in range(N):
for t in range(N):
if D[s][e[0]] + e[2] + D[e[1]][t] == D[s][t]:
used = True
if not used:
ans += 1
print(ans)
|
N,M = list(map(int,input().split()))
inf = float('inf')
D = [[inf]*N for _ in range(N)]
for i in range(N):
D[i][i] = 0
edges = []
for _ in range(M):
a,b,c = list(map(int,input().split()))
a -= 1
b -= 1
D[a][b] = c
D[b][a] = c
edges.append([a,b,c])
for k in range(N):
for i in range(N):
for j in range(N):
D[i][j] = min(D[i][j],D[i][k] + D[k][j])
# for i in range(N):
# print(D[i])
ans = 0
for e in edges:
used = False
for s in range(N):
if D[s][e[0]] + e[2] == D[s][e[1]]:
used = True
if not used:
ans += 1
print(ans)
| 31 | 30 | 684 | 638 |
N, M = list(map(int, input().split()))
inf = float("inf")
D = [[inf] * N for _ in range(N)]
for i in range(N):
D[i][i] = 0
edges = []
for _ in range(M):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
D[a][b] = c
D[b][a] = c
edges.append([a, b, c])
for k in range(N):
for i in range(N):
for j in range(N):
D[i][j] = min(D[i][j], D[i][k] + D[k][j])
# for i in range(N):
# print(D[i])
ans = 0
for e in edges:
used = False
for s in range(N):
for t in range(N):
if D[s][e[0]] + e[2] + D[e[1]][t] == D[s][t]:
used = True
if not used:
ans += 1
print(ans)
|
N, M = list(map(int, input().split()))
inf = float("inf")
D = [[inf] * N for _ in range(N)]
for i in range(N):
D[i][i] = 0
edges = []
for _ in range(M):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
D[a][b] = c
D[b][a] = c
edges.append([a, b, c])
for k in range(N):
for i in range(N):
for j in range(N):
D[i][j] = min(D[i][j], D[i][k] + D[k][j])
# for i in range(N):
# print(D[i])
ans = 0
for e in edges:
used = False
for s in range(N):
if D[s][e[0]] + e[2] == D[s][e[1]]:
used = True
if not used:
ans += 1
print(ans)
| false | 3.225806 |
[
"- for t in range(N):",
"- if D[s][e[0]] + e[2] + D[e[1]][t] == D[s][t]:",
"- used = True",
"+ if D[s][e[0]] + e[2] == D[s][e[1]]:",
"+ used = True"
] | false | 0.043326 | 0.035912 | 1.20644 |
[
"s902427927",
"s523025346"
] |
u227082700
|
p03200
|
python
|
s505594169
|
s301994495
| 98 | 70 | 3,500 | 3,500 |
Accepted
|
Accepted
| 28.57 |
a,s,b=0,eval(input()),0
for i in range(len(s)):a+=i*(s[i]=="W");b+=(s[i]=="W")
print((a-((b*(b-1))//2)))
|
a,s,b=0,eval(input()),0
for i in range(len(s)):
if s[i]=="W":a+=i;b+=1
print((a-((b*(b-1))//2)))
| 3 | 4 | 98 | 93 |
a, s, b = 0, eval(input()), 0
for i in range(len(s)):
a += i * (s[i] == "W")
b += s[i] == "W"
print((a - ((b * (b - 1)) // 2)))
|
a, s, b = 0, eval(input()), 0
for i in range(len(s)):
if s[i] == "W":
a += i
b += 1
print((a - ((b * (b - 1)) // 2)))
| false | 25 |
[
"- a += i * (s[i] == \"W\")",
"- b += s[i] == \"W\"",
"+ if s[i] == \"W\":",
"+ a += i",
"+ b += 1"
] | false | 0.03474 | 0.035629 | 0.975047 |
[
"s505594169",
"s301994495"
] |
u046158516
|
p02586
|
python
|
s872839076
|
s654179988
| 1,805 | 840 | 468,416 | 439,788 |
Accepted
|
Accepted
| 53.46 |
import os,io
import sys
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
r,c,k=list(map(int,input().split()))
dp = [[[0 for y in range(c)] for z in range(r)] for P in range(4)]
m=[]
for i in range(r):
m.append([])
for j in range(c):
m[i].append(0)
for i in range(k):
ri,ci,v=list(map(int,input().split()))
m[ri-1][ci-1]=v
dp[0][0][0]=0
dp[1][0][0]=m[0][0]
dp[2][0][0]=m[0][0]
dp[3][0][0]=m[0][0]
for i in range(r):
for j in range(c):
if j+1<c:
dp[0][i][j+1]=max(dp[0][i][j+1],dp[0][i][j])
dp[1][i][j+1]=max(dp[1][i][j],max(dp[1][i][j+1],dp[0][i][j]+m[i][j+1]))
dp[2][i][j+1]=max(dp[2][i][j],max(dp[2][i][j+1],dp[1][i][j]+m[i][j+1]))
dp[3][i][j+1]=max(dp[3][i][j],max(dp[3][i][j+1],dp[2][i][j]+m[i][j+1]))
if i+1<r:
dp[0][i+1][j]=dp[3][i][j]
dp[1][i+1][j]=dp[3][i][j]+m[i+1][j]
dp[2][i+1][j]=dp[3][i][j]+m[i+1][j]
dp[3][i+1][j]=dp[3][i][j]+m[i+1][j]
print((dp[3][r-1][c-1]))
|
import os,io
import sys
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
r,c,k=list(map(int,input().split()))
dp = [0]*(r*c*4)
m=[]
for i in range(r):
m.append([])
for j in range(c):
m[i].append(0)
for i in range(k):
ri,ci,v=list(map(int,input().split()))
m[ri-1][ci-1]=v
dp[0*r*c+0*c+0]=0
dp[1*r*c+0*c+0]=m[0][0]
dp[2*r*c+0*c+0]=m[0][0]
dp[3*r*c+0*c+0]=m[0][0]
for i in range(r):
for j in range(c):
if j+1<c:
dp[0*r*c+i*c+j+1]=max(dp[0*r*c+i*c+j+1],dp[0*r*c+i*c+j])
dp[1*r*c+i*c+j+1]=max(dp[1*r*c+i*c+j],max(dp[1*r*c+i*c+j+1],dp[0*r*c+i*c+j]+m[i][j+1]))
dp[2*r*c+i*c+j+1]=max(dp[2*r*c+i*c+j],max(dp[2*r*c+i*c+j+1],dp[1*r*c+i*c+j]+m[i][j+1]))
dp[3*r*c+i*c+j+1]=max(dp[3*r*c+i*c+j],max(dp[3*r*c+i*c+j+1],dp[2*r*c+i*c+j]+m[i][j+1]))
if i+1<r:
dp[0*r*c+(i+1)*c+j]=dp[3*r*c+i*c+j]
dp[1*r*c+(i+1)*c+j]=dp[3*r*c+i*c+j]+m[i+1][j]
dp[2*r*c+(i+1)*c+j]=dp[3*r*c+i*c+j]+m[i+1][j]
dp[3*r*c+(i+1)*c+j]=dp[3*r*c+i*c+j]+m[i+1][j]
print((dp[3*r*c+(r-1)*c+c-1]))
| 31 | 31 | 973 | 1,045 |
import os, io
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
r, c, k = list(map(int, input().split()))
dp = [[[0 for y in range(c)] for z in range(r)] for P in range(4)]
m = []
for i in range(r):
m.append([])
for j in range(c):
m[i].append(0)
for i in range(k):
ri, ci, v = list(map(int, input().split()))
m[ri - 1][ci - 1] = v
dp[0][0][0] = 0
dp[1][0][0] = m[0][0]
dp[2][0][0] = m[0][0]
dp[3][0][0] = m[0][0]
for i in range(r):
for j in range(c):
if j + 1 < c:
dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j])
dp[1][i][j + 1] = max(
dp[1][i][j], max(dp[1][i][j + 1], dp[0][i][j] + m[i][j + 1])
)
dp[2][i][j + 1] = max(
dp[2][i][j], max(dp[2][i][j + 1], dp[1][i][j] + m[i][j + 1])
)
dp[3][i][j + 1] = max(
dp[3][i][j], max(dp[3][i][j + 1], dp[2][i][j] + m[i][j + 1])
)
if i + 1 < r:
dp[0][i + 1][j] = dp[3][i][j]
dp[1][i + 1][j] = dp[3][i][j] + m[i + 1][j]
dp[2][i + 1][j] = dp[3][i][j] + m[i + 1][j]
dp[3][i + 1][j] = dp[3][i][j] + m[i + 1][j]
print((dp[3][r - 1][c - 1]))
|
import os, io
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
r, c, k = list(map(int, input().split()))
dp = [0] * (r * c * 4)
m = []
for i in range(r):
m.append([])
for j in range(c):
m[i].append(0)
for i in range(k):
ri, ci, v = list(map(int, input().split()))
m[ri - 1][ci - 1] = v
dp[0 * r * c + 0 * c + 0] = 0
dp[1 * r * c + 0 * c + 0] = m[0][0]
dp[2 * r * c + 0 * c + 0] = m[0][0]
dp[3 * r * c + 0 * c + 0] = m[0][0]
for i in range(r):
for j in range(c):
if j + 1 < c:
dp[0 * r * c + i * c + j + 1] = max(
dp[0 * r * c + i * c + j + 1], dp[0 * r * c + i * c + j]
)
dp[1 * r * c + i * c + j + 1] = max(
dp[1 * r * c + i * c + j],
max(
dp[1 * r * c + i * c + j + 1],
dp[0 * r * c + i * c + j] + m[i][j + 1],
),
)
dp[2 * r * c + i * c + j + 1] = max(
dp[2 * r * c + i * c + j],
max(
dp[2 * r * c + i * c + j + 1],
dp[1 * r * c + i * c + j] + m[i][j + 1],
),
)
dp[3 * r * c + i * c + j + 1] = max(
dp[3 * r * c + i * c + j],
max(
dp[3 * r * c + i * c + j + 1],
dp[2 * r * c + i * c + j] + m[i][j + 1],
),
)
if i + 1 < r:
dp[0 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j]
dp[1 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]
dp[2 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]
dp[3 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]
print((dp[3 * r * c + (r - 1) * c + c - 1]))
| false | 0 |
[
"-dp = [[[0 for y in range(c)] for z in range(r)] for P in range(4)]",
"+dp = [0] * (r * c * 4)",
"-dp[0][0][0] = 0",
"-dp[1][0][0] = m[0][0]",
"-dp[2][0][0] = m[0][0]",
"-dp[3][0][0] = m[0][0]",
"+dp[0 * r * c + 0 * c + 0] = 0",
"+dp[1 * r * c + 0 * c + 0] = m[0][0]",
"+dp[2 * r * c + 0 * c + 0] = m[0][0]",
"+dp[3 * r * c + 0 * c + 0] = m[0][0]",
"- dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j])",
"- dp[1][i][j + 1] = max(",
"- dp[1][i][j], max(dp[1][i][j + 1], dp[0][i][j] + m[i][j + 1])",
"+ dp[0 * r * c + i * c + j + 1] = max(",
"+ dp[0 * r * c + i * c + j + 1], dp[0 * r * c + i * c + j]",
"- dp[2][i][j + 1] = max(",
"- dp[2][i][j], max(dp[2][i][j + 1], dp[1][i][j] + m[i][j + 1])",
"+ dp[1 * r * c + i * c + j + 1] = max(",
"+ dp[1 * r * c + i * c + j],",
"+ max(",
"+ dp[1 * r * c + i * c + j + 1],",
"+ dp[0 * r * c + i * c + j] + m[i][j + 1],",
"+ ),",
"- dp[3][i][j + 1] = max(",
"- dp[3][i][j], max(dp[3][i][j + 1], dp[2][i][j] + m[i][j + 1])",
"+ dp[2 * r * c + i * c + j + 1] = max(",
"+ dp[2 * r * c + i * c + j],",
"+ max(",
"+ dp[2 * r * c + i * c + j + 1],",
"+ dp[1 * r * c + i * c + j] + m[i][j + 1],",
"+ ),",
"+ )",
"+ dp[3 * r * c + i * c + j + 1] = max(",
"+ dp[3 * r * c + i * c + j],",
"+ max(",
"+ dp[3 * r * c + i * c + j + 1],",
"+ dp[2 * r * c + i * c + j] + m[i][j + 1],",
"+ ),",
"- dp[0][i + 1][j] = dp[3][i][j]",
"- dp[1][i + 1][j] = dp[3][i][j] + m[i + 1][j]",
"- dp[2][i + 1][j] = dp[3][i][j] + m[i + 1][j]",
"- dp[3][i + 1][j] = dp[3][i][j] + m[i + 1][j]",
"-print((dp[3][r - 1][c - 1]))",
"+ dp[0 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j]",
"+ dp[1 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]",
"+ dp[2 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]",
"+ dp[3 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]",
"+print((dp[3 * r * c + (r - 1) * c + c - 1]))"
] | false | 0.035562 | 0.036865 | 0.964642 |
[
"s872839076",
"s654179988"
] |
u133886644
|
p03325
|
python
|
s297140437
|
s476125966
| 142 | 79 | 4,084 | 4,084 |
Accepted
|
Accepted
| 44.37 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
L = [int(v) for v in input().split()]
ans = 0
for v in L:
c = 0
while v % (2 ** (c + 1)) == 0:
c += 1
ans += c
print(ans)
|
import sys
input = sys.stdin.readline
N, = list(map(int, input().split()))
L = [int(v) for v in input().split()]
ans = 0
for v in L:
while v % 2 == 0:
ans += 1
v = v // 2
print(ans)
| 15 | 12 | 214 | 208 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
L = [int(v) for v in input().split()]
ans = 0
for v in L:
c = 0
while v % (2 ** (c + 1)) == 0:
c += 1
ans += c
print(ans)
|
import sys
input = sys.stdin.readline
(N,) = list(map(int, input().split()))
L = [int(v) for v in input().split()]
ans = 0
for v in L:
while v % 2 == 0:
ans += 1
v = v // 2
print(ans)
| false | 20 |
[
"-N = int(eval(input()))",
"+(N,) = list(map(int, input().split()))",
"- c = 0",
"- while v % (2 ** (c + 1)) == 0:",
"- c += 1",
"- ans += c",
"+ while v % 2 == 0:",
"+ ans += 1",
"+ v = v // 2"
] | false | 0.04761 | 0.041849 | 1.137646 |
[
"s297140437",
"s476125966"
] |
u279493135
|
p02690
|
python
|
s596268747
|
s936481184
| 320 | 81 | 10,308 | 10,616 |
Accepted
|
Accepted
| 74.69 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
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
X = INT()
for A in range(-int(X**(1/3))-1, int(X**(1/3))+1):
for B in range(-int(X**(1/3)), A):
if B**5 == A**5-X:
print((A, B))
exit()
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, 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
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
X = INT()
for i in range(-205, 205):
for j in range(-205, 205):
if i**5-j**5 == X:
print((i, j))
exit()
| 26 | 27 | 942 | 901 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import (
accumulate,
permutations,
combinations,
product,
groupby,
combinations_with_replacement,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
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
X = INT()
for A in range(-int(X ** (1 / 3)) - 1, int(X ** (1 / 3)) + 1):
for B in range(-int(X ** (1 / 3)), A):
if B**5 == A**5 - X:
print((A, B))
exit()
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, 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
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
X = INT()
for i in range(-205, 205):
for j in range(-205, 205):
if i**5 - j**5 == X:
print((i, j))
exit()
| false | 3.703704 |
[
"-from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd",
"-from itertools import (",
"- accumulate,",
"- permutations,",
"- combinations,",
"- product,",
"- groupby,",
"- combinations_with_replacement,",
"-)",
"+from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians",
"+from itertools import accumulate, permutations, combinations, product, groupby",
"+from fractions import gcd",
"-for A in range(-int(X ** (1 / 3)) - 1, int(X ** (1 / 3)) + 1):",
"- for B in range(-int(X ** (1 / 3)), A):",
"- if B**5 == A**5 - X:",
"- print((A, B))",
"+for i in range(-205, 205):",
"+ for j in range(-205, 205):",
"+ if i**5 - j**5 == X:",
"+ print((i, j))"
] | false | 0.085931 | 0.178784 | 0.480643 |
[
"s596268747",
"s936481184"
] |
u581603131
|
p02711
|
python
|
s467416867
|
s827436659
| 22 | 20 | 9,032 | 9,028 |
Accepted
|
Accepted
| 9.09 |
N = eval(input())
print(('Yes' if '7' in N else 'No'))
|
print(('Yes' if '7' in eval(input()) else 'No'))
| 2 | 1 | 48 | 40 |
N = eval(input())
print(("Yes" if "7" in N else "No"))
|
print(("Yes" if "7" in eval(input()) else "No"))
| false | 50 |
[
"-N = eval(input())",
"-print((\"Yes\" if \"7\" in N else \"No\"))",
"+print((\"Yes\" if \"7\" in eval(input()) else \"No\"))"
] | false | 0.061041 | 0.033549 | 1.819441 |
[
"s467416867",
"s827436659"
] |
u297574184
|
p02848
|
python
|
s983911953
|
s545196868
| 34 | 22 | 3,060 | 3,060 |
Accepted
|
Accepted
| 35.29 |
N = int(eval(input()))
Ss = eval(input())
ordA = ord('A')
ans = ''
for S in Ss:
i = ord(S) - ordA
i = (i+N) % 26
ans += chr(ordA + i)
print(ans)
|
ordA = ord('A')
N = int(eval(input()))
Ss = input().rstrip()
anss = ''
for S in Ss:
S = ord(S) - ordA
anss += chr(ordA + (S+N)%26)
print(anss)
| 12 | 11 | 159 | 158 |
N = int(eval(input()))
Ss = eval(input())
ordA = ord("A")
ans = ""
for S in Ss:
i = ord(S) - ordA
i = (i + N) % 26
ans += chr(ordA + i)
print(ans)
|
ordA = ord("A")
N = int(eval(input()))
Ss = input().rstrip()
anss = ""
for S in Ss:
S = ord(S) - ordA
anss += chr(ordA + (S + N) % 26)
print(anss)
| false | 8.333333 |
[
"+ordA = ord(\"A\")",
"-Ss = eval(input())",
"-ordA = ord(\"A\")",
"-ans = \"\"",
"+Ss = input().rstrip()",
"+anss = \"\"",
"- i = ord(S) - ordA",
"- i = (i + N) % 26",
"- ans += chr(ordA + i)",
"-print(ans)",
"+ S = ord(S) - ordA",
"+ anss += chr(ordA + (S + N) % 26)",
"+print(anss)"
] | false | 0.064284 | 0.036569 | 1.757851 |
[
"s983911953",
"s545196868"
] |
u426649993
|
p03986
|
python
|
s849630377
|
s767075364
| 303 | 67 | 3,756 | 3,500 |
Accepted
|
Accepted
| 77.89 |
if __name__ == "__main__":
s = eval(input())
ans = ''
for ss in s:
if ss == 'S':
ans += ss
else:
if len(ans) == 0:
ans += ss
elif ans[len(ans) - 1] == 'S':
ans = ans[:-1]
elif ans[len(ans) - 1] == 'T':
ans += ss
print((len(ans)))
|
if __name__ == "__main__":
x = eval(input())
count = 0
ans = len(x)
for i in range(len(x)):
if x[i] == 'S':
count += 1
elif count > 0 and x[i] == 'T':
ans -= 2
count -= 1
else:
count = 0
print(ans)
| 17 | 15 | 369 | 300 |
if __name__ == "__main__":
s = eval(input())
ans = ""
for ss in s:
if ss == "S":
ans += ss
else:
if len(ans) == 0:
ans += ss
elif ans[len(ans) - 1] == "S":
ans = ans[:-1]
elif ans[len(ans) - 1] == "T":
ans += ss
print((len(ans)))
|
if __name__ == "__main__":
x = eval(input())
count = 0
ans = len(x)
for i in range(len(x)):
if x[i] == "S":
count += 1
elif count > 0 and x[i] == "T":
ans -= 2
count -= 1
else:
count = 0
print(ans)
| false | 11.764706 |
[
"- s = eval(input())",
"- ans = \"\"",
"- for ss in s:",
"- if ss == \"S\":",
"- ans += ss",
"+ x = eval(input())",
"+ count = 0",
"+ ans = len(x)",
"+ for i in range(len(x)):",
"+ if x[i] == \"S\":",
"+ count += 1",
"+ elif count > 0 and x[i] == \"T\":",
"+ ans -= 2",
"+ count -= 1",
"- if len(ans) == 0:",
"- ans += ss",
"- elif ans[len(ans) - 1] == \"S\":",
"- ans = ans[:-1]",
"- elif ans[len(ans) - 1] == \"T\":",
"- ans += ss",
"- print((len(ans)))",
"+ count = 0",
"+ print(ans)"
] | false | 0.037592 | 0.036723 | 1.023659 |
[
"s849630377",
"s767075364"
] |
u102461423
|
p03014
|
python
|
s811388393
|
s679519476
| 778 | 435 | 127,852 | 145,468 |
Accepted
|
Accepted
| 44.09 |
import numpy as np
H,W = list(map(int,input().split()))
# 周りに壁を、0,1化、壁を0で持つ
grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:-1] = (np.array([list(eval(input())) for _ in range(H)]) == '.')
L = grid.size
# x軸方向の集計
def F(transpose):
x = grid
if transpose:
x = x.T
x = np.ravel(x) # to 1D array
left_zero = -np.arange(L) # 左の壁のindexの-1倍
left_zero[x] = 0
np.minimum.accumulate(left_zero, out=left_zero)
right_zero = np.arange(L) # 逆順ソートした上で左の壁のindex
right_zero[x[::-1]] = 0
np.maximum.accumulate(right_zero, out=right_zero)
y = left_zero
y -= right_zero[::-1]
return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
answer = (F(False) + F(True)).max()+2*L-5
print(answer)
|
import numpy as np
import sys
buf = sys.stdin.buffer
H,W = list(map(int,buf.readline().split()))
# 周りに壁を、0,1化、壁を0で持つ
grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:] = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'.').reshape((H,W+1))
# x軸方向の集計
def F(transpose):
x = grid
if transpose:
x = (x.T).copy()
x = np.ravel(x) # to 1D array
L = len(x)
left_zero = -np.arange(L) # 左の壁のindexの-1倍
left_zero[x] = 0
np.minimum.accumulate(left_zero, out=left_zero)
right_zero = np.arange(L) # 逆順ソートした上で左の壁のindex
right_zero[x[::-1]] = 0
np.maximum.accumulate(right_zero, out=right_zero)
y = left_zero
y += L-right_zero[::-1]
return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
answer = (F(False) + F(True)).max()-5
print(answer)
| 31 | 32 | 754 | 817 |
import numpy as np
H, W = list(map(int, input().split()))
# 周りに壁を、0,1化、壁を0で持つ
grid = np.zeros((H + 2, W + 2), dtype=np.bool)
grid[1:-1, 1:-1] = np.array([list(eval(input())) for _ in range(H)]) == "."
L = grid.size
# x軸方向の集計
def F(transpose):
x = grid
if transpose:
x = x.T
x = np.ravel(x) # to 1D array
left_zero = -np.arange(L) # 左の壁のindexの-1倍
left_zero[x] = 0
np.minimum.accumulate(left_zero, out=left_zero)
right_zero = np.arange(L) # 逆順ソートした上で左の壁のindex
right_zero[x[::-1]] = 0
np.maximum.accumulate(right_zero, out=right_zero)
y = left_zero
y -= right_zero[::-1]
return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
answer = (F(False) + F(True)).max() + 2 * L - 5
print(answer)
|
import numpy as np
import sys
buf = sys.stdin.buffer
H, W = list(map(int, buf.readline().split()))
# 周りに壁を、0,1化、壁を0で持つ
grid = np.zeros((H + 2, W + 2), dtype=np.bool)
grid[1:-1, 1:] = (np.frombuffer(buf.read(H * (W + 1)), dtype="S1") == b".").reshape(
(H, W + 1)
)
# x軸方向の集計
def F(transpose):
x = grid
if transpose:
x = (x.T).copy()
x = np.ravel(x) # to 1D array
L = len(x)
left_zero = -np.arange(L) # 左の壁のindexの-1倍
left_zero[x] = 0
np.minimum.accumulate(left_zero, out=left_zero)
right_zero = np.arange(L) # 逆順ソートした上で左の壁のindex
right_zero[x[::-1]] = 0
np.maximum.accumulate(right_zero, out=right_zero)
y = left_zero
y += L - right_zero[::-1]
return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
answer = (F(False) + F(True)).max() - 5
print(answer)
| false | 3.125 |
[
"+import sys",
"-H, W = list(map(int, input().split()))",
"+buf = sys.stdin.buffer",
"+H, W = list(map(int, buf.readline().split()))",
"-grid[1:-1, 1:-1] = np.array([list(eval(input())) for _ in range(H)]) == \".\"",
"-L = grid.size",
"+grid[1:-1, 1:] = (np.frombuffer(buf.read(H * (W + 1)), dtype=\"S1\") == b\".\").reshape(",
"+ (H, W + 1)",
"+)",
"- x = x.T",
"+ x = (x.T).copy()",
"+ L = len(x)",
"- y -= right_zero[::-1]",
"+ y += L - right_zero[::-1]",
"-answer = (F(False) + F(True)).max() + 2 * L - 5",
"+answer = (F(False) + F(True)).max() - 5"
] | false | 0.520589 | 0.466712 | 1.115439 |
[
"s811388393",
"s679519476"
] |
u600402037
|
p02996
|
python
|
s337317378
|
s111746924
| 948 | 783 | 55,252 | 53,696 |
Accepted
|
Accepted
| 17.41 |
a = [int(eval(input())) for i in range(1)]
n = a[0]
works = [list(map(int, input().split())) for i in range(n)]
#print(works)
works = sorted(works, key=lambda x: x[1])
work_time = 0
for w in works:
work_time += w[0]
if work_time > w[1]:
print("No")
break
else:
print("Yes")
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
AB = [lr() for _ in range(N)]
AB.sort(key=lambda x: x[1])
answer = 'Yes'
time = 0
for i in range(N):
if time + AB[i][0] > AB[i][1]:
answer = 'No'
time += AB[i][0]
print(answer)
| 13 | 17 | 296 | 340 |
a = [int(eval(input())) for i in range(1)]
n = a[0]
works = [list(map(int, input().split())) for i in range(n)]
# print(works)
works = sorted(works, key=lambda x: x[1])
work_time = 0
for w in works:
work_time += w[0]
if work_time > w[1]:
print("No")
break
else:
print("Yes")
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
AB = [lr() for _ in range(N)]
AB.sort(key=lambda x: x[1])
answer = "Yes"
time = 0
for i in range(N):
if time + AB[i][0] > AB[i][1]:
answer = "No"
time += AB[i][0]
print(answer)
| false | 23.529412 |
[
"-a = [int(eval(input())) for i in range(1)]",
"-n = a[0]",
"-works = [list(map(int, input().split())) for i in range(n)]",
"-# print(works)",
"-works = sorted(works, key=lambda x: x[1])",
"-work_time = 0",
"-for w in works:",
"- work_time += w[0]",
"- if work_time > w[1]:",
"- print(\"No\")",
"- break",
"-else:",
"- print(\"Yes\")",
"+import sys",
"+",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lambda: int(sr())",
"+lr = lambda: list(map(int, sr().split()))",
"+N = ir()",
"+AB = [lr() for _ in range(N)]",
"+AB.sort(key=lambda x: x[1])",
"+answer = \"Yes\"",
"+time = 0",
"+for i in range(N):",
"+ if time + AB[i][0] > AB[i][1]:",
"+ answer = \"No\"",
"+ time += AB[i][0]",
"+print(answer)"
] | false | 0.039586 | 0.060365 | 0.655776 |
[
"s337317378",
"s111746924"
] |
u018679195
|
p02696
|
python
|
s784319965
|
s959022959
| 70 | 23 | 68,988 | 8,908 |
Accepted
|
Accepted
| 67.14 |
from sys import stdin, stdout
from collections import defaultdict
import math
from queue import Queue
a, b, n = list(map(int, stdin.readline().strip().split()))
x = min(b - 1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
stdout.writelines(str(ans) + '\n')
|
import math
def eq_value(a, b, x):
return math.floor(a * x / b) - a * math.floor(x / b)
A, B, n = list(map(int, input().split()))
print((eq_value(A, B, min(B-1, n))))
| 13 | 9 | 277 | 175 |
from sys import stdin, stdout
from collections import defaultdict
import math
from queue import Queue
a, b, n = list(map(int, stdin.readline().strip().split()))
x = min(b - 1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
stdout.writelines(str(ans) + "\n")
|
import math
def eq_value(a, b, x):
return math.floor(a * x / b) - a * math.floor(x / b)
A, B, n = list(map(int, input().split()))
print((eq_value(A, B, min(B - 1, n))))
| false | 30.769231 |
[
"-from sys import stdin, stdout",
"-from collections import defaultdict",
"-from queue import Queue",
"-a, b, n = list(map(int, stdin.readline().strip().split()))",
"-x = min(b - 1, n)",
"-ans = math.floor(a * x / b) - a * math.floor(x / b)",
"-stdout.writelines(str(ans) + \"\\n\")",
"+",
"+def eq_value(a, b, x):",
"+ return math.floor(a * x / b) - a * math.floor(x / b)",
"+",
"+",
"+A, B, n = list(map(int, input().split()))",
"+print((eq_value(A, B, min(B - 1, n))))"
] | false | 0.139576 | 0.047193 | 2.957579 |
[
"s784319965",
"s959022959"
] |
u063052907
|
p03835
|
python
|
s552847184
|
s218407504
| 1,467 | 19 | 2,940 | 2,940 |
Accepted
|
Accepted
| 98.7 |
# coding: utf-8
K, S = list(map(int, input().split()))
cnt=0
for x in range(K+1):
yz = S - x
if yz < 0:
break
elif yz > 2*K:
continue
else:
for y in range(K+1):
z = S - x - y
if 0<=z<=K:
cnt+=1
print(cnt)
|
# coding: utf-8
K, S = list(map(int, input().split()))
cnt=0
for x in range(K+1):
yz = S - x
if yz < 0:
break
elif yz > 2*K:
continue
else:
cnt += yz + 1 - 2 * max(0, yz - K)
print(cnt)
| 15 | 12 | 373 | 271 |
# coding: utf-8
K, S = list(map(int, input().split()))
cnt = 0
for x in range(K + 1):
yz = S - x
if yz < 0:
break
elif yz > 2 * K:
continue
else:
for y in range(K + 1):
z = S - x - y
if 0 <= z <= K:
cnt += 1
print(cnt)
|
# coding: utf-8
K, S = list(map(int, input().split()))
cnt = 0
for x in range(K + 1):
yz = S - x
if yz < 0:
break
elif yz > 2 * K:
continue
else:
cnt += yz + 1 - 2 * max(0, yz - K)
print(cnt)
| false | 20 |
[
"- for y in range(K + 1):",
"- z = S - x - y",
"- if 0 <= z <= K:",
"- cnt += 1",
"+ cnt += yz + 1 - 2 * max(0, yz - K)"
] | false | 0.088937 | 0.008804 | 10.102301 |
[
"s552847184",
"s218407504"
] |
u054514819
|
p02742
|
python
|
s495058518
|
s191479724
| 19 | 17 | 2,940 | 3,060 |
Accepted
|
Accepted
| 10.53 |
H, W = list(map(int, input().split()))
if H==1 or W==1:
print((1))
else:
print(((H*W+1)//2))
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
from math import ceil
H, W = mapint()
if H==1 or W==1:
print((1))
else:
print((ceil(H*W/2)))
| 5 | 11 | 90 | 243 |
H, W = list(map(int, input().split()))
if H == 1 or W == 1:
print((1))
else:
print(((H * W + 1) // 2))
|
import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
from math import ceil
H, W = mapint()
if H == 1 or W == 1:
print((1))
else:
print((ceil(H * W / 2)))
| false | 54.545455 |
[
"-H, W = list(map(int, input().split()))",
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def mapint():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+sys.setrecursionlimit(10**9)",
"+from math import ceil",
"+",
"+H, W = mapint()",
"- print(((H * W + 1) // 2))",
"+ print((ceil(H * W / 2)))"
] | false | 0.102824 | 0.066601 | 1.543867 |
[
"s495058518",
"s191479724"
] |
u718949306
|
p02813
|
python
|
s143083688
|
s973176912
| 48 | 29 | 3,064 | 3,064 |
Accepted
|
Accepted
| 39.58 |
import itertools
s = 1
a = 0
b = 0
N = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
for i in ite:
if list(i) == p:
a = s
s += 1
s = 1
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
for i in ite:
if list(i) == q:
b = s
s += 1
if a > b:
total = a - b
else:
total = b - a
print(total)
|
import itertools
N = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
a = 0
b = 0
s = 1
for i in ite:
if i == p:
a = s
if i == q:
b = s
s += 1
if a > b:
total = a - b
else:
total = b - a
print(total)
| 25 | 20 | 476 | 361 |
import itertools
s = 1
a = 0
b = 0
N = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
for i in ite:
if list(i) == p:
a = s
s += 1
s = 1
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
for i in ite:
if list(i) == q:
b = s
s += 1
if a > b:
total = a - b
else:
total = b - a
print(total)
|
import itertools
N = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
a = 0
b = 0
s = 1
for i in ite:
if i == p:
a = s
if i == q:
b = s
s += 1
if a > b:
total = a - b
else:
total = b - a
print(total)
| false | 20 |
[
"-s = 1",
"+N = int(eval(input()))",
"+p = tuple(map(int, input().split()))",
"+q = tuple(map(int, input().split()))",
"+ite = [x for x in range(1, N + 1)]",
"+ite = itertools.permutations(ite)",
"-N = int(eval(input()))",
"-p = list(map(int, input().split()))",
"-q = list(map(int, input().split()))",
"-ite = [x for x in range(1, N + 1)]",
"-ite = itertools.permutations(ite)",
"+s = 1",
"- if list(i) == p:",
"+ if i == p:",
"- s += 1",
"-s = 1",
"-ite = [x for x in range(1, N + 1)]",
"-ite = itertools.permutations(ite)",
"-for i in ite:",
"- if list(i) == q:",
"+ if i == q:"
] | false | 0.040662 | 0.074814 | 0.543514 |
[
"s143083688",
"s973176912"
] |
u643679148
|
p02802
|
python
|
s230160833
|
s165042892
| 254 | 216 | 36,464 | 18,212 |
Accepted
|
Accepted
| 14.96 |
from collections import defaultdict as dic
n, m = list(map(int, input().split()))
ac = 0
pena = 0
d = dic(list)
for i in range(m):
pi, si = input().split()
d[pi].append(si)
for (k, v) in list(d.items()):
pe = 0
flag = False
for aw in v:
if aw == 'WA':
pe += 1
else:
ac += 1
flag = True
break
if flag:
pena += pe
print((ac, pena))
|
# -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
ck = set()
pe = 0
ac = 0
penalty = 0
cp = [0] * (n+1)
for i in range(m):
p, s = input().split()
p = int(p)
if p in ck:
continue
if s == 'WA':
cp[p] += 1
else:
penalty += cp[p]
pe = 0
ac += 1
ck.add(p)
print((ac, penalty))
| 24 | 22 | 438 | 368 |
from collections import defaultdict as dic
n, m = list(map(int, input().split()))
ac = 0
pena = 0
d = dic(list)
for i in range(m):
pi, si = input().split()
d[pi].append(si)
for (k, v) in list(d.items()):
pe = 0
flag = False
for aw in v:
if aw == "WA":
pe += 1
else:
ac += 1
flag = True
break
if flag:
pena += pe
print((ac, pena))
|
# -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
ck = set()
pe = 0
ac = 0
penalty = 0
cp = [0] * (n + 1)
for i in range(m):
p, s = input().split()
p = int(p)
if p in ck:
continue
if s == "WA":
cp[p] += 1
else:
penalty += cp[p]
pe = 0
ac += 1
ck.add(p)
print((ac, penalty))
| false | 8.333333 |
[
"-from collections import defaultdict as dic",
"-",
"+# -*- coding: utf-8 -*-",
"+ck = set()",
"+pe = 0",
"-pena = 0",
"-d = dic(list)",
"+penalty = 0",
"+cp = [0] * (n + 1)",
"- pi, si = input().split()",
"- d[pi].append(si)",
"-for (k, v) in list(d.items()):",
"- pe = 0",
"- flag = False",
"- for aw in v:",
"- if aw == \"WA\":",
"- pe += 1",
"- else:",
"- ac += 1",
"- flag = True",
"- break",
"- if flag:",
"- pena += pe",
"-print((ac, pena))",
"+ p, s = input().split()",
"+ p = int(p)",
"+ if p in ck:",
"+ continue",
"+ if s == \"WA\":",
"+ cp[p] += 1",
"+ else:",
"+ penalty += cp[p]",
"+ pe = 0",
"+ ac += 1",
"+ ck.add(p)",
"+print((ac, penalty))"
] | false | 0.04273 | 0.070704 | 0.604349 |
[
"s230160833",
"s165042892"
] |
u490553751
|
p02724
|
python
|
s260246230
|
s549223361
| 91 | 30 | 3,444 | 9,076 |
Accepted
|
Accepted
| 67.03 |
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
X = int(eval(input()))
k = X //500
ans = 0
ans += 1000*k
X -= 500*k
l = X //5
ans += 5*l
print(ans)
|
N = int(eval(input()))
d = N // 500
mod = N % 500
d2 = mod // 5
print((d*1000+d2*5))
| 13 | 5 | 227 | 80 |
# template
def inputlist():
return [int(j) for j in input().split()]
from collections import Counter
# template
# issueから始める
X = int(eval(input()))
k = X // 500
ans = 0
ans += 1000 * k
X -= 500 * k
l = X // 5
ans += 5 * l
print(ans)
|
N = int(eval(input()))
d = N // 500
mod = N % 500
d2 = mod // 5
print((d * 1000 + d2 * 5))
| false | 61.538462 |
[
"-# template",
"-def inputlist():",
"- return [int(j) for j in input().split()]",
"-",
"-",
"-from collections import Counter",
"-",
"-# template",
"-# issueから始める",
"-X = int(eval(input()))",
"-k = X // 500",
"-ans = 0",
"-ans += 1000 * k",
"-X -= 500 * k",
"-l = X // 5",
"-ans += 5 * l",
"-print(ans)",
"+N = int(eval(input()))",
"+d = N // 500",
"+mod = N % 500",
"+d2 = mod // 5",
"+print((d * 1000 + d2 * 5))"
] | false | 0.03712 | 0.037987 | 0.97717 |
[
"s260246230",
"s549223361"
] |
u133936772
|
p03014
|
python
|
s277006814
|
s274631947
| 1,739 | 1,554 | 179,332 | 111,836 |
Accepted
|
Accepted
| 10.64 |
h,w=list(map(int,input().split()))
f=lambda:[[0]*w for _ in range(h)]
g=[eval(input()) for _ in range(h)]
l,r=f(),f()
for i in range(h):
lc=rc=0
for j in range(w):
if g[i][j]=='.': lc+=1; l[i][j]=lc
else: lc=0
if g[i][-1-j]=='.': rc+=1; r[i][-1-j]=rc
else: rc=0
d,u=f(),f()
for i in range(w):
dc=uc=0
for j in range(h):
if g[j][i]=='.': dc+=1; d[j][i]=dc
else: dc=0
if g[-1-j][i]=='.': uc+=1; u[-1-j][i]=uc
else: uc=0
print((max(l[i][j]+r[i][j]+d[i][j]+u[i][j]-3 for i in range(h) for j in range(w))))
|
h,w=list(map(int,input().split()))
g=[[c=='.'for c in eval(input())] for _ in range(h)]
a=[[-3]*w for _ in range(h)]
for i in range(h):
l=r=0
for j in range(w):
l=-~l*g[i][j]; a[i][j]+=l
r=-~r*g[i][-1-j]; a[i][-1-j]+=r
for i in range(w):
d=u=0
for j in range(h):
d=-~d*g[j][i]; a[j][i]+=d
u=-~u*g[-1-j][i]; a[-1-j][i]+=u
print((max(a[i][j] for i in range(h) for j in range(w))))
| 20 | 14 | 546 | 401 |
h, w = list(map(int, input().split()))
f = lambda: [[0] * w for _ in range(h)]
g = [eval(input()) for _ in range(h)]
l, r = f(), f()
for i in range(h):
lc = rc = 0
for j in range(w):
if g[i][j] == ".":
lc += 1
l[i][j] = lc
else:
lc = 0
if g[i][-1 - j] == ".":
rc += 1
r[i][-1 - j] = rc
else:
rc = 0
d, u = f(), f()
for i in range(w):
dc = uc = 0
for j in range(h):
if g[j][i] == ".":
dc += 1
d[j][i] = dc
else:
dc = 0
if g[-1 - j][i] == ".":
uc += 1
u[-1 - j][i] = uc
else:
uc = 0
print(
(max(l[i][j] + r[i][j] + d[i][j] + u[i][j] - 3 for i in range(h) for j in range(w)))
)
|
h, w = list(map(int, input().split()))
g = [[c == "." for c in eval(input())] for _ in range(h)]
a = [[-3] * w for _ in range(h)]
for i in range(h):
l = r = 0
for j in range(w):
l = -~l * g[i][j]
a[i][j] += l
r = -~r * g[i][-1 - j]
a[i][-1 - j] += r
for i in range(w):
d = u = 0
for j in range(h):
d = -~d * g[j][i]
a[j][i] += d
u = -~u * g[-1 - j][i]
a[-1 - j][i] += u
print((max(a[i][j] for i in range(h) for j in range(w))))
| false | 30 |
[
"-f = lambda: [[0] * w for _ in range(h)]",
"-g = [eval(input()) for _ in range(h)]",
"-l, r = f(), f()",
"+g = [[c == \".\" for c in eval(input())] for _ in range(h)]",
"+a = [[-3] * w for _ in range(h)]",
"- lc = rc = 0",
"+ l = r = 0",
"- if g[i][j] == \".\":",
"- lc += 1",
"- l[i][j] = lc",
"- else:",
"- lc = 0",
"- if g[i][-1 - j] == \".\":",
"- rc += 1",
"- r[i][-1 - j] = rc",
"- else:",
"- rc = 0",
"-d, u = f(), f()",
"+ l = -~l * g[i][j]",
"+ a[i][j] += l",
"+ r = -~r * g[i][-1 - j]",
"+ a[i][-1 - j] += r",
"- dc = uc = 0",
"+ d = u = 0",
"- if g[j][i] == \".\":",
"- dc += 1",
"- d[j][i] = dc",
"- else:",
"- dc = 0",
"- if g[-1 - j][i] == \".\":",
"- uc += 1",
"- u[-1 - j][i] = uc",
"- else:",
"- uc = 0",
"-print(",
"- (max(l[i][j] + r[i][j] + d[i][j] + u[i][j] - 3 for i in range(h) for j in range(w)))",
"-)",
"+ d = -~d * g[j][i]",
"+ a[j][i] += d",
"+ u = -~u * g[-1 - j][i]",
"+ a[-1 - j][i] += u",
"+print((max(a[i][j] for i in range(h) for j in range(w))))"
] | false | 0.060733 | 0.059397 | 1.022487 |
[
"s277006814",
"s274631947"
] |
u823885866
|
p03041
|
python
|
s805599520
|
s843133729
| 115 | 29 | 26,956 | 8,984 |
Accepted
|
Accepted
| 74.78 |
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7
a, b = rm()
s = rr()
print((s[:b-1] + s[b-1].lower() + s[b:]))
|
import sys
rr = lambda: sys.stdin.readline().rstrip()
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
a, b = rm()
s = rr()
print((s[:b-1] + s[b-1].lower() + s[b:]))
| 19 | 6 | 465 | 179 |
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float("inf")
mod = 10**9 + 7
a, b = rm()
s = rr()
print((s[: b - 1] + s[b - 1].lower() + s[b:]))
|
import sys
rr = lambda: sys.stdin.readline().rstrip()
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
a, b = rm()
s = rr()
print((s[: b - 1] + s[b - 1].lower() + s[b:]))
| false | 68.421053 |
[
"-import math",
"-import itertools",
"-import collections",
"-import heapq",
"-import re",
"-import numpy as np",
"-rs = lambda: sys.stdin.buffer.readline().split()",
"-ri = lambda: int(sys.stdin.readline())",
"-rl = lambda: list(map(int, sys.stdin.readline().split()))",
"-inf = float(\"inf\")",
"-mod = 10**9 + 7"
] | false | 0.091684 | 0.047645 | 1.924293 |
[
"s805599520",
"s843133729"
] |
u077291787
|
p02983
|
python
|
s971552985
|
s366013537
| 532 | 47 | 3,064 | 3,064 |
Accepted
|
Accepted
| 91.17 |
# ABC133C - Remainder Minimization 2019
def main():
L, R = list(map(int, input().rstrip().split()))
MOD = 2019
if R - L + 1 >= MOD: # L <= 2019n <= R
print((0))
else: # max: 2018 * 2017 patterns
ans = float("inf")
L, R = L % MOD, R % MOD
for i in range(L, R):
for j in range(i + 1, R + 1):
ans = min(ans, (i * j) % MOD)
print(ans)
if __name__ == "__main__":
main()
|
# ABC133C - Remainder Minimization 2019
def main():
L, R = list(map(int, input().rstrip().split()))
MOD = 2019
if R - L + 1 >= MOD: # L <= 2019n <= R
print((0))
else: # max: 2018 * 2017 patterns
ans = float("inf")
L, R = L % MOD, R % MOD
for i in range(L, R):
for j in range(i + 1, R + 1):
ans = min(ans, (i * j) % MOD)
if ans == 0:
print(ans)
return
print(ans)
if __name__ == "__main__":
main()
| 17 | 20 | 470 | 560 |
# ABC133C - Remainder Minimization 2019
def main():
L, R = list(map(int, input().rstrip().split()))
MOD = 2019
if R - L + 1 >= MOD: # L <= 2019n <= R
print((0))
else: # max: 2018 * 2017 patterns
ans = float("inf")
L, R = L % MOD, R % MOD
for i in range(L, R):
for j in range(i + 1, R + 1):
ans = min(ans, (i * j) % MOD)
print(ans)
if __name__ == "__main__":
main()
|
# ABC133C - Remainder Minimization 2019
def main():
L, R = list(map(int, input().rstrip().split()))
MOD = 2019
if R - L + 1 >= MOD: # L <= 2019n <= R
print((0))
else: # max: 2018 * 2017 patterns
ans = float("inf")
L, R = L % MOD, R % MOD
for i in range(L, R):
for j in range(i + 1, R + 1):
ans = min(ans, (i * j) % MOD)
if ans == 0:
print(ans)
return
print(ans)
if __name__ == "__main__":
main()
| false | 15 |
[
"+ if ans == 0:",
"+ print(ans)",
"+ return"
] | false | 0.049176 | 0.037295 | 1.318572 |
[
"s971552985",
"s366013537"
] |
u945181840
|
p03240
|
python
|
s370588360
|
s438779725
| 1,041 | 32 | 3,064 | 3,064 |
Accepted
|
Accepted
| 96.93 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
xyh = [list(map(int, input().split())) for _ in range(N)]
for i in range(101):
for j in range(101):
for x, y, h in xyh:
if h != 0:
H = h + abs(i - x) + abs(j - y)
for x, y, h in xyh:
if h != max(H - abs(i - x) - abs(j - y), 0):
break
else:
print((i, j, H))
exit()
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda i:i[2], reverse=True)
x0, y0, h0 = xyh[0]
for i in range(101):
for j in range(101):
H = h0 + abs(i - x0) + abs(j - y0)
for x, y, h in xyh:
if h > 0:
if H != h + abs(i - x) + abs(j - y):
break
else:
if H - abs(i - x) - abs(j - y) > 0:
break
else:
print((i, j, H))
exit()
| 17 | 21 | 490 | 570 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
xyh = [list(map(int, input().split())) for _ in range(N)]
for i in range(101):
for j in range(101):
for x, y, h in xyh:
if h != 0:
H = h + abs(i - x) + abs(j - y)
for x, y, h in xyh:
if h != max(H - abs(i - x) - abs(j - y), 0):
break
else:
print((i, j, H))
exit()
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda i: i[2], reverse=True)
x0, y0, h0 = xyh[0]
for i in range(101):
for j in range(101):
H = h0 + abs(i - x0) + abs(j - y0)
for x, y, h in xyh:
if h > 0:
if H != h + abs(i - x) + abs(j - y):
break
else:
if H - abs(i - x) - abs(j - y) > 0:
break
else:
print((i, j, H))
exit()
| false | 19.047619 |
[
"+xyh.sort(key=lambda i: i[2], reverse=True)",
"+x0, y0, h0 = xyh[0]",
"+ H = h0 + abs(i - x0) + abs(j - y0)",
"- if h != 0:",
"- H = h + abs(i - x) + abs(j - y)",
"- for x, y, h in xyh:",
"- if h != max(H - abs(i - x) - abs(j - y), 0):",
"- break",
"- else:",
"- print((i, j, H))",
"- exit()",
"+ if h > 0:",
"+ if H != h + abs(i - x) + abs(j - y):",
"+ break",
"+ else:",
"+ if H - abs(i - x) - abs(j - y) > 0:",
"+ break",
"+ else:",
"+ print((i, j, H))",
"+ exit()"
] | false | 0.057398 | 0.040333 | 1.423085 |
[
"s370588360",
"s438779725"
] |
u767664985
|
p03533
|
python
|
s790221123
|
s414632139
| 22 | 17 | 3,188 | 2,940 |
Accepted
|
Accepted
| 22.73 |
import re
l = re.compile("^A?KIHA?BA?RA?$").findall(eval(input()))
if l:
print("YES")
else:
print("NO")
|
S = eval(input())
strings = ["AKIHABARA", "KIHABARA", "AKIHBARA", "AKIHABRA", "AKIHABAR", "KIHBARA", "KIHABRA", "KIHABAR", "AKIHBRA", "AKIHBAR", "AKIHABR", "AKIHBR", "KIHABR", "KIHBAR", "KIHBRA", "KIHBR"]
if S in strings:
print("YES")
else:
print("NO")
| 6 | 6 | 105 | 254 |
import re
l = re.compile("^A?KIHA?BA?RA?$").findall(eval(input()))
if l:
print("YES")
else:
print("NO")
|
S = eval(input())
strings = [
"AKIHABARA",
"KIHABARA",
"AKIHBARA",
"AKIHABRA",
"AKIHABAR",
"KIHBARA",
"KIHABRA",
"KIHABAR",
"AKIHBRA",
"AKIHBAR",
"AKIHABR",
"AKIHBR",
"KIHABR",
"KIHBAR",
"KIHBRA",
"KIHBR",
]
if S in strings:
print("YES")
else:
print("NO")
| false | 0 |
[
"-import re",
"-",
"-l = re.compile(\"^A?KIHA?BA?RA?$\").findall(eval(input()))",
"-if l:",
"+S = eval(input())",
"+strings = [",
"+ \"AKIHABARA\",",
"+ \"KIHABARA\",",
"+ \"AKIHBARA\",",
"+ \"AKIHABRA\",",
"+ \"AKIHABAR\",",
"+ \"KIHBARA\",",
"+ \"KIHABRA\",",
"+ \"KIHABAR\",",
"+ \"AKIHBRA\",",
"+ \"AKIHBAR\",",
"+ \"AKIHABR\",",
"+ \"AKIHBR\",",
"+ \"KIHABR\",",
"+ \"KIHBAR\",",
"+ \"KIHBRA\",",
"+ \"KIHBR\",",
"+]",
"+if S in strings:"
] | false | 0.11797 | 0.04022 | 2.93312 |
[
"s790221123",
"s414632139"
] |
u573754721
|
p02885
|
python
|
s751108714
|
s704817724
| 175 | 18 | 38,384 | 2,940 |
Accepted
|
Accepted
| 89.71 |
a,b=list(map(int,input().split()))
if 0>a-(2*b):
print((0))
else:
print((a-(2*b)))
|
a,b=list(map(int,input().split()))
if a<2*b:
print((0))
else:
print((a-(2*b)))
| 5 | 5 | 85 | 76 |
a, b = list(map(int, input().split()))
if 0 > a - (2 * b):
print((0))
else:
print((a - (2 * b)))
|
a, b = list(map(int, input().split()))
if a < 2 * b:
print((0))
else:
print((a - (2 * b)))
| false | 0 |
[
"-if 0 > a - (2 * b):",
"+if a < 2 * b:"
] | false | 0.036056 | 0.03426 | 1.052421 |
[
"s751108714",
"s704817724"
] |
u150984829
|
p02279
|
python
|
s590338885
|
s531632404
| 870 | 660 | 55,916 | 52,936 |
Accepted
|
Accepted
| 24.14 |
def q(a,h):
d[a]=str(h)
for b in t[a]:q(b,h+1)
t,p,d={},{},{}
for _ in[0]*int(eval(input())):
e=input().split()
t[e[0]]=e[2:]
for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
for i in sorted(map(int,t)):
i=str(i)
f='root'if'-1'==p[i]else'internal node'if t[i]else'leaf'
print(f'node {i}: parent = {p[i]}, depth = {d[i]}, {f}, {list(map(int,t[i]))}')
|
def q(a,h):
d[a]=str(h)
for b in t[a]:q(b,h+1)
t,p,d={},{},{}
for _ in[0]*int(eval(input())):
e=input().split()
t[e[0]]=e[2:]
for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
for i in sorted(map(int,t)):i=str(i);print(f"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]")
| 15 | 12 | 383 | 370 |
def q(a, h):
d[a] = str(h)
for b in t[a]:
q(b, h + 1)
t, p, d = {}, {}, {}
for _ in [0] * int(eval(input())):
e = input().split()
t[e[0]] = e[2:]
for i in e[2:]:
p[i] = e[0]
r = (set(t) - set(p)).pop()
p[r] = "-1"
q(r, 0)
for i in sorted(map(int, t)):
i = str(i)
f = "root" if "-1" == p[i] else "internal node" if t[i] else "leaf"
print(f"node {i}: parent = {p[i]}, depth = {d[i]}, {f}, {list(map(int,t[i]))}")
|
def q(a, h):
d[a] = str(h)
for b in t[a]:
q(b, h + 1)
t, p, d = {}, {}, {}
for _ in [0] * int(eval(input())):
e = input().split()
t[e[0]] = e[2:]
for i in e[2:]:
p[i] = e[0]
r = (set(t) - set(p)).pop()
p[r] = "-1"
q(r, 0)
for i in sorted(map(int, t)):
i = str(i)
print(
f"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]"
)
| false | 20 |
[
"- f = \"root\" if \"-1\" == p[i] else \"internal node\" if t[i] else \"leaf\"",
"- print(f\"node {i}: parent = {p[i]}, depth = {d[i]}, {f}, {list(map(int,t[i]))}\")",
"+ print(",
"+ f\"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]\"",
"+ )"
] | false | 0.080417 | 0.082335 | 0.976698 |
[
"s590338885",
"s531632404"
] |
u189326411
|
p03013
|
python
|
s734014052
|
s257259508
| 618 | 468 | 464,164 | 460,056 |
Accepted
|
Accepted
| 24.27 |
n,m = list(map(int, input().split()))
mod = 10**9+7
#フィボナッチ数列
dp = [0 for i in range(n+2)]
dp[0] = 1
dp[1] = 1
for i in range(2,n+2):
dp[i] = dp[i-1] + dp[i-2]
#穴が無い場合
if m==0:
print((dp[n]%mod))
exit()
lst = []
for i in range(m):
lst.append(int(eval(input())))
lst.sort()
#2連続穴がある場合
for i in range(len(lst)-1):
if lst[i]+1 == lst[i+1]:
print((0))
exit()
lst2 = []
for i in range(len(lst)):
if i==0:
lst2.append(lst[0]-1)
else:
lst2.append(lst[i]-lst[i-1]-2)
lst2.append(n-lst[-1]-1)
ans = 1
for i in lst2:
ans *= dp[i]
ans %= mod
# print(lst)
# print(lst2)
print(ans)
|
n,m = list(map(int, input().split()))
mod = 10**9+7
lst = []
for i in range(m):
lst.append(int(eval(input())))
lst.sort()
#フィボナッチ数列
dp = [-1 for i in range(n+2)]
dp[0] = 1
dp[1] = 1
for i in lst:
dp[i] = 0
for i in range(2,n+2):
if dp[i]<0:
dp[i] = dp[i-1] + dp[i-2]
# print(lst)
# print(lst2)
# print(dp)
print((dp[n]%mod))
| 42 | 22 | 669 | 355 |
n, m = list(map(int, input().split()))
mod = 10**9 + 7
# フィボナッチ数列
dp = [0 for i in range(n + 2)]
dp[0] = 1
dp[1] = 1
for i in range(2, n + 2):
dp[i] = dp[i - 1] + dp[i - 2]
# 穴が無い場合
if m == 0:
print((dp[n] % mod))
exit()
lst = []
for i in range(m):
lst.append(int(eval(input())))
lst.sort()
# 2連続穴がある場合
for i in range(len(lst) - 1):
if lst[i] + 1 == lst[i + 1]:
print((0))
exit()
lst2 = []
for i in range(len(lst)):
if i == 0:
lst2.append(lst[0] - 1)
else:
lst2.append(lst[i] - lst[i - 1] - 2)
lst2.append(n - lst[-1] - 1)
ans = 1
for i in lst2:
ans *= dp[i]
ans %= mod
# print(lst)
# print(lst2)
print(ans)
|
n, m = list(map(int, input().split()))
mod = 10**9 + 7
lst = []
for i in range(m):
lst.append(int(eval(input())))
lst.sort()
# フィボナッチ数列
dp = [-1 for i in range(n + 2)]
dp[0] = 1
dp[1] = 1
for i in lst:
dp[i] = 0
for i in range(2, n + 2):
if dp[i] < 0:
dp[i] = dp[i - 1] + dp[i - 2]
# print(lst)
# print(lst2)
# print(dp)
print((dp[n] % mod))
| false | 47.619048 |
[
"-# フィボナッチ数列",
"-dp = [0 for i in range(n + 2)]",
"-dp[0] = 1",
"-dp[1] = 1",
"-for i in range(2, n + 2):",
"- dp[i] = dp[i - 1] + dp[i - 2]",
"-# 穴が無い場合",
"-if m == 0:",
"- print((dp[n] % mod))",
"- exit()",
"-# 2連続穴がある場合",
"-for i in range(len(lst) - 1):",
"- if lst[i] + 1 == lst[i + 1]:",
"- print((0))",
"- exit()",
"-lst2 = []",
"-for i in range(len(lst)):",
"- if i == 0:",
"- lst2.append(lst[0] - 1)",
"- else:",
"- lst2.append(lst[i] - lst[i - 1] - 2)",
"-lst2.append(n - lst[-1] - 1)",
"-ans = 1",
"-for i in lst2:",
"- ans *= dp[i]",
"- ans %= mod",
"+# フィボナッチ数列",
"+dp = [-1 for i in range(n + 2)]",
"+dp[0] = 1",
"+dp[1] = 1",
"+for i in lst:",
"+ dp[i] = 0",
"+for i in range(2, n + 2):",
"+ if dp[i] < 0:",
"+ dp[i] = dp[i - 1] + dp[i - 2]",
"-print(ans)",
"+# print(dp)",
"+print((dp[n] % mod))"
] | false | 0.083804 | 0.072854 | 1.150297 |
[
"s734014052",
"s257259508"
] |
u780475861
|
p03647
|
python
|
s557261339
|
s057655392
| 359 | 290 | 19,024 | 19,168 |
Accepted
|
Accepted
| 19.22 |
import sys
n, m = list(map(int, sys.stdin.readline().split()))
set1, setn = set(), set()
for _ in range(m):
i, j = list(map(int, sys.stdin.readline().split()))
if i in [1, n] or j in [1, n]:
if i == 1:
set1.add(j)
if i == n:
setn.add(j)
if j == 1:
set1.add(i)
if j == n:
setn.add(i)
if set1 & setn:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
|
import sys
def main():
n, m = list(map(int, sys.stdin.readline().split()))
set1, setn = set(), set()
for _ in range(m):
i, j = list(map(int, sys.stdin.readline().split()))
if i == 1:
set1.add(j)
if j == n:
setn.add(i)
if set1 & setn:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
if __name__ == '__main__':
main()
| 18 | 20 | 396 | 366 |
import sys
n, m = list(map(int, sys.stdin.readline().split()))
set1, setn = set(), set()
for _ in range(m):
i, j = list(map(int, sys.stdin.readline().split()))
if i in [1, n] or j in [1, n]:
if i == 1:
set1.add(j)
if i == n:
setn.add(j)
if j == 1:
set1.add(i)
if j == n:
setn.add(i)
if set1 & setn:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
|
import sys
def main():
n, m = list(map(int, sys.stdin.readline().split()))
set1, setn = set(), set()
for _ in range(m):
i, j = list(map(int, sys.stdin.readline().split()))
if i == 1:
set1.add(j)
if j == n:
setn.add(i)
if set1 & setn:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
if __name__ == "__main__":
main()
| false | 10 |
[
"-n, m = list(map(int, sys.stdin.readline().split()))",
"-set1, setn = set(), set()",
"-for _ in range(m):",
"- i, j = list(map(int, sys.stdin.readline().split()))",
"- if i in [1, n] or j in [1, n]:",
"+",
"+def main():",
"+ n, m = list(map(int, sys.stdin.readline().split()))",
"+ set1, setn = set(), set()",
"+ for _ in range(m):",
"+ i, j = list(map(int, sys.stdin.readline().split()))",
"- if i == n:",
"- setn.add(j)",
"- if j == 1:",
"- set1.add(i)",
"-if set1 & setn:",
"- print(\"POSSIBLE\")",
"-else:",
"- print(\"IMPOSSIBLE\")",
"+ if set1 & setn:",
"+ print(\"POSSIBLE\")",
"+ else:",
"+ print(\"IMPOSSIBLE\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.043717 | 0.040779 | 1.072047 |
[
"s557261339",
"s057655392"
] |
u110943895
|
p03447
|
python
|
s488335843
|
s609516040
| 19 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10.53 |
cash = int(eval(input()))
price_cake = int(eval(input()))
price_donut = int(eval(input()))
print(((cash-price_cake)%price_donut))
|
cash, price_cake, price_donut = [int(eval(input())) for i in range(3)]
print(((cash-price_cake)%price_donut))
| 4 | 2 | 112 | 102 |
cash = int(eval(input()))
price_cake = int(eval(input()))
price_donut = int(eval(input()))
print(((cash - price_cake) % price_donut))
|
cash, price_cake, price_donut = [int(eval(input())) for i in range(3)]
print(((cash - price_cake) % price_donut))
| false | 50 |
[
"-cash = int(eval(input()))",
"-price_cake = int(eval(input()))",
"-price_donut = int(eval(input()))",
"+cash, price_cake, price_donut = [int(eval(input())) for i in range(3)]"
] | false | 0.037578 | 0.03627 | 1.036063 |
[
"s488335843",
"s609516040"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.