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
sequence | 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
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u677312543 | p03212 | python | s035158271 | s367401768 | 355 | 92 | 3,064 | 3,060 | Accepted | Accepted | 74.08 | n = int(eval(input()))
cnt = 0
i = 1
while i <= n:
is_broken = False
string = list(str(i))
for j, s in enumerate(string):
if s not in ['3', '5', '7']:
i = i + 10**(len(string) - j - 1)
is_broken = True
break
if is_broken:
continue
c1 = string.count('3') >= 1
c2 = string.count('5') >= 1
c3 = string.count('7') >= 1
if c1 and c2 and c3:
cnt += 1
i += 1
print(cnt) | n = int(eval(input()))
def dfs(s):
if int(s) > n:
return 0
ret = 1 if all(s.count(c) > 0 for c in '753') else 0
for c in '753':
ret += dfs(s + c)
return ret
print((dfs('0'))) | 24 | 11 | 479 | 210 | n = int(eval(input()))
cnt = 0
i = 1
while i <= n:
is_broken = False
string = list(str(i))
for j, s in enumerate(string):
if s not in ["3", "5", "7"]:
i = i + 10 ** (len(string) - j - 1)
is_broken = True
break
if is_broken:
continue
c1 = string.count("3") >= 1
c2 = string.count("5") >= 1
c3 = string.count("7") >= 1
if c1 and c2 and c3:
cnt += 1
i += 1
print(cnt)
| n = int(eval(input()))
def dfs(s):
if int(s) > n:
return 0
ret = 1 if all(s.count(c) > 0 for c in "753") else 0
for c in "753":
ret += dfs(s + c)
return ret
print((dfs("0")))
| false | 54.166667 | [
"-cnt = 0",
"-i = 1",
"-while i <= n:",
"- is_broken = False",
"- string = list(str(i))",
"- for j, s in enumerate(string):",
"- if s not in [\"3\", \"5\", \"7\"]:",
"- i = i + 10 ** (len(string) - j - 1)",
"- is_broken = True",
"- break",
"- if is_broken:",
"- continue",
"- c1 = string.count(\"3\") >= 1",
"- c2 = string.count(\"5\") >= 1",
"- c3 = string.count(\"7\") >= 1",
"- if c1 and c2 and c3:",
"- cnt += 1",
"- i += 1",
"-print(cnt)",
"+",
"+",
"+def dfs(s):",
"+ if int(s) > n:",
"+ return 0",
"+ ret = 1 if all(s.count(c) > 0 for c in \"753\") else 0",
"+ for c in \"753\":",
"+ ret += dfs(s + c)",
"+ return ret",
"+",
"+",
"+print((dfs(\"0\")))"
] | false | 0.091683 | 0.100534 | 0.91196 | [
"s035158271",
"s367401768"
] |
u017810624 | p02695 | python | s317854809 | s770760639 | 275 | 167 | 103,152 | 85,992 | Accepted | Accepted | 39.27 | n,m,q=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
L=[]
for i in range(1,m+1):
if n==1:
L.append((i))
else:
for i2 in range(i,m+1):
if n==2:
L.append((i,i2))
else:
for i3 in range(i2,m+1):
if n==3:
L.append((i,i2,i3))
else:
for i4 in range(i3,m+1):
if n==4:
L.append((i,i2,i3,i4))
else:
for i5 in range(i4,m+1):
if n==5:
L.append((i,i2,i3,i4,i5))
else:
for i6 in range(i5,m+1):
if n==6:
L.append((i,i2,i3,i4,i5,i6))
else:
for i7 in range(i6,m+1):
if n==7:
L.append((i,i2,i3,i4,i5,i6,i7))
else:
for i8 in range(i7,m+1):
if n==8:
L.append((i,i2,i3,i4,i5,i6,i7,i8))
else:
for i9 in range(i8,m+1):
if n==9:
L.append((i,i2,i3,i4,i5,i6,i7,i8,i9))
else:
for i10 in range(i9,m+1):
L.append((i,i2,i3,i4,i5,i6,i7,i8,i9,i10))
ans=[]
for i in range(len(L)):
ct=0
for j in range(q):
if L[i][l[j][1]-1]-L[i][l[j][0]-1]==l[j][2]:
ct+=l[j][3]
ans.append(ct)
print((max(ans))) | import itertools
n,m,q=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
M=[i+1 for i in range(m)]
L=[]
for i in itertools.combinations_with_replacement(M,n):
L.append(i)
ans=[]
for i in range(len(L)):
ct=0
for j in range(q):
if L[i][l[j][1]-1]-L[i][l[j][0]-1]==l[j][2]:
ct+=l[j][3]
ans.append(ct)
print((max(ans))) | 49 | 15 | 1,676 | 373 | n, m, q = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(q)]
L = []
for i in range(1, m + 1):
if n == 1:
L.append((i))
else:
for i2 in range(i, m + 1):
if n == 2:
L.append((i, i2))
else:
for i3 in range(i2, m + 1):
if n == 3:
L.append((i, i2, i3))
else:
for i4 in range(i3, m + 1):
if n == 4:
L.append((i, i2, i3, i4))
else:
for i5 in range(i4, m + 1):
if n == 5:
L.append((i, i2, i3, i4, i5))
else:
for i6 in range(i5, m + 1):
if n == 6:
L.append((i, i2, i3, i4, i5, i6))
else:
for i7 in range(i6, m + 1):
if n == 7:
L.append(
(i, i2, i3, i4, i5, i6, i7)
)
else:
for i8 in range(i7, m + 1):
if n == 8:
L.append(
(
i,
i2,
i3,
i4,
i5,
i6,
i7,
i8,
)
)
else:
for i9 in range(
i8, m + 1
):
if n == 9:
L.append(
(
i,
i2,
i3,
i4,
i5,
i6,
i7,
i8,
i9,
)
)
else:
for (
i10
) in range(
i9, m + 1
):
L.append(
(
i,
i2,
i3,
i4,
i5,
i6,
i7,
i8,
i9,
i10,
)
)
ans = []
for i in range(len(L)):
ct = 0
for j in range(q):
if L[i][l[j][1] - 1] - L[i][l[j][0] - 1] == l[j][2]:
ct += l[j][3]
ans.append(ct)
print((max(ans)))
| import itertools
n, m, q = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(q)]
M = [i + 1 for i in range(m)]
L = []
for i in itertools.combinations_with_replacement(M, n):
L.append(i)
ans = []
for i in range(len(L)):
ct = 0
for j in range(q):
if L[i][l[j][1] - 1] - L[i][l[j][0] - 1] == l[j][2]:
ct += l[j][3]
ans.append(ct)
print((max(ans)))
| false | 69.387755 | [
"+import itertools",
"+",
"+M = [i + 1 for i in range(m)]",
"-for i in range(1, m + 1):",
"- if n == 1:",
"- L.append((i))",
"- else:",
"- for i2 in range(i, m + 1):",
"- if n == 2:",
"- L.append((i, i2))",
"- else:",
"- for i3 in range(i2, m + 1):",
"- if n == 3:",
"- L.append((i, i2, i3))",
"- else:",
"- for i4 in range(i3, m + 1):",
"- if n == 4:",
"- L.append((i, i2, i3, i4))",
"- else:",
"- for i5 in range(i4, m + 1):",
"- if n == 5:",
"- L.append((i, i2, i3, i4, i5))",
"- else:",
"- for i6 in range(i5, m + 1):",
"- if n == 6:",
"- L.append((i, i2, i3, i4, i5, i6))",
"- else:",
"- for i7 in range(i6, m + 1):",
"- if n == 7:",
"- L.append(",
"- (i, i2, i3, i4, i5, i6, i7)",
"- )",
"- else:",
"- for i8 in range(i7, m + 1):",
"- if n == 8:",
"- L.append(",
"- (",
"- i,",
"- i2,",
"- i3,",
"- i4,",
"- i5,",
"- i6,",
"- i7,",
"- i8,",
"- )",
"- )",
"- else:",
"- for i9 in range(",
"- i8, m + 1",
"- ):",
"- if n == 9:",
"- L.append(",
"- (",
"- i,",
"- i2,",
"- i3,",
"- i4,",
"- i5,",
"- i6,",
"- i7,",
"- i8,",
"- i9,",
"- )",
"- )",
"- else:",
"- for (",
"- i10",
"- ) in range(",
"- i9, m + 1",
"- ):",
"- L.append(",
"- (",
"- i,",
"- i2,",
"- i3,",
"- i4,",
"- i5,",
"- i6,",
"- i7,",
"- i8,",
"- i9,",
"- i10,",
"- )",
"- )",
"+for i in itertools.combinations_with_replacement(M, n):",
"+ L.append(i)"
] | false | 0.095533 | 0.065864 | 1.450462 | [
"s317854809",
"s770760639"
] |
u978178314 | p02761 | python | s433280068 | s702581801 | 201 | 173 | 41,456 | 38,384 | Accepted | Accepted | 13.93 | N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]
i = 10**(N-1) if N > 1 else 0
while i < 10**N:
n = [(i//10**j)%10 for j in reversed(list(range(N)))]
f = True
for s, c in SC:
if n[s-1] != c:
f = False
if f:
break
i += 1
if i >= 10**N:
print((-1))
else:
print(i) | N, M = list(map(int, input().split()))
num = [-1]*N
err = False
for _ in range(M):
s, c = list(map(int, input().split()))
if num[s-1] == -1:
num[s-1] = c
else:
if num[s-1] != c:
err = True
if err or (N > 1 and num[0] == 0):
print((-1))
else:
ans = 0
i = 0
n = 0
while i < N:
if num[i] < 0:
n = 1 if i == 0 and N > 1 else 0
else:
n = num[i]
ans = ans * 10 + n
i += 1
print(ans) | 16 | 24 | 344 | 445 | N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]
i = 10 ** (N - 1) if N > 1 else 0
while i < 10**N:
n = [(i // 10**j) % 10 for j in reversed(list(range(N)))]
f = True
for s, c in SC:
if n[s - 1] != c:
f = False
if f:
break
i += 1
if i >= 10**N:
print((-1))
else:
print(i)
| N, M = list(map(int, input().split()))
num = [-1] * N
err = False
for _ in range(M):
s, c = list(map(int, input().split()))
if num[s - 1] == -1:
num[s - 1] = c
else:
if num[s - 1] != c:
err = True
if err or (N > 1 and num[0] == 0):
print((-1))
else:
ans = 0
i = 0
n = 0
while i < N:
if num[i] < 0:
n = 1 if i == 0 and N > 1 else 0
else:
n = num[i]
ans = ans * 10 + n
i += 1
print(ans)
| false | 33.333333 | [
"-SC = [list(map(int, input().split())) for _ in range(M)]",
"-i = 10 ** (N - 1) if N > 1 else 0",
"-while i < 10**N:",
"- n = [(i // 10**j) % 10 for j in reversed(list(range(N)))]",
"- f = True",
"- for s, c in SC:",
"- if n[s - 1] != c:",
"- f = False",
"- if f:",
"- break",
"- i += 1",
"-if i >= 10**N:",
"+num = [-1] * N",
"+err = False",
"+for _ in range(M):",
"+ s, c = list(map(int, input().split()))",
"+ if num[s - 1] == -1:",
"+ num[s - 1] = c",
"+ else:",
"+ if num[s - 1] != c:",
"+ err = True",
"+if err or (N > 1 and num[0] == 0):",
"- print(i)",
"+ ans = 0",
"+ i = 0",
"+ n = 0",
"+ while i < N:",
"+ if num[i] < 0:",
"+ n = 1 if i == 0 and N > 1 else 0",
"+ else:",
"+ n = num[i]",
"+ ans = ans * 10 + n",
"+ i += 1",
"+ print(ans)"
] | false | 0.037756 | 0.071249 | 0.52992 | [
"s433280068",
"s702581801"
] |
u975445930 | p02682 | python | s588575400 | s349425548 | 24 | 21 | 9,172 | 9,068 | Accepted | Accepted | 12.5 | a,b,c,k = list(map(int, input().split()))
if k<=a:
print(k)
elif a < k and k <= a+b:
print(a)
elif k > a+b:
print((a-(k-a-b))) | a,b,c,k = list(map(int, input().split()))
A = min(a,k)
k -= A
B = min(b,k)
k -= B
print((A-k)) | 7 | 6 | 136 | 91 | a, b, c, k = list(map(int, input().split()))
if k <= a:
print(k)
elif a < k and k <= a + b:
print(a)
elif k > a + b:
print((a - (k - a - b)))
| a, b, c, k = list(map(int, input().split()))
A = min(a, k)
k -= A
B = min(b, k)
k -= B
print((A - k))
| false | 14.285714 | [
"-if k <= a:",
"- print(k)",
"-elif a < k and k <= a + b:",
"- print(a)",
"-elif k > a + b:",
"- print((a - (k - a - b)))",
"+A = min(a, k)",
"+k -= A",
"+B = min(b, k)",
"+k -= B",
"+print((A - k))"
] | false | 0.038046 | 0.038266 | 0.994273 | [
"s588575400",
"s349425548"
] |
u670180528 | p03785 | python | s446187815 | s371299953 | 129 | 101 | 14,436 | 14,436 | Accepted | Accepted | 21.71 | from collections import deque
n,c,k,*t = list(map(int,open(0).read().split()))
d = deque(sorted(t)+[float("inf")])
f = d[0]
cnt = ans = 0
while d:
if d[0]-f <= k:
del d[0]
cnt += 1
if cnt == c:
f = d[0]
cnt = 0
ans += 1
else:
f = d.popleft()
cnt = 1
ans += 1
print((ans-(c==1))) | from collections import deque
def solve():
n,c,k,*t = list(map(int,open(0).read().split()))
d = deque(sorted(t)+[float("inf")])
fir = d[0]
cnt = ans = 0
while d:
if d[0]-fir <= k:
del d[0]
cnt += 1
if cnt == c:
fir = d[0]
cnt = 0
ans += 1
else:
fir = d.popleft()
cnt = 1
ans += 1
print((ans-(c==1)))
if __name__=="__main__":
solve() | 18 | 24 | 310 | 392 | from collections import deque
n, c, k, *t = list(map(int, open(0).read().split()))
d = deque(sorted(t) + [float("inf")])
f = d[0]
cnt = ans = 0
while d:
if d[0] - f <= k:
del d[0]
cnt += 1
if cnt == c:
f = d[0]
cnt = 0
ans += 1
else:
f = d.popleft()
cnt = 1
ans += 1
print((ans - (c == 1)))
| from collections import deque
def solve():
n, c, k, *t = list(map(int, open(0).read().split()))
d = deque(sorted(t) + [float("inf")])
fir = d[0]
cnt = ans = 0
while d:
if d[0] - fir <= k:
del d[0]
cnt += 1
if cnt == c:
fir = d[0]
cnt = 0
ans += 1
else:
fir = d.popleft()
cnt = 1
ans += 1
print((ans - (c == 1)))
if __name__ == "__main__":
solve()
| false | 25 | [
"-n, c, k, *t = list(map(int, open(0).read().split()))",
"-d = deque(sorted(t) + [float(\"inf\")])",
"-f = d[0]",
"-cnt = ans = 0",
"-while d:",
"- if d[0] - f <= k:",
"- del d[0]",
"- cnt += 1",
"- if cnt == c:",
"- f = d[0]",
"- cnt = 0",
"+",
"+def solve():",
"+ n, c, k, *t = list(map(int, open(0).read().split()))",
"+ d = deque(sorted(t) + [float(\"inf\")])",
"+ fir = d[0]",
"+ cnt = ans = 0",
"+ while d:",
"+ if d[0] - fir <= k:",
"+ del d[0]",
"+ cnt += 1",
"+ if cnt == c:",
"+ fir = d[0]",
"+ cnt = 0",
"+ ans += 1",
"+ else:",
"+ fir = d.popleft()",
"+ cnt = 1",
"- else:",
"- f = d.popleft()",
"- cnt = 1",
"- ans += 1",
"-print((ans - (c == 1)))",
"+ print((ans - (c == 1)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.091604 | 0.118891 | 0.770481 | [
"s446187815",
"s371299953"
] |
u141786930 | p03078 | python | s293616715 | s666091381 | 1,761 | 740 | 158,892 | 8,508 | Accepted | Accepted | 57.98 | # D - Cake 123
import heapq
import itertools
x, y, z, k = list(map(int, input().split()))
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
C = list(int(c) for c in input().split())
hq = []
for i, j in itertools.product(A, B):
heapq.heappush(hq, (i+j)*-1)
AB = []
while len(hq)>0 and len(AB)<=k:
AB.append(heapq.heappop(hq)*-1)
hq = []
for i, j in itertools.product(AB, C):
heapq.heappush(hq, (i+j)*-1)
for _ in range(k):
print((heapq.heappop(hq)*-1)) | # D - Cake 123
import heapq
import itertools
x, y, z, k = list(map(int, input().split()))
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
C = list(int(c) for c in input().split())
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
hq = []
for i in range(x):
for j in range(y):
for l in range(z):
if (i+1)*(j+1)*(l+1)<=k:
heapq.heappush(hq, (A[i]+B[j]+C[l])*-1)
else:
break
'''
hq = []
for i, j in itertools.product(A, B):
heapq.heappush(hq, (i+j)*-1)
AB = []
while len(hq)>0 and len(AB)<=k:
AB.append(heapq.heappop(hq)*-1)
hq = []
for i, j in itertools.product(AB, C):
heapq.heappush(hq, (i+j)*-1)
'''
for _ in range(k):
print((heapq.heappop(hq)*-1))
| 25 | 41 | 524 | 825 | # D - Cake 123
import heapq
import itertools
x, y, z, k = list(map(int, input().split()))
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
C = list(int(c) for c in input().split())
hq = []
for i, j in itertools.product(A, B):
heapq.heappush(hq, (i + j) * -1)
AB = []
while len(hq) > 0 and len(AB) <= k:
AB.append(heapq.heappop(hq) * -1)
hq = []
for i, j in itertools.product(AB, C):
heapq.heappush(hq, (i + j) * -1)
for _ in range(k):
print((heapq.heappop(hq) * -1))
| # D - Cake 123
import heapq
import itertools
x, y, z, k = list(map(int, input().split()))
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
C = list(int(c) for c in input().split())
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
hq = []
for i in range(x):
for j in range(y):
for l in range(z):
if (i + 1) * (j + 1) * (l + 1) <= k:
heapq.heappush(hq, (A[i] + B[j] + C[l]) * -1)
else:
break
"""
hq = []
for i, j in itertools.product(A, B):
heapq.heappush(hq, (i+j)*-1)
AB = []
while len(hq)>0 and len(AB)<=k:
AB.append(heapq.heappop(hq)*-1)
hq = []
for i, j in itertools.product(AB, C):
heapq.heappush(hq, (i+j)*-1)
"""
for _ in range(k):
print((heapq.heappop(hq) * -1))
| false | 39.02439 | [
"+A.sort(reverse=True)",
"+B.sort(reverse=True)",
"+C.sort(reverse=True)",
"+hq = []",
"+for i in range(x):",
"+ for j in range(y):",
"+ for l in range(z):",
"+ if (i + 1) * (j + 1) * (l + 1) <= k:",
"+ heapq.heappush(hq, (A[i] + B[j] + C[l]) * -1)",
"+ else:",
"+ break",
"+\"\"\"",
"- heapq.heappush(hq, (i + j) * -1)",
"+ heapq.heappush(hq, (i+j)*-1)",
"-while len(hq) > 0 and len(AB) <= k:",
"- AB.append(heapq.heappop(hq) * -1)",
"+while len(hq)>0 and len(AB)<=k:",
"+ AB.append(heapq.heappop(hq)*-1)",
"- heapq.heappush(hq, (i + j) * -1)",
"+ heapq.heappush(hq, (i+j)*-1)",
"+\"\"\""
] | false | 0.065132 | 0.057182 | 1.139042 | [
"s293616715",
"s666091381"
] |
u644907318 | p03937 | python | s002240082 | s741775731 | 167 | 66 | 38,356 | 62,312 | Accepted | Accepted | 60.48 | H,W = list(map(int,input().split()))
A = [input().strip() for _ in range(H)]
r = 0
c = 0
for i in range(H):
for j in range(1,W):
if A[i][j]==A[i][j-1]=="#":
r += 1
for j in range(W):
for i in range(1,H):
if A[i][j]==A[i-1][j]=="#":
c += 1
if r==W-1 and c==H-1:
print("Possible")
else:
print("Impossible") | H,W = list(map(int,input().split()))
A = [list(input().strip()) for _ in range(H)]
x = [0,0]
A[0][0] = "."
while True:
if x[0]==H-1 and x[1]==W-1:break
if x[0]<H-1 and A[x[0]+1][x[1]]=="#":
A[x[0]+1][x[1]]="."
x = [x[0]+1,x[1]]
elif x[1]<W-1 and A[x[0]][x[1]+1]=="#":
A[x[0]][x[1]+1]="."
x = [x[0],x[1]+1]
elif (x[0]<H-1 and A[x[0]+1][x[1]]==".") and (x[1]<W-1 and A[x[0]][x[1]+1]=="."):
break
elif (x[0]==H-1 and x[1]<W-1 and A[x[0]][x[1]+1]==".") or (x[1]==W-1 and x[0]<H-1 and A[x[0]+1][x[1]]=="."):
break
flag = 0
for i in range(H):
for j in range(W):
if A[i][j]=="#":
flag = 1
break
if flag==1:break
if flag==0:
print("Possible")
else:
print("Impossible") | 16 | 27 | 369 | 796 | H, W = list(map(int, input().split()))
A = [input().strip() for _ in range(H)]
r = 0
c = 0
for i in range(H):
for j in range(1, W):
if A[i][j] == A[i][j - 1] == "#":
r += 1
for j in range(W):
for i in range(1, H):
if A[i][j] == A[i - 1][j] == "#":
c += 1
if r == W - 1 and c == H - 1:
print("Possible")
else:
print("Impossible")
| H, W = list(map(int, input().split()))
A = [list(input().strip()) for _ in range(H)]
x = [0, 0]
A[0][0] = "."
while True:
if x[0] == H - 1 and x[1] == W - 1:
break
if x[0] < H - 1 and A[x[0] + 1][x[1]] == "#":
A[x[0] + 1][x[1]] = "."
x = [x[0] + 1, x[1]]
elif x[1] < W - 1 and A[x[0]][x[1] + 1] == "#":
A[x[0]][x[1] + 1] = "."
x = [x[0], x[1] + 1]
elif (x[0] < H - 1 and A[x[0] + 1][x[1]] == ".") and (
x[1] < W - 1 and A[x[0]][x[1] + 1] == "."
):
break
elif (x[0] == H - 1 and x[1] < W - 1 and A[x[0]][x[1] + 1] == ".") or (
x[1] == W - 1 and x[0] < H - 1 and A[x[0] + 1][x[1]] == "."
):
break
flag = 0
for i in range(H):
for j in range(W):
if A[i][j] == "#":
flag = 1
break
if flag == 1:
break
if flag == 0:
print("Possible")
else:
print("Impossible")
| false | 40.740741 | [
"-A = [input().strip() for _ in range(H)]",
"-r = 0",
"-c = 0",
"+A = [list(input().strip()) for _ in range(H)]",
"+x = [0, 0]",
"+A[0][0] = \".\"",
"+while True:",
"+ if x[0] == H - 1 and x[1] == W - 1:",
"+ break",
"+ if x[0] < H - 1 and A[x[0] + 1][x[1]] == \"#\":",
"+ A[x[0] + 1][x[1]] = \".\"",
"+ x = [x[0] + 1, x[1]]",
"+ elif x[1] < W - 1 and A[x[0]][x[1] + 1] == \"#\":",
"+ A[x[0]][x[1] + 1] = \".\"",
"+ x = [x[0], x[1] + 1]",
"+ elif (x[0] < H - 1 and A[x[0] + 1][x[1]] == \".\") and (",
"+ x[1] < W - 1 and A[x[0]][x[1] + 1] == \".\"",
"+ ):",
"+ break",
"+ elif (x[0] == H - 1 and x[1] < W - 1 and A[x[0]][x[1] + 1] == \".\") or (",
"+ x[1] == W - 1 and x[0] < H - 1 and A[x[0] + 1][x[1]] == \".\"",
"+ ):",
"+ break",
"+flag = 0",
"- for j in range(1, W):",
"- if A[i][j] == A[i][j - 1] == \"#\":",
"- r += 1",
"-for j in range(W):",
"- for i in range(1, H):",
"- if A[i][j] == A[i - 1][j] == \"#\":",
"- c += 1",
"-if r == W - 1 and c == H - 1:",
"+ for j in range(W):",
"+ if A[i][j] == \"#\":",
"+ flag = 1",
"+ break",
"+ if flag == 1:",
"+ break",
"+if flag == 0:"
] | false | 0.041895 | 0.036909 | 1.135094 | [
"s002240082",
"s741775731"
] |
u936985471 | p03167 | python | s087781327 | s634642434 | 685 | 598 | 49,448 | 49,696 | Accepted | Accepted | 12.7 | import sys
readline = sys.stdin.readline
H,W = list(map(int,readline().split()))
DIV = 10 ** 9 + 7
G = [None] * H
for i in range(H):
G[i] = readline().rstrip()
dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][1] = 1
for i in range(H):
for j in range(W):
if G[i][j] == "#":
dp[i + 1][j + 1] = 0
else:
dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1]
dp[i + 1][j + 1] %= DIV
print((dp[-1][-1]))
| import sys
readline = sys.stdin.readline
H,W = list(map(int,readline().split()))
G = [readline().rstrip() for i in range(H)]
DIV = 10 ** 9 + 7
dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][1] = 1
for i in range(H):
for j in range(W):
if G[i][j] == "#":
dp[i + 1][j + 1] = 0
continue
dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
dp[i + 1][j + 1] %= DIV
print((dp[-1][-1])) | 21 | 18 | 443 | 418 | import sys
readline = sys.stdin.readline
H, W = list(map(int, readline().split()))
DIV = 10**9 + 7
G = [None] * H
for i in range(H):
G[i] = readline().rstrip()
dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][1] = 1
for i in range(H):
for j in range(W):
if G[i][j] == "#":
dp[i + 1][j + 1] = 0
else:
dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1]
dp[i + 1][j + 1] %= DIV
print((dp[-1][-1]))
| import sys
readline = sys.stdin.readline
H, W = list(map(int, readline().split()))
G = [readline().rstrip() for i in range(H)]
DIV = 10**9 + 7
dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][1] = 1
for i in range(H):
for j in range(W):
if G[i][j] == "#":
dp[i + 1][j + 1] = 0
continue
dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
dp[i + 1][j + 1] %= DIV
print((dp[-1][-1]))
| false | 14.285714 | [
"+G = [readline().rstrip() for i in range(H)]",
"-G = [None] * H",
"-for i in range(H):",
"- G[i] = readline().rstrip()",
"- else:",
"- dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1]",
"- dp[i + 1][j + 1] %= DIV",
"+ continue",
"+ dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]",
"+ dp[i + 1][j + 1] %= DIV"
] | false | 0.044772 | 0.044424 | 1.007823 | [
"s087781327",
"s634642434"
] |
u525065967 | p02603 | python | s072157970 | s461115133 | 32 | 28 | 9,056 | 9,108 | Accepted | Accepted | 12.5 | n = int(eval(input()))
A = [0] + [*list(map(int, input().split()))]
dp_stock = [0]*(n+1)
dp_yen = [0]*(n+1)
dp_yen[0] = 1000
for day in range(1, n+1):
dp_stock[day] = max(dp_stock[day-1], dp_yen[day-1] // A[day])
remain = dp_yen[day-1] - dp_stock[day-1]*A[day-1]
dp_yen[day] = max(dp_yen[day-1], remain + dp_stock[day-1] * A[day])
print((dp_yen[n]))
| n = int(eval(input()))
A = [0] + [*list(map(int, input().split()))] + [0]
dp_yen = [0]*(n+1)
dp_yen[1] = 1000
for day in range(1, n):
stock = 0
if A[day] > 0: stock = dp_yen[day] // A[day]
remain = dp_yen[day] - stock*A[day]
dp_yen[day+1] = max(dp_yen[day], remain + stock * A[day+1])
print((dp_yen[n]))
| 10 | 10 | 357 | 315 | n = int(eval(input()))
A = [0] + [*list(map(int, input().split()))]
dp_stock = [0] * (n + 1)
dp_yen = [0] * (n + 1)
dp_yen[0] = 1000
for day in range(1, n + 1):
dp_stock[day] = max(dp_stock[day - 1], dp_yen[day - 1] // A[day])
remain = dp_yen[day - 1] - dp_stock[day - 1] * A[day - 1]
dp_yen[day] = max(dp_yen[day - 1], remain + dp_stock[day - 1] * A[day])
print((dp_yen[n]))
| n = int(eval(input()))
A = [0] + [*list(map(int, input().split()))] + [0]
dp_yen = [0] * (n + 1)
dp_yen[1] = 1000
for day in range(1, n):
stock = 0
if A[day] > 0:
stock = dp_yen[day] // A[day]
remain = dp_yen[day] - stock * A[day]
dp_yen[day + 1] = max(dp_yen[day], remain + stock * A[day + 1])
print((dp_yen[n]))
| false | 0 | [
"-A = [0] + [*list(map(int, input().split()))]",
"-dp_stock = [0] * (n + 1)",
"+A = [0] + [*list(map(int, input().split()))] + [0]",
"-dp_yen[0] = 1000",
"-for day in range(1, n + 1):",
"- dp_stock[day] = max(dp_stock[day - 1], dp_yen[day - 1] // A[day])",
"- remain = dp_yen[day - 1] - dp_stock[day - 1] * A[day - 1]",
"- dp_yen[day] = max(dp_yen[day - 1], remain + dp_stock[day - 1] * A[day])",
"+dp_yen[1] = 1000",
"+for day in range(1, n):",
"+ stock = 0",
"+ if A[day] > 0:",
"+ stock = dp_yen[day] // A[day]",
"+ remain = dp_yen[day] - stock * A[day]",
"+ dp_yen[day + 1] = max(dp_yen[day], remain + stock * A[day + 1])"
] | false | 0.04153 | 0.036596 | 1.134829 | [
"s072157970",
"s461115133"
] |
u957167787 | p03408 | python | s912276667 | s135139969 | 20 | 17 | 3,060 | 3,060 | Accepted | Accepted | 15 | N = int(eval(input())) # 青いカードの枚数
s = [eval(input()) for _ in range(N)] # 青いカードに書かれている文字列
M = int(eval(input())) # 赤いカードの枚数
t = [eval(input()) for _ in range(M)]
count = [s.count(s[i]) - t.count(s[i]) for i in range(N)] # sにある要素で得点をリストに入れる(tのみにある文字列は答えになり得ない)
ans = max(0, max(count)) # countが全て負だったら0を返す
print(ans)
| N = int(eval(input())) # 青いカードの枚数
s = [eval(input()) for _ in range(N)] # 青いカードに書かれている文字列
M = int(eval(input())) # 赤いカードの枚数
t = [eval(input()) for _ in range(M)]
sset = list(set(s)) # set型のままではインデックスを選べないので注意,この文はなくても良いがforループの短縮に繋がる
count = [s.count(sset[i]) - t.count(sset[i]) for i in range(len(sset))] # sにある要素で得点をリストに入れる(tのみにある文字列は答えになり得ない)
ans = max(0, max(count)) # countの最大値が負だったら0を返す
print(ans)
| 9 | 10 | 302 | 391 | N = int(eval(input())) # 青いカードの枚数
s = [eval(input()) for _ in range(N)] # 青いカードに書かれている文字列
M = int(eval(input())) # 赤いカードの枚数
t = [eval(input()) for _ in range(M)]
count = [
s.count(s[i]) - t.count(s[i]) for i in range(N)
] # sにある要素で得点をリストに入れる(tのみにある文字列は答えになり得ない)
ans = max(0, max(count)) # countが全て負だったら0を返す
print(ans)
| N = int(eval(input())) # 青いカードの枚数
s = [eval(input()) for _ in range(N)] # 青いカードに書かれている文字列
M = int(eval(input())) # 赤いカードの枚数
t = [eval(input()) for _ in range(M)]
sset = list(set(s)) # set型のままではインデックスを選べないので注意,この文はなくても良いがforループの短縮に繋がる
count = [
s.count(sset[i]) - t.count(sset[i]) for i in range(len(sset))
] # sにある要素で得点をリストに入れる(tのみにある文字列は答えになり得ない)
ans = max(0, max(count)) # countの最大値が負だったら0を返す
print(ans)
| false | 10 | [
"+sset = list(set(s)) # set型のままではインデックスを選べないので注意,この文はなくても良いがforループの短縮に繋がる",
"- s.count(s[i]) - t.count(s[i]) for i in range(N)",
"+ s.count(sset[i]) - t.count(sset[i]) for i in range(len(sset))",
"-ans = max(0, max(count)) # countが全て負だったら0を返す",
"+ans = max(0, max(count)) # countの最大値が負だったら0を返す"
] | false | 0.050279 | 0.049774 | 1.010135 | [
"s912276667",
"s135139969"
] |
u133936772 | p03212 | python | s351507827 | s602681081 | 103 | 50 | 3,060 | 3,060 | Accepted | Accepted | 51.46 | n = int(eval(input()))
import itertools as it
ans = 0
for i in range(11):
for p in it.product(*['357']*i):
if len(set(p))>2 and int(''.join(p))<=n:
ans += 1
print(ans) | n = eval(input())
import itertools as it
print((sum(len(set(p))>2 and int(''.join(p))<=int(n) for i in range(len(n)+1) for p in it.product('357',repeat=i)))) | 8 | 3 | 180 | 151 | n = int(eval(input()))
import itertools as it
ans = 0
for i in range(11):
for p in it.product(*["357"] * i):
if len(set(p)) > 2 and int("".join(p)) <= n:
ans += 1
print(ans)
| n = eval(input())
import itertools as it
print(
(
sum(
len(set(p)) > 2 and int("".join(p)) <= int(n)
for i in range(len(n) + 1)
for p in it.product("357", repeat=i)
)
)
)
| false | 62.5 | [
"-n = int(eval(input()))",
"+n = eval(input())",
"-ans = 0",
"-for i in range(11):",
"- for p in it.product(*[\"357\"] * i):",
"- if len(set(p)) > 2 and int(\"\".join(p)) <= n:",
"- ans += 1",
"-print(ans)",
"+print(",
"+ (",
"+ sum(",
"+ len(set(p)) > 2 and int(\"\".join(p)) <= int(n)",
"+ for i in range(len(n) + 1)",
"+ for p in it.product(\"357\", repeat=i)",
"+ )",
"+ )",
"+)"
] | false | 0.151804 | 0.038194 | 3.97456 | [
"s351507827",
"s602681081"
] |
u368796742 | p02821 | python | s886460501 | s860469127 | 440 | 347 | 23,420 | 23,412 | Accepted | Accepted | 21.14 | def main():
import bisect
import numpy as np
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
l.sort()
l1 = np.array(l)
def bise(x):
y = np.searchsorted(l1,x-l1)
return n*n-y.sum()
left = -1
right = l[-1]*2+1
while right > left+1:
mid = (right+left)//2
if bise(mid) >= k:
left = mid
else:
right = mid
ans = 0
count = 0
acc = [0]
for i in l:
acc.append(acc[-1]+i)
for i in l:
index = bisect.bisect_left(l,right-i)
ans += i*(n-index) + acc[n]-acc[index]
count += n-index
print((ans-(count-k)*left))
if __name__ == "__main__":
main() | def main():
import bisect
import numpy as np
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
l.sort()
l = np.array(l)
def bise(x):
y = np.searchsorted(l,x-l)
return n*n-y.sum()
left = -1
right = l[-1]*2+1
while right > left+1:
mid = (right+left)//2
if bise(mid) >= k:
left = mid
else:
right = mid
ans = 0
acc = np.zeros(n+1,np.int64)
acc[1:] = l.cumsum()
x = np.searchsorted(l,right-l)
count = n*n-x.sum()
ans = (acc[-1]-acc[x]).sum() + (l*(n-x)).sum()
print((ans-(count-k)*left))
if __name__ == "__main__":
main() | 34 | 32 | 754 | 714 | def main():
import bisect
import numpy as np
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
l1 = np.array(l)
def bise(x):
y = np.searchsorted(l1, x - l1)
return n * n - y.sum()
left = -1
right = l[-1] * 2 + 1
while right > left + 1:
mid = (right + left) // 2
if bise(mid) >= k:
left = mid
else:
right = mid
ans = 0
count = 0
acc = [0]
for i in l:
acc.append(acc[-1] + i)
for i in l:
index = bisect.bisect_left(l, right - i)
ans += i * (n - index) + acc[n] - acc[index]
count += n - index
print((ans - (count - k) * left))
if __name__ == "__main__":
main()
| def main():
import bisect
import numpy as np
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
l = np.array(l)
def bise(x):
y = np.searchsorted(l, x - l)
return n * n - y.sum()
left = -1
right = l[-1] * 2 + 1
while right > left + 1:
mid = (right + left) // 2
if bise(mid) >= k:
left = mid
else:
right = mid
ans = 0
acc = np.zeros(n + 1, np.int64)
acc[1:] = l.cumsum()
x = np.searchsorted(l, right - l)
count = n * n - x.sum()
ans = (acc[-1] - acc[x]).sum() + (l * (n - x)).sum()
print((ans - (count - k) * left))
if __name__ == "__main__":
main()
| false | 5.882353 | [
"- l1 = np.array(l)",
"+ l = np.array(l)",
"- y = np.searchsorted(l1, x - l1)",
"+ y = np.searchsorted(l, x - l)",
"- count = 0",
"- acc = [0]",
"- for i in l:",
"- acc.append(acc[-1] + i)",
"- for i in l:",
"- index = bisect.bisect_left(l, right - i)",
"- ans += i * (n - index) + acc[n] - acc[index]",
"- count += n - index",
"+ acc = np.zeros(n + 1, np.int64)",
"+ acc[1:] = l.cumsum()",
"+ x = np.searchsorted(l, right - l)",
"+ count = n * n - x.sum()",
"+ ans = (acc[-1] - acc[x]).sum() + (l * (n - x)).sum()"
] | false | 0.261779 | 0.483343 | 0.541602 | [
"s886460501",
"s860469127"
] |
u539367121 | p02989 | python | s926675450 | s143051198 | 116 | 68 | 20,668 | 20,708 | Accepted | Accepted | 41.38 | from bisect import bisect_left
n=int(eval(input()))
d=list(map(int,input().split()))
d=sorted(d)
ans=0
for i in range(1,10**5+1):
p=bisect_left(d,i)
ans+=1 if p==(n-p) else 0
print(ans) | n=int(eval(input()))
d=sorted(list(map(int,input().split())))
ans=d[n//2]-d[n//2-1]
print(ans)
| 12 | 4 | 197 | 92 | from bisect import bisect_left
n = int(eval(input()))
d = list(map(int, input().split()))
d = sorted(d)
ans = 0
for i in range(1, 10**5 + 1):
p = bisect_left(d, i)
ans += 1 if p == (n - p) else 0
print(ans)
| n = int(eval(input()))
d = sorted(list(map(int, input().split())))
ans = d[n // 2] - d[n // 2 - 1]
print(ans)
| false | 66.666667 | [
"-from bisect import bisect_left",
"-",
"-d = list(map(int, input().split()))",
"-d = sorted(d)",
"-ans = 0",
"-for i in range(1, 10**5 + 1):",
"- p = bisect_left(d, i)",
"- ans += 1 if p == (n - p) else 0",
"+d = sorted(list(map(int, input().split())))",
"+ans = d[n // 2] - d[n // 2 - 1]"
] | false | 0.073647 | 0.044044 | 1.672105 | [
"s926675450",
"s143051198"
] |
u562935282 | p03095 | python | s354817481 | s015791514 | 751 | 28 | 3,444 | 3,820 | Accepted | Accepted | 96.27 | from collections import defaultdict
mod = 10 ** 9 + 7
n = int(eval(input()))
s = eval(input())
d = defaultdict(int)
ans = 0
for c in s:
d[c] += 1
t = 1
for chr_, cnt in list(d.items()):
if chr_ == c:
continue
t *= cnt + 1
ans = (ans + t) % mod
print(ans)
| from collections import Counter
from functools import reduce
from operator import mul
mod = 10 ** 9 + 7
def my_mul(a, b):
return a * b % mod
n = int(eval(input()))
s = eval(input())
cnt = Counter(s)
print((reduce(my_mul, (v + 1 for v in list(cnt.values()))) - 1))
# 同じ文字列でも、異なる位置から作られたものは区別するため、2
# N − 1 通りのすべての部分列が区別され
# ることになります。
# 条件より、同じ文字を 2 度使ってはいけないため、ある文字 c について colorful の条件を壊さないとり方
# は (c の出現回数 + 1) となります (どれか 1 つを取るケース及び文字 c を一切取らないケース)
# すべての文字 c についてのこのとり方の積を求め、空文字列の分の 1 を引いた数が答えとなります。
| 19 | 24 | 303 | 517 | from collections import defaultdict
mod = 10**9 + 7
n = int(eval(input()))
s = eval(input())
d = defaultdict(int)
ans = 0
for c in s:
d[c] += 1
t = 1
for chr_, cnt in list(d.items()):
if chr_ == c:
continue
t *= cnt + 1
ans = (ans + t) % mod
print(ans)
| from collections import Counter
from functools import reduce
from operator import mul
mod = 10**9 + 7
def my_mul(a, b):
return a * b % mod
n = int(eval(input()))
s = eval(input())
cnt = Counter(s)
print((reduce(my_mul, (v + 1 for v in list(cnt.values()))) - 1))
# 同じ文字列でも、異なる位置から作られたものは区別するため、2
# N − 1 通りのすべての部分列が区別され
# ることになります。
# 条件より、同じ文字を 2 度使ってはいけないため、ある文字 c について colorful の条件を壊さないとり方
# は (c の出現回数 + 1) となります (どれか 1 つを取るケース及び文字 c を一切取らないケース)
# すべての文字 c についてのこのとり方の積を求め、空文字列の分の 1 を引いた数が答えとなります。
| false | 20.833333 | [
"-from collections import defaultdict",
"+from collections import Counter",
"+from functools import reduce",
"+from operator import mul",
"+",
"+",
"+def my_mul(a, b):",
"+ return a * b % mod",
"+",
"+",
"-d = defaultdict(int)",
"-ans = 0",
"-for c in s:",
"- d[c] += 1",
"- t = 1",
"- for chr_, cnt in list(d.items()):",
"- if chr_ == c:",
"- continue",
"- t *= cnt + 1",
"- ans = (ans + t) % mod",
"-print(ans)",
"+cnt = Counter(s)",
"+print((reduce(my_mul, (v + 1 for v in list(cnt.values()))) - 1))",
"+# 同じ文字列でも、異なる位置から作られたものは区別するため、2",
"+# N − 1 通りのすべての部分列が区別され",
"+# ることになります。",
"+# 条件より、同じ文字を 2 度使ってはいけないため、ある文字 c について colorful の条件を壊さないとり方",
"+# は (c の出現回数 + 1) となります (どれか 1 つを取るケース及び文字 c を一切取らないケース)",
"+# すべての文字 c についてのこのとり方の積を求め、空文字列の分の 1 を引いた数が答えとなります。"
] | false | 0.040194 | 0.040031 | 1.004083 | [
"s354817481",
"s015791514"
] |
u952708174 | p03331 | python | s516562927 | s695701216 | 289 | 17 | 3,188 | 3,060 | Accepted | Accepted | 94.12 | def a_digits_sum(N):
def digit_sum(n): # 非負整数nの各桁の和
str_n = str(n)
ret = 0
for c in str_n:
ret += int(c)
return ret
ans = float('inf')
for A in range(1, N):
B = N - A
ans = min(ans, digit_sum(A) + digit_sum(B))
return ans
N = int(eval(input()))
print((a_digits_sum(N))) | def a_digits_sum(N):
# A+B のk桁目を c_k、Nのk桁目をn_kとおくと、筆算の考え方より、
# c_k=n_k となるようにすればいい。つまり解はNの各桁の和に等しい。
# ただし、Nが10の冪乗のときは、上の考え方では片方がNに等しくなってしまう。
# この場合、 N=10^k とすると、 A=a*10^(k-1), B=b*10^(k-1) (ただし a+b=10)
# の形にするしかない。よってA+Bの各桁の和は常に10。
ans = 0
n = str(N)
for c in n:
ans += int(c)
if ans == 1:
# 最上位桁に1が出て、その後0しか出ていない。Nは10の冪乗だった
ans = 10
return ans
N = int(eval(input()))
print((a_digits_sum(N))) | 16 | 17 | 355 | 465 | def a_digits_sum(N):
def digit_sum(n): # 非負整数nの各桁の和
str_n = str(n)
ret = 0
for c in str_n:
ret += int(c)
return ret
ans = float("inf")
for A in range(1, N):
B = N - A
ans = min(ans, digit_sum(A) + digit_sum(B))
return ans
N = int(eval(input()))
print((a_digits_sum(N)))
| def a_digits_sum(N):
# A+B のk桁目を c_k、Nのk桁目をn_kとおくと、筆算の考え方より、
# c_k=n_k となるようにすればいい。つまり解はNの各桁の和に等しい。
# ただし、Nが10の冪乗のときは、上の考え方では片方がNに等しくなってしまう。
# この場合、 N=10^k とすると、 A=a*10^(k-1), B=b*10^(k-1) (ただし a+b=10)
# の形にするしかない。よってA+Bの各桁の和は常に10。
ans = 0
n = str(N)
for c in n:
ans += int(c)
if ans == 1:
# 最上位桁に1が出て、その後0しか出ていない。Nは10の冪乗だった
ans = 10
return ans
N = int(eval(input()))
print((a_digits_sum(N)))
| false | 5.882353 | [
"- def digit_sum(n): # 非負整数nの各桁の和",
"- str_n = str(n)",
"- ret = 0",
"- for c in str_n:",
"- ret += int(c)",
"- return ret",
"-",
"- ans = float(\"inf\")",
"- for A in range(1, N):",
"- B = N - A",
"- ans = min(ans, digit_sum(A) + digit_sum(B))",
"+ # A+B のk桁目を c_k、Nのk桁目をn_kとおくと、筆算の考え方より、",
"+ # c_k=n_k となるようにすればいい。つまり解はNの各桁の和に等しい。",
"+ # ただし、Nが10の冪乗のときは、上の考え方では片方がNに等しくなってしまう。",
"+ # この場合、 N=10^k とすると、 A=a*10^(k-1), B=b*10^(k-1) (ただし a+b=10)",
"+ # の形にするしかない。よってA+Bの各桁の和は常に10。",
"+ ans = 0",
"+ n = str(N)",
"+ for c in n:",
"+ ans += int(c)",
"+ if ans == 1:",
"+ # 最上位桁に1が出て、その後0しか出ていない。Nは10の冪乗だった",
"+ ans = 10"
] | false | 0.101347 | 0.035937 | 2.820106 | [
"s516562927",
"s695701216"
] |
u086566114 | p02412 | python | s728305362 | s199712455 | 30 | 20 | 6,416 | 6,356 | Accepted | Accepted | 33.33 | def get_num(n, x):
ans = 0
for n3 in range(min(n, x - 2), (x + 2) / 3, -1):
for n2 in range(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
for n1 in range(min(n2 - 1, x - n3 - n2), 0, -1):
if n3 == x - n1 - n2:
ans += 1
break
return ans
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
if x < 3:
print((0))
else:
print((get_num(n, x))) | def get_num(n, x):
ans = 0
for n3 in range(min(n, x - 3), (x + 2) / 3, -1):
for n2 in range(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
for n1 in range(min(n2 - 1, x - n3 - n2), 0, -1):
if n3 == x - n1 - n2:
ans += 1
break
return ans
data = []
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
if x < 3:
# print(0)
data.append(0)
else:
# print(get_num(n, x))
data.append(get_num(n, x))
for n in data:
print(n) | 19 | 24 | 524 | 629 | def get_num(n, x):
ans = 0
for n3 in range(min(n, x - 2), (x + 2) / 3, -1):
for n2 in range(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
for n1 in range(min(n2 - 1, x - n3 - n2), 0, -1):
if n3 == x - n1 - n2:
ans += 1
break
return ans
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
if x < 3:
print((0))
else:
print((get_num(n, x)))
| def get_num(n, x):
ans = 0
for n3 in range(min(n, x - 3), (x + 2) / 3, -1):
for n2 in range(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
for n1 in range(min(n2 - 1, x - n3 - n2), 0, -1):
if n3 == x - n1 - n2:
ans += 1
break
return ans
data = []
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
if x < 3:
# print(0)
data.append(0)
else:
# print(get_num(n, x))
data.append(get_num(n, x))
for n in data:
print(n)
| false | 20.833333 | [
"- for n3 in range(min(n, x - 2), (x + 2) / 3, -1):",
"+ for n3 in range(min(n, x - 3), (x + 2) / 3, -1):",
"+data = []",
"- print((0))",
"+ # print(0)",
"+ data.append(0)",
"- print((get_num(n, x)))",
"+ # print(get_num(n, x))",
"+ data.append(get_num(n, x))",
"+for n in data:",
"+ print(n)"
] | false | 0.056926 | 0.057934 | 0.982598 | [
"s728305362",
"s199712455"
] |
u241159583 | p03487 | python | s411337989 | s075517654 | 91 | 76 | 18,676 | 22,480 | Accepted | Accepted | 16.48 | from collections import Counter
n = int(eval(input()))
a = Counter(list(map(int, input().split())))
ans = 0
for x,y in list(a.items()):
if x == y: continue
if x < y: ans += y-x
else: ans += y
print(ans) | from collections import Counter
n = int(eval(input()))
a = Counter(list(map(int, input().split())))
ans = 0
for x,y in list(a.items()):
if y<x: ans += y
else:ans += y-x
print(ans) | 10 | 8 | 212 | 182 | from collections import Counter
n = int(eval(input()))
a = Counter(list(map(int, input().split())))
ans = 0
for x, y in list(a.items()):
if x == y:
continue
if x < y:
ans += y - x
else:
ans += y
print(ans)
| from collections import Counter
n = int(eval(input()))
a = Counter(list(map(int, input().split())))
ans = 0
for x, y in list(a.items()):
if y < x:
ans += y
else:
ans += y - x
print(ans)
| false | 20 | [
"- if x == y:",
"- continue",
"- if x < y:",
"+ if y < x:",
"+ ans += y",
"+ else:",
"- else:",
"- ans += y"
] | false | 0.047924 | 0.048457 | 0.988988 | [
"s411337989",
"s075517654"
] |
u852690916 | p02763 | python | s386018392 | s058281367 | 1,933 | 728 | 435,904 | 165,220 | Accepted | Accepted | 62.34 | import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
S = list(input().rstrip())
c = lambda x: ord(x) - ord('a')
tree = [SegmentTree(N, lambda x,y:x|y) for _ in range(26)]
for i, l in enumerate(S):
tree[c(l)].update(i, 1)
Q = int(eval(input()))
for _ in range(Q):
t, a, b = input().rstrip().split()
if t == '1':
a = int(a) - 1
tree[c(S[a])].update(a, 0)
tree[c(b)].update(a, 1)
S[a] = b
else:
a, b = int(a)-1, int(b)-1
ans = 0
for i in range(26):
t = tree[i].query(a, b+1)
ans += 1 if t else 0
print(ans)
class SegmentTree:
def __init__(self, n=None, f=max, zero_factory=int, converter=lambda x:x, initial_values=None):
assert(n, initial_values)
size = n if n else len(initial_values)
self.__f, self.__z, self.__c = f, zero_factory, converter
self.__n = 1 << ((size - 1).bit_length())
self.__dat = [zero_factory() for _ in range(2 * self.__n)]
if initial_values:
zi = self.__get_leaf(0)
for i, v in enumerate(initial_values): self.__dat[zi + i] = converter(v)
for i in range(zi-1, -1, -1): self.__dat[i] = f(*self.__get_children(i))
def update(self, index, value):
i, v = self.__get_leaf(index), self.__c(value)
if self.__dat[i] == v: return
self.__dat[i] = v
while i:
i = self.__get_parent(i)
self.__dat[i] = self.__f(*self.__get_children(i))
def query(self, from_inclusive, to_exclusive):
ans = self.__z()
if to_exclusive <= from_inclusive: return ans
l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1
while r - l > 1:
if self.__is_right(l): ans = self.__f(ans, self.__dat[l])
if self.__is_left(r): ans, r = self.__f(ans, self.__dat[r]), r-1
l, r = l//2, self.__get_parent(r)
ans = self.__f(ans, self.__dat[l])
if l != r: ans = self.__f(ans, self.__dat[r])
return ans
def __get_leaf(self, i): return self.__n + i - 1
def __get_parent(self, i): return (i-1)//2
def __get_children(self, i): return (self.__dat[2*i+1], self.__dat[2*i+2])
def __is_left(self, i): return i&1 == 1
def __is_right(self, i): return i&1 == 0
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
S = ['$'] + list(input().rstrip())
c = lambda x: ord(x) - ord('a')
bit = [BinaryIndexedTree(N) for _ in range(26)]
for i, l in enumerate(S):
if i == 0: continue
bit[c(l)].add(i, 1)
Q = int(eval(input()))
for _ in range(Q):
t, a, b = input().rstrip().split()
if t == '1':
a = int(a)
bit[c(S[a])].add(a, -1)
bit[c(b)].add(a, 1)
S[a] = b
else:
a, b = int(a), int(b)
ans = 0
for i in range(26):
t = bit[i].sum(b)
if a >= 1: t -= bit[i].sum(a-1)
ans += 1 if t else 0
print(ans)
class BinaryIndexedTree:
def __init__(self, n=None, f=lambda x,y:x+y, zero=0, initial_values=None):
assert(n or initial_values)
self.__f, self.__z, = f, zero
self.__n = n if n else len(initial_values)
self.__dat = [zero] * (self.__n + 1)
if initial_values:
for i in range(1, self.__n + 1): self.add(i, initial_values[i-1]) #slow
def add(self, i, v):
while i <= self.__n:
self.__dat[i] = self.__f(self.__dat[i], v)
i += -i&i
def sum(self, r):
ans = self.__z
while r:
ans = self.__f(ans, self.__dat[r])
r -= -r&r
return ans
if __name__ == '__main__':
main()
| 67 | 52 | 2,512 | 1,507 | import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
S = list(input().rstrip())
c = lambda x: ord(x) - ord("a")
tree = [SegmentTree(N, lambda x, y: x | y) for _ in range(26)]
for i, l in enumerate(S):
tree[c(l)].update(i, 1)
Q = int(eval(input()))
for _ in range(Q):
t, a, b = input().rstrip().split()
if t == "1":
a = int(a) - 1
tree[c(S[a])].update(a, 0)
tree[c(b)].update(a, 1)
S[a] = b
else:
a, b = int(a) - 1, int(b) - 1
ans = 0
for i in range(26):
t = tree[i].query(a, b + 1)
ans += 1 if t else 0
print(ans)
class SegmentTree:
def __init__(
self,
n=None,
f=max,
zero_factory=int,
converter=lambda x: x,
initial_values=None,
):
assert (n, initial_values)
size = n if n else len(initial_values)
self.__f, self.__z, self.__c = f, zero_factory, converter
self.__n = 1 << ((size - 1).bit_length())
self.__dat = [zero_factory() for _ in range(2 * self.__n)]
if initial_values:
zi = self.__get_leaf(0)
for i, v in enumerate(initial_values):
self.__dat[zi + i] = converter(v)
for i in range(zi - 1, -1, -1):
self.__dat[i] = f(*self.__get_children(i))
def update(self, index, value):
i, v = self.__get_leaf(index), self.__c(value)
if self.__dat[i] == v:
return
self.__dat[i] = v
while i:
i = self.__get_parent(i)
self.__dat[i] = self.__f(*self.__get_children(i))
def query(self, from_inclusive, to_exclusive):
ans = self.__z()
if to_exclusive <= from_inclusive:
return ans
l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1
while r - l > 1:
if self.__is_right(l):
ans = self.__f(ans, self.__dat[l])
if self.__is_left(r):
ans, r = self.__f(ans, self.__dat[r]), r - 1
l, r = l // 2, self.__get_parent(r)
ans = self.__f(ans, self.__dat[l])
if l != r:
ans = self.__f(ans, self.__dat[r])
return ans
def __get_leaf(self, i):
return self.__n + i - 1
def __get_parent(self, i):
return (i - 1) // 2
def __get_children(self, i):
return (self.__dat[2 * i + 1], self.__dat[2 * i + 2])
def __is_left(self, i):
return i & 1 == 1
def __is_right(self, i):
return i & 1 == 0
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
S = ["$"] + list(input().rstrip())
c = lambda x: ord(x) - ord("a")
bit = [BinaryIndexedTree(N) for _ in range(26)]
for i, l in enumerate(S):
if i == 0:
continue
bit[c(l)].add(i, 1)
Q = int(eval(input()))
for _ in range(Q):
t, a, b = input().rstrip().split()
if t == "1":
a = int(a)
bit[c(S[a])].add(a, -1)
bit[c(b)].add(a, 1)
S[a] = b
else:
a, b = int(a), int(b)
ans = 0
for i in range(26):
t = bit[i].sum(b)
if a >= 1:
t -= bit[i].sum(a - 1)
ans += 1 if t else 0
print(ans)
class BinaryIndexedTree:
def __init__(self, n=None, f=lambda x, y: x + y, zero=0, initial_values=None):
assert n or initial_values
self.__f, self.__z, = (
f,
zero,
)
self.__n = n if n else len(initial_values)
self.__dat = [zero] * (self.__n + 1)
if initial_values:
for i in range(1, self.__n + 1):
self.add(i, initial_values[i - 1]) # slow
def add(self, i, v):
while i <= self.__n:
self.__dat[i] = self.__f(self.__dat[i], v)
i += -i & i
def sum(self, r):
ans = self.__z
while r:
ans = self.__f(ans, self.__dat[r])
r -= -r & r
return ans
if __name__ == "__main__":
main()
| false | 22.38806 | [
"- S = list(input().rstrip())",
"+ S = [\"$\"] + list(input().rstrip())",
"- tree = [SegmentTree(N, lambda x, y: x | y) for _ in range(26)]",
"+ bit = [BinaryIndexedTree(N) for _ in range(26)]",
"- tree[c(l)].update(i, 1)",
"+ if i == 0:",
"+ continue",
"+ bit[c(l)].add(i, 1)",
"- a = int(a) - 1",
"- tree[c(S[a])].update(a, 0)",
"- tree[c(b)].update(a, 1)",
"+ a = int(a)",
"+ bit[c(S[a])].add(a, -1)",
"+ bit[c(b)].add(a, 1)",
"- a, b = int(a) - 1, int(b) - 1",
"+ a, b = int(a), int(b)",
"- t = tree[i].query(a, b + 1)",
"+ t = bit[i].sum(b)",
"+ if a >= 1:",
"+ t -= bit[i].sum(a - 1)",
"-class SegmentTree:",
"- def __init__(",
"- self,",
"- n=None,",
"- f=max,",
"- zero_factory=int,",
"- converter=lambda x: x,",
"- initial_values=None,",
"- ):",
"- assert (n, initial_values)",
"- size = n if n else len(initial_values)",
"- self.__f, self.__z, self.__c = f, zero_factory, converter",
"- self.__n = 1 << ((size - 1).bit_length())",
"- self.__dat = [zero_factory() for _ in range(2 * self.__n)]",
"+class BinaryIndexedTree:",
"+ def __init__(self, n=None, f=lambda x, y: x + y, zero=0, initial_values=None):",
"+ assert n or initial_values",
"+ self.__f, self.__z, = (",
"+ f,",
"+ zero,",
"+ )",
"+ self.__n = n if n else len(initial_values)",
"+ self.__dat = [zero] * (self.__n + 1)",
"- zi = self.__get_leaf(0)",
"- for i, v in enumerate(initial_values):",
"- self.__dat[zi + i] = converter(v)",
"- for i in range(zi - 1, -1, -1):",
"- self.__dat[i] = f(*self.__get_children(i))",
"+ for i in range(1, self.__n + 1):",
"+ self.add(i, initial_values[i - 1]) # slow",
"- def update(self, index, value):",
"- i, v = self.__get_leaf(index), self.__c(value)",
"- if self.__dat[i] == v:",
"- return",
"- self.__dat[i] = v",
"- while i:",
"- i = self.__get_parent(i)",
"- self.__dat[i] = self.__f(*self.__get_children(i))",
"+ def add(self, i, v):",
"+ while i <= self.__n:",
"+ self.__dat[i] = self.__f(self.__dat[i], v)",
"+ i += -i & i",
"- def query(self, from_inclusive, to_exclusive):",
"- ans = self.__z()",
"- if to_exclusive <= from_inclusive:",
"- return ans",
"- l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1",
"- while r - l > 1:",
"- if self.__is_right(l):",
"- ans = self.__f(ans, self.__dat[l])",
"- if self.__is_left(r):",
"- ans, r = self.__f(ans, self.__dat[r]), r - 1",
"- l, r = l // 2, self.__get_parent(r)",
"- ans = self.__f(ans, self.__dat[l])",
"- if l != r:",
"+ def sum(self, r):",
"+ ans = self.__z",
"+ while r:",
"+ r -= -r & r",
"-",
"- def __get_leaf(self, i):",
"- return self.__n + i - 1",
"-",
"- def __get_parent(self, i):",
"- return (i - 1) // 2",
"-",
"- def __get_children(self, i):",
"- return (self.__dat[2 * i + 1], self.__dat[2 * i + 2])",
"-",
"- def __is_left(self, i):",
"- return i & 1 == 1",
"-",
"- def __is_right(self, i):",
"- return i & 1 == 0"
] | false | 0.121068 | 0.036381 | 3.327753 | [
"s386018392",
"s058281367"
] |
u189487046 | p03400 | python | s609859354 | s762092298 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | n = int(eval(input()))
d, x = list(map(int, input().split()))
# 各参加者がチョコレートを食べる日付を取得してリストへ格納する
al = [0 for _ in range(n)]
for i in range(n):
al[i] = int(eval(input()))
# 1日目が経過した状態にする
ans = n
eat_count = [1 for _ in range(n)]
next_eat = [0 for _ in range(n)]
for i in range(n):
next_eat[i] = al[i]*eat_count[i]+1
eat_count[i] = 2
# 2日目以降の食べた個数を求める
for day in range(1, d+1):
if not(day in next_eat):
continue
for i, eat_day in enumerate(next_eat):
if eat_day == day:
ans += 1
next_eat[i] = al[i]*eat_count[i]+1
eat_count[i] += 1
print((ans+x))
| n = int(eval(input()))
d, x = list(map(int, input().split()))
# 各参加者がチョコレートを食べる日付を取得してリストへ格納する
al = [0 for _ in range(n)]
for i in range(n):
al[i] = int(eval(input()))
ans = 0
for i in al:
ans += ((d-1)//i)
ans += 1
print((ans+x)) | 28 | 14 | 627 | 238 | n = int(eval(input()))
d, x = list(map(int, input().split()))
# 各参加者がチョコレートを食べる日付を取得してリストへ格納する
al = [0 for _ in range(n)]
for i in range(n):
al[i] = int(eval(input()))
# 1日目が経過した状態にする
ans = n
eat_count = [1 for _ in range(n)]
next_eat = [0 for _ in range(n)]
for i in range(n):
next_eat[i] = al[i] * eat_count[i] + 1
eat_count[i] = 2
# 2日目以降の食べた個数を求める
for day in range(1, d + 1):
if not (day in next_eat):
continue
for i, eat_day in enumerate(next_eat):
if eat_day == day:
ans += 1
next_eat[i] = al[i] * eat_count[i] + 1
eat_count[i] += 1
print((ans + x))
| n = int(eval(input()))
d, x = list(map(int, input().split()))
# 各参加者がチョコレートを食べる日付を取得してリストへ格納する
al = [0 for _ in range(n)]
for i in range(n):
al[i] = int(eval(input()))
ans = 0
for i in al:
ans += (d - 1) // i
ans += 1
print((ans + x))
| false | 50 | [
"-# 1日目が経過した状態にする",
"-ans = n",
"-eat_count = [1 for _ in range(n)]",
"-next_eat = [0 for _ in range(n)]",
"-for i in range(n):",
"- next_eat[i] = al[i] * eat_count[i] + 1",
"- eat_count[i] = 2",
"-# 2日目以降の食べた個数を求める",
"-for day in range(1, d + 1):",
"- if not (day in next_eat):",
"- continue",
"- for i, eat_day in enumerate(next_eat):",
"- if eat_day == day:",
"- ans += 1",
"- next_eat[i] = al[i] * eat_count[i] + 1",
"- eat_count[i] += 1",
"+ans = 0",
"+for i in al:",
"+ ans += (d - 1) // i",
"+ ans += 1"
] | false | 0.044779 | 0.155276 | 0.288385 | [
"s609859354",
"s762092298"
] |
u077291787 | p03157 | python | s859481657 | s204021820 | 542 | 398 | 149,252 | 12,568 | Accepted | Accepted | 26.57 | # aising2019C - Alternating Path
import sys
sys.setrecursionlimit(10 ** 9)
def dfs(x: int, y: int) -> None:
global blk, wht
cur = S[x][y]
S[x][y] = 2 # make the grid visited
if cur:
blk += 1
else:
wht += 1
for dx, dy in dxy:
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == cur ^ 1:
dfs(nx, ny)
def main():
# separate S to connected components
global H, W, S, dxy, blk, wht
H, W, *S = open(0).read().split()
H, W = int(H), int(W)
S = [[1 if i == "#" else 0 for i in s] for s in S]
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] != 2:
blk, wht = 0, 0
dfs(i, j)
ans += blk * wht
print(ans)
if __name__ == "__main__":
main() | # aising2019C - Alternating Path
def dfs(sx: int, sy: int) -> None:
color = [0] * 2
s_col = S[sx][sy]
color[s_col] += 1
S[sx][sy] = 2 # make the grid visited
stack = [(sx, sy, s_col)]
while stack:
x, y, col = stack.pop()
for dx, dy in dxy:
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == col ^ 1:
n_col = S[nx][ny]
stack.append((nx, ny, n_col))
color[n_col] += 1
S[nx][ny] = 2
return color[0] * color[1]
def main():
# separate S to connected components
global H, W, S, dxy, blk, wht
H, W, *S = open(0).read().split()
H, W = int(H), int(W)
S = [[1 if i == "#" else 0 for i in s] for s in S]
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] != 2:
ans += dfs(i, j)
print(ans)
if __name__ == "__main__":
main() | 39 | 36 | 917 | 1,027 | # aising2019C - Alternating Path
import sys
sys.setrecursionlimit(10**9)
def dfs(x: int, y: int) -> None:
global blk, wht
cur = S[x][y]
S[x][y] = 2 # make the grid visited
if cur:
blk += 1
else:
wht += 1
for dx, dy in dxy:
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == cur ^ 1:
dfs(nx, ny)
def main():
# separate S to connected components
global H, W, S, dxy, blk, wht
H, W, *S = open(0).read().split()
H, W = int(H), int(W)
S = [[1 if i == "#" else 0 for i in s] for s in S]
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] != 2:
blk, wht = 0, 0
dfs(i, j)
ans += blk * wht
print(ans)
if __name__ == "__main__":
main()
| # aising2019C - Alternating Path
def dfs(sx: int, sy: int) -> None:
color = [0] * 2
s_col = S[sx][sy]
color[s_col] += 1
S[sx][sy] = 2 # make the grid visited
stack = [(sx, sy, s_col)]
while stack:
x, y, col = stack.pop()
for dx, dy in dxy:
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == col ^ 1:
n_col = S[nx][ny]
stack.append((nx, ny, n_col))
color[n_col] += 1
S[nx][ny] = 2
return color[0] * color[1]
def main():
# separate S to connected components
global H, W, S, dxy, blk, wht
H, W, *S = open(0).read().split()
H, W = int(H), int(W)
S = [[1 if i == "#" else 0 for i in s] for s in S]
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] != 2:
ans += dfs(i, j)
print(ans)
if __name__ == "__main__":
main()
| false | 7.692308 | [
"-import sys",
"-",
"-sys.setrecursionlimit(10**9)",
"-",
"-",
"-def dfs(x: int, y: int) -> None:",
"- global blk, wht",
"- cur = S[x][y]",
"- S[x][y] = 2 # make the grid visited",
"- if cur:",
"- blk += 1",
"- else:",
"- wht += 1",
"- for dx, dy in dxy:",
"- nx, ny = x + dx, y + dy",
"- if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == cur ^ 1:",
"- dfs(nx, ny)",
"+def dfs(sx: int, sy: int) -> None:",
"+ color = [0] * 2",
"+ s_col = S[sx][sy]",
"+ color[s_col] += 1",
"+ S[sx][sy] = 2 # make the grid visited",
"+ stack = [(sx, sy, s_col)]",
"+ while stack:",
"+ x, y, col = stack.pop()",
"+ for dx, dy in dxy:",
"+ nx, ny = x + dx, y + dy",
"+ if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == col ^ 1:",
"+ n_col = S[nx][ny]",
"+ stack.append((nx, ny, n_col))",
"+ color[n_col] += 1",
"+ S[nx][ny] = 2",
"+ return color[0] * color[1]",
"- blk, wht = 0, 0",
"- dfs(i, j)",
"- ans += blk * wht",
"+ ans += dfs(i, j)"
] | false | 0.045261 | 0.036674 | 1.234124 | [
"s859481657",
"s204021820"
] |
u595289165 | p02948 | python | s144003675 | s952656901 | 779 | 643 | 38,188 | 31,676 | Accepted | Accepted | 17.46 | import heapq
n, m = list(map(int, input().split()))
work = [list(map(int, input().split())) for _ in range(n)]
work.sort()
cd = []
heapq.heapify(cd)
cnt = 0
ans = 0
# b, a
# aの条件
for k in range(m+1):
# a = kの仕事をheappush
for i in range(cnt, n):
a, b = work[i]
if a == k:
heapq.heappush(cd, [-b, a])
else:
cnt = i
break
if i == n-1:
cnt = n-1
if not cd:
continue
ans -= heapq.heappop(cd)[0]
print(ans)
| import heapq
n, m = list(map(int, input().split()))
work = [list(map(int, input().split())) for _ in range(n)]
work.sort()
cd = []
heapq.heapify(cd)
cnt = 0
ans = 0
# b, a
# aの条件
for k in range(m+1):
# a = kの仕事をheappush
for i in range(cnt, n):
a, b = work[i]
if a == k:
heapq.heappush(cd, -b)
else:
cnt = i
break
if i == n-1:
cnt = n-1
if not cd:
continue
ans -= heapq.heappop(cd)
print(ans)
| 32 | 32 | 536 | 528 | import heapq
n, m = list(map(int, input().split()))
work = [list(map(int, input().split())) for _ in range(n)]
work.sort()
cd = []
heapq.heapify(cd)
cnt = 0
ans = 0
# b, a
# aの条件
for k in range(m + 1):
# a = kの仕事をheappush
for i in range(cnt, n):
a, b = work[i]
if a == k:
heapq.heappush(cd, [-b, a])
else:
cnt = i
break
if i == n - 1:
cnt = n - 1
if not cd:
continue
ans -= heapq.heappop(cd)[0]
print(ans)
| import heapq
n, m = list(map(int, input().split()))
work = [list(map(int, input().split())) for _ in range(n)]
work.sort()
cd = []
heapq.heapify(cd)
cnt = 0
ans = 0
# b, a
# aの条件
for k in range(m + 1):
# a = kの仕事をheappush
for i in range(cnt, n):
a, b = work[i]
if a == k:
heapq.heappush(cd, -b)
else:
cnt = i
break
if i == n - 1:
cnt = n - 1
if not cd:
continue
ans -= heapq.heappop(cd)
print(ans)
| false | 0 | [
"- heapq.heappush(cd, [-b, a])",
"+ heapq.heappush(cd, -b)",
"- ans -= heapq.heappop(cd)[0]",
"+ ans -= heapq.heappop(cd)"
] | false | 0.049986 | 0.041369 | 1.208299 | [
"s144003675",
"s952656901"
] |
u077291787 | p03356 | python | s566387665 | s470231491 | 518 | 473 | 25,184 | 25,560 | Accepted | Accepted | 8.69 | # ARC097D - Equals (ABC097D)
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, N):
self.parent = [i for i in range(N + 1)]
self.rank = [0] * (N + 1)
def find(self, x): # find the group (root) of a vertex
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same(self, x, y): # check two vertices are in the same group
return self.find(x) == self.find(y)
def unite(self, x, y): # unite two groups
x, y = self.find(x), self.find(y)
if x == y: # the same group
return
# unite a small one to a bigger one to balance trees
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
# check i and Pi are connected components or not
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
U = UnionFind(N) # construct a Union-Find tree (1-idx)
for v, u in E: # connected components are in the same group
U.unite(v, u)
ans = sum(U.is_same(i, p) for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main() | # ABC097D - Equals (ARC097D)
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, N): # construct a Union-Find tree (1-idx)
self.parent = [i for i in range(N + 1)]
self.rank = [0] * (N + 1)
def find(self, x): # find the group (root) of a vertex
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same(self, x, y): # check two vertices are in the same group
return self.find(x) == self.find(y)
def unite(self, x, y): # unite two groups
x, y = self.find(x), self.find(y)
if x == y: # the same group
return
# unite a small one to a bigger one to balance trees
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
# check i and Pi are connected components or not
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
U = UnionFind(N) # construct a Union-Find tree (1-idx)
for v, u in E: # connected components are in the same group
U.unite(v, u)
ans = sum(U.is_same(i, p) for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main() | 46 | 46 | 1,433 | 1,472 | # ARC097D - Equals (ABC097D)
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, N):
self.parent = [i for i in range(N + 1)]
self.rank = [0] * (N + 1)
def find(self, x): # find the group (root) of a vertex
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same(self, x, y): # check two vertices are in the same group
return self.find(x) == self.find(y)
def unite(self, x, y): # unite two groups
x, y = self.find(x), self.find(y)
if x == y: # the same group
return
# unite a small one to a bigger one to balance trees
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
# check i and Pi are connected components or not
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
U = UnionFind(N) # construct a Union-Find tree (1-idx)
for v, u in E: # connected components are in the same group
U.unite(v, u)
ans = sum(U.is_same(i, p) for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main()
| # ABC097D - Equals (ARC097D)
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, N): # construct a Union-Find tree (1-idx)
self.parent = [i for i in range(N + 1)]
self.rank = [0] * (N + 1)
def find(self, x): # find the group (root) of a vertex
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same(self, x, y): # check two vertices are in the same group
return self.find(x) == self.find(y)
def unite(self, x, y): # unite two groups
x, y = self.find(x), self.find(y)
if x == y: # the same group
return
# unite a small one to a bigger one to balance trees
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
# check i and Pi are connected components or not
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
U = UnionFind(N) # construct a Union-Find tree (1-idx)
for v, u in E: # connected components are in the same group
U.unite(v, u)
ans = sum(U.is_same(i, p) for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"-# ARC097D - Equals (ABC097D)",
"+# ABC097D - Equals (ARC097D)",
"- def __init__(self, N):",
"+ def __init__(self, N): # construct a Union-Find tree (1-idx)"
] | false | 0.046009 | 0.034623 | 1.328869 | [
"s566387665",
"s470231491"
] |
u150984829 | p02248 | python | s189741083 | s889658440 | 2,120 | 1,790 | 47,924 | 7,520 | Accepted | Accepted | 15.57 | T,P=input(),input()
for x in[i for i,c in enumerate(T)if P[0]==c]:P!=T[x:x+len(P)]or print(x)
| def f():
T,P=input(),input()
for i in range(len(T)):P!=T[i:i+len(P)]or print(i)
f()
| 2 | 4 | 95 | 89 | T, P = input(), input()
for x in [i for i, c in enumerate(T) if P[0] == c]:
P != T[x : x + len(P)] or print(x)
| def f():
T, P = input(), input()
for i in range(len(T)):
P != T[i : i + len(P)] or print(i)
f()
| false | 50 | [
"-T, P = input(), input()",
"-for x in [i for i, c in enumerate(T) if P[0] == c]:",
"- P != T[x : x + len(P)] or print(x)",
"+def f():",
"+ T, P = input(), input()",
"+ for i in range(len(T)):",
"+ P != T[i : i + len(P)] or print(i)",
"+",
"+",
"+f()"
] | false | 0.036985 | 0.043831 | 0.843804 | [
"s189741083",
"s889658440"
] |
u603958124 | p03910 | python | s801232354 | s404669528 | 45 | 39 | 13,832 | 10,564 | Accepted | Accepted | 13.33 | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
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())
ans = []
def dfs(m):
if m == 1:
ans.append(1)
return 0
elif m == 2:
ans.append(2)
return 0
else:
k = ceil(sqrt(1+8*m))//2
ans.append(k)
dfs(m-k)
n = INT()
dfs(n)
for x in ans:
print(x) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
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())
n = INT()
ans = []
reg = 0
i = 1
while reg <= n:
ans.append(i)
reg += i
i += 1
if reg - n > 0:
ans.remove(reg-n)
for x in ans:
print(x) | 36 | 31 | 1,019 | 912 | from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
comb,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10**7)
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())
ans = []
def dfs(m):
if m == 1:
ans.append(1)
return 0
elif m == 2:
ans.append(2)
return 0
else:
k = ceil(sqrt(1 + 8 * m)) // 2
ans.append(k)
dfs(m - k)
n = INT()
dfs(n)
for x in ans:
print(x)
| from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
comb,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10**7)
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())
n = INT()
ans = []
reg = 0
i = 1
while reg <= n:
ans.append(i)
reg += i
i += 1
if reg - n > 0:
ans.remove(reg - n)
for x in ans:
print(x)
| false | 13.888889 | [
"+n = INT()",
"-",
"-",
"-def dfs(m):",
"- if m == 1:",
"- ans.append(1)",
"- return 0",
"- elif m == 2:",
"- ans.append(2)",
"- return 0",
"- else:",
"- k = ceil(sqrt(1 + 8 * m)) // 2",
"- ans.append(k)",
"- dfs(m - k)",
"-",
"-",
"-n = INT()",
"-dfs(n)",
"+reg = 0",
"+i = 1",
"+while reg <= n:",
"+ ans.append(i)",
"+ reg += i",
"+ i += 1",
"+if reg - n > 0:",
"+ ans.remove(reg - n)"
] | false | 0.040238 | 0.040151 | 1.002162 | [
"s801232354",
"s404669528"
] |
u077291787 | p02913 | python | s599275394 | s585088874 | 587 | 347 | 60,124 | 27,348 | Accepted | Accepted | 40.89 | # ABC141E - Who Says a Pun?
class RollingHash:
def __init__(self, source: str, base=1007, mod=10 ** 9 + 7):
self.source = source
self.length = len(source)
self.base = base
self.mod = mod
self.hash = self._get_hash_from_zero()
self.power = self._get_base_pow()
def _get_hash_from_zero(self): # compute hash of interval [0, right)
cur, hash_from_zero = 0, [0]
for e in self.source:
cur = (cur * self.base + ord(e)) % self.mod
hash_from_zero.append(cur)
return hash_from_zero
def _get_base_pow(self): # computer mod of power of base
cur, power = 1, [1]
for i in range(self.length):
cur *= self.base % self.mod
power.append(cur)
return power
def get_hash(self, l: int, r: int): # compute hash of interval [left, right)
return (self.hash[r] - self.hash[l] * self.power[r - l]) % self.mod
def main():
N = int(eval(input()))
S = input().rstrip()
rh, ok, ng = RollingHash(S), 0, N // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
flg, memo = 0, set()
for i in range(N - 2 * mid + 1):
memo.add(rh.get_hash(i, i + mid))
if rh.get_hash(i + mid, i + 2 * mid) in memo:
flg = 1
break
if flg:
ok = mid # next mid will be longer
else:
ng = mid # next mid will be shorter
print(ok) # max length of substrings appeared twice or more
if __name__ == "__main__":
main() | from typing import List
class RollingHash:
__slots__ = ["source", "length", "base", "mod", "hash", "power"]
def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):
self.source = source
self.length = len(source)
self.base = base
self.mod = mod
self.hash = self._get_hash_from_zero()
self.power = self._get_base_pow()
def _get_hash_from_zero(self) -> List[int]:
"""Compute hash of interval [0, right)."""
cur, hash_from_zero = 0, [0]
for e in self.source:
cur = (cur * self.base + ord(e)) % self.mod
hash_from_zero.append(cur)
return hash_from_zero
def _get_base_pow(self) -> List[int]:
"""Compute mod of power of base."""
cur, power = 1, [1]
for i in range(self.length):
cur *= self.base % self.mod
power.append(cur)
return power
def get_hash(self, left: int, right: int):
"""Compute hash of interval [left, right)."""
return (
self.hash[right] - self.hash[left] * self.power[right - left]
) % self.mod
def abc141_e():
# https://atcoder.jp/contests/abc141/tasks/abc141_e
N = int(eval(input()))
S = input().rstrip()
rh = RollingHash(S)
ok, ng = 0, N // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
flg, memo = 0, set()
for i in range(N - 2 * mid + 1):
memo.add(rh.get_hash(i, i + mid))
if rh.get_hash(i + mid, i + 2 * mid) in memo:
flg = 1
break
if flg:
ok = mid # next mid will be longer
else:
ng = mid # next mid will be shorter
print(ok) # max length of substrings appeared twice or more
if __name__ == "__main__":
abc141_e()
| 49 | 60 | 1,615 | 1,881 | # ABC141E - Who Says a Pun?
class RollingHash:
def __init__(self, source: str, base=1007, mod=10**9 + 7):
self.source = source
self.length = len(source)
self.base = base
self.mod = mod
self.hash = self._get_hash_from_zero()
self.power = self._get_base_pow()
def _get_hash_from_zero(self): # compute hash of interval [0, right)
cur, hash_from_zero = 0, [0]
for e in self.source:
cur = (cur * self.base + ord(e)) % self.mod
hash_from_zero.append(cur)
return hash_from_zero
def _get_base_pow(self): # computer mod of power of base
cur, power = 1, [1]
for i in range(self.length):
cur *= self.base % self.mod
power.append(cur)
return power
def get_hash(self, l: int, r: int): # compute hash of interval [left, right)
return (self.hash[r] - self.hash[l] * self.power[r - l]) % self.mod
def main():
N = int(eval(input()))
S = input().rstrip()
rh, ok, ng = RollingHash(S), 0, N // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
flg, memo = 0, set()
for i in range(N - 2 * mid + 1):
memo.add(rh.get_hash(i, i + mid))
if rh.get_hash(i + mid, i + 2 * mid) in memo:
flg = 1
break
if flg:
ok = mid # next mid will be longer
else:
ng = mid # next mid will be shorter
print(ok) # max length of substrings appeared twice or more
if __name__ == "__main__":
main()
| from typing import List
class RollingHash:
__slots__ = ["source", "length", "base", "mod", "hash", "power"]
def __init__(self, source: str, base: int = 1007, mod: int = 10**9 + 7):
self.source = source
self.length = len(source)
self.base = base
self.mod = mod
self.hash = self._get_hash_from_zero()
self.power = self._get_base_pow()
def _get_hash_from_zero(self) -> List[int]:
"""Compute hash of interval [0, right)."""
cur, hash_from_zero = 0, [0]
for e in self.source:
cur = (cur * self.base + ord(e)) % self.mod
hash_from_zero.append(cur)
return hash_from_zero
def _get_base_pow(self) -> List[int]:
"""Compute mod of power of base."""
cur, power = 1, [1]
for i in range(self.length):
cur *= self.base % self.mod
power.append(cur)
return power
def get_hash(self, left: int, right: int):
"""Compute hash of interval [left, right)."""
return (
self.hash[right] - self.hash[left] * self.power[right - left]
) % self.mod
def abc141_e():
# https://atcoder.jp/contests/abc141/tasks/abc141_e
N = int(eval(input()))
S = input().rstrip()
rh = RollingHash(S)
ok, ng = 0, N // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
flg, memo = 0, set()
for i in range(N - 2 * mid + 1):
memo.add(rh.get_hash(i, i + mid))
if rh.get_hash(i + mid, i + 2 * mid) in memo:
flg = 1
break
if flg:
ok = mid # next mid will be longer
else:
ng = mid # next mid will be shorter
print(ok) # max length of substrings appeared twice or more
if __name__ == "__main__":
abc141_e()
| false | 18.333333 | [
"-# ABC141E - Who Says a Pun?",
"+from typing import List",
"+",
"+",
"- def __init__(self, source: str, base=1007, mod=10**9 + 7):",
"+ __slots__ = [\"source\", \"length\", \"base\", \"mod\", \"hash\", \"power\"]",
"+",
"+ def __init__(self, source: str, base: int = 1007, mod: int = 10**9 + 7):",
"- def _get_hash_from_zero(self): # compute hash of interval [0, right)",
"+ def _get_hash_from_zero(self) -> List[int]:",
"+ \"\"\"Compute hash of interval [0, right).\"\"\"",
"- def _get_base_pow(self): # computer mod of power of base",
"+ def _get_base_pow(self) -> List[int]:",
"+ \"\"\"Compute mod of power of base.\"\"\"",
"- def get_hash(self, l: int, r: int): # compute hash of interval [left, right)",
"- return (self.hash[r] - self.hash[l] * self.power[r - l]) % self.mod",
"+ def get_hash(self, left: int, right: int):",
"+ \"\"\"Compute hash of interval [left, right).\"\"\"",
"+ return (",
"+ self.hash[right] - self.hash[left] * self.power[right - left]",
"+ ) % self.mod",
"-def main():",
"+def abc141_e():",
"+ # https://atcoder.jp/contests/abc141/tasks/abc141_e",
"- rh, ok, ng = RollingHash(S), 0, N // 2 + 1",
"+ rh = RollingHash(S)",
"+ ok, ng = 0, N // 2 + 1",
"- main()",
"+ abc141_e()"
] | false | 0.041321 | 0.111488 | 0.37063 | [
"s599275394",
"s585088874"
] |
u706929073 | p02887 | python | s950600993 | s041887298 | 43 | 37 | 3,316 | 4,664 | Accepted | Accepted | 13.95 | n = int(eval(input()))
s = eval(input())
count = 1
for i in range(1, n):
count += (1 if s[i] != s[i-1] else 0)
print(count)
| n = int(eval(input()))
s = list(eval(input()))
prev = s[0]
count = 1
for s_i in s[1::]:
if prev != s_i:
count += 1
prev = s_i
print(count)
| 7 | 10 | 123 | 157 | n = int(eval(input()))
s = eval(input())
count = 1
for i in range(1, n):
count += 1 if s[i] != s[i - 1] else 0
print(count)
| n = int(eval(input()))
s = list(eval(input()))
prev = s[0]
count = 1
for s_i in s[1::]:
if prev != s_i:
count += 1
prev = s_i
print(count)
| false | 30 | [
"-s = eval(input())",
"+s = list(eval(input()))",
"+prev = s[0]",
"-for i in range(1, n):",
"- count += 1 if s[i] != s[i - 1] else 0",
"+for s_i in s[1::]:",
"+ if prev != s_i:",
"+ count += 1",
"+ prev = s_i"
] | false | 0.086923 | 0.036487 | 2.3823 | [
"s950600993",
"s041887298"
] |
u624475441 | p03666 | python | s619780324 | s331003260 | 242 | 221 | 3,060 | 3,060 | Accepted | Accepted | 8.68 | N, A, B, C, D = list(map(int, input().split()))
lb, ub = A, A
for _ in range(1, N):
if (lb + ub) / 2 < B:
lb, ub = lb + C, ub + D
else:
lb, ub = lb - D, ub - C
if lb <= B <= ub:
print('YES')
else:
print('NO') | N, A, B, C, D = list(map(int, input().split()))
for m in range(N):
if C * (N - 1 - m) - D * m <= B - A <= D * (N - 1 - m) - C * m:
print('YES')
break
else:
print('NO') | 11 | 7 | 244 | 191 | N, A, B, C, D = list(map(int, input().split()))
lb, ub = A, A
for _ in range(1, N):
if (lb + ub) / 2 < B:
lb, ub = lb + C, ub + D
else:
lb, ub = lb - D, ub - C
if lb <= B <= ub:
print("YES")
else:
print("NO")
| N, A, B, C, D = list(map(int, input().split()))
for m in range(N):
if C * (N - 1 - m) - D * m <= B - A <= D * (N - 1 - m) - C * m:
print("YES")
break
else:
print("NO")
| false | 36.363636 | [
"-lb, ub = A, A",
"-for _ in range(1, N):",
"- if (lb + ub) / 2 < B:",
"- lb, ub = lb + C, ub + D",
"- else:",
"- lb, ub = lb - D, ub - C",
"-if lb <= B <= ub:",
"- print(\"YES\")",
"+for m in range(N):",
"+ if C * (N - 1 - m) - D * m <= B - A <= D * (N - 1 - m) - C * m:",
"+ print(\"YES\")",
"+ break"
] | false | 0.089431 | 0.079721 | 1.121799 | [
"s619780324",
"s331003260"
] |
u477977638 | p02936 | python | s366203515 | s397700580 | 1,851 | 613 | 116,204 | 99,652 | Accepted | Accepted | 66.88 | from collections import deque
n,q=list(map(int,input().split()))
li=[[] for i in range(n+1)]
ans=[0]*(n+1)
for i in range(n-1):
a,b=list(map(int,input().split()))
li[a].append(b)
li[b].append(a)
for i in range(q):
p,x=list(map(int,input().split()))
ans[p]+=x
Q=deque([1])
sumi=set([1])
while Q:
# print(Q)
now=Q.pop()
for i in li[now]:
if i in sumi:
continue
else:
sumi.add(i)
Q.append(i)
ans[i]+=ans[now]
print((*ans[1:])) | import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
from collections import deque
def main():
n,q=list(map(int,input().split()))
li=[[] for i in range(n+1)]
ans=[0]*(n+1)
for i in range(n-1):
a,b=list(map(int,input().split()))
li[a].append(b)
li[b].append(a)
for i in range(q):
p,x=list(map(int,input().split()))
ans[p]+=x
Q=deque([1])
sumi=set([1])
while Q:
# print(Q)
now=Q.pop()
for i in li[now]:
if i in sumi:
continue
else:
sumi.add(i)
Q.append(i)
ans[i]+=ans[now]
print((*ans[1:]))
if __name__ == "__main__":
main() | 30 | 42 | 485 | 718 | from collections import deque
n, q = list(map(int, input().split()))
li = [[] for i in range(n + 1)]
ans = [0] * (n + 1)
for i in range(n - 1):
a, b = list(map(int, input().split()))
li[a].append(b)
li[b].append(a)
for i in range(q):
p, x = list(map(int, input().split()))
ans[p] += x
Q = deque([1])
sumi = set([1])
while Q:
# print(Q)
now = Q.pop()
for i in li[now]:
if i in sumi:
continue
else:
sumi.add(i)
Q.append(i)
ans[i] += ans[now]
print((*ans[1:]))
| import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
from collections import deque
def main():
n, q = list(map(int, input().split()))
li = [[] for i in range(n + 1)]
ans = [0] * (n + 1)
for i in range(n - 1):
a, b = list(map(int, input().split()))
li[a].append(b)
li[b].append(a)
for i in range(q):
p, x = list(map(int, input().split()))
ans[p] += x
Q = deque([1])
sumi = set([1])
while Q:
# print(Q)
now = Q.pop()
for i in li[now]:
if i in sumi:
continue
else:
sumi.add(i)
Q.append(i)
ans[i] += ans[now]
print((*ans[1:]))
if __name__ == "__main__":
main()
| false | 28.571429 | [
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+input = sys.stdin.buffer.readline",
"+inputs = sys.stdin.buffer.readlines",
"-n, q = list(map(int, input().split()))",
"-li = [[] for i in range(n + 1)]",
"-ans = [0] * (n + 1)",
"-for i in range(n - 1):",
"- a, b = list(map(int, input().split()))",
"- li[a].append(b)",
"- li[b].append(a)",
"-for i in range(q):",
"- p, x = list(map(int, input().split()))",
"- ans[p] += x",
"-Q = deque([1])",
"-sumi = set([1])",
"-while Q:",
"- # print(Q)",
"- now = Q.pop()",
"- for i in li[now]:",
"- if i in sumi:",
"- continue",
"- else:",
"- sumi.add(i)",
"- Q.append(i)",
"- ans[i] += ans[now]",
"-print((*ans[1:]))",
"+",
"+def main():",
"+ n, q = list(map(int, input().split()))",
"+ li = [[] for i in range(n + 1)]",
"+ ans = [0] * (n + 1)",
"+ for i in range(n - 1):",
"+ a, b = list(map(int, input().split()))",
"+ li[a].append(b)",
"+ li[b].append(a)",
"+ for i in range(q):",
"+ p, x = list(map(int, input().split()))",
"+ ans[p] += x",
"+ Q = deque([1])",
"+ sumi = set([1])",
"+ while Q:",
"+ # print(Q)",
"+ now = Q.pop()",
"+ for i in li[now]:",
"+ if i in sumi:",
"+ continue",
"+ else:",
"+ sumi.add(i)",
"+ Q.append(i)",
"+ ans[i] += ans[now]",
"+ print((*ans[1:]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.058578 | 0.042127 | 1.390508 | [
"s366203515",
"s397700580"
] |
u762420987 | p03013 | python | s711353569 | s659481567 | 258 | 180 | 13,216 | 13,192 | Accepted | Accepted | 30.23 | N, M = list(map(int, input().split()))
aset = set([int(eval(input())) for _ in range(M)])
dp = [0] * (N + 1)
dp[0] = 1
for i in range(N):
for j in range(i + 1, min(N, i + 2) + 1):
if j not in aset:
dp[j] += dp[i]
dp[j] %= 10**9 + 7
print((dp[N]))
| N, M = list(map(int, input().split()))
aset = set([int(eval(input())) for _ in range(M)])
dp = [0] * (N + 1)
dp[0] = 1
if 1 not in aset:
dp[1] = 1
for i in range(2, N + 1):
if i in aset:
dp[i] = 0
else:
dp[i] = (dp[i - 1] + dp[i - 2]) % (10**9 + 7)
print((dp[-1]))
| 10 | 12 | 278 | 290 | N, M = list(map(int, input().split()))
aset = set([int(eval(input())) for _ in range(M)])
dp = [0] * (N + 1)
dp[0] = 1
for i in range(N):
for j in range(i + 1, min(N, i + 2) + 1):
if j not in aset:
dp[j] += dp[i]
dp[j] %= 10**9 + 7
print((dp[N]))
| N, M = list(map(int, input().split()))
aset = set([int(eval(input())) for _ in range(M)])
dp = [0] * (N + 1)
dp[0] = 1
if 1 not in aset:
dp[1] = 1
for i in range(2, N + 1):
if i in aset:
dp[i] = 0
else:
dp[i] = (dp[i - 1] + dp[i - 2]) % (10**9 + 7)
print((dp[-1]))
| false | 16.666667 | [
"-for i in range(N):",
"- for j in range(i + 1, min(N, i + 2) + 1):",
"- if j not in aset:",
"- dp[j] += dp[i]",
"- dp[j] %= 10**9 + 7",
"-print((dp[N]))",
"+if 1 not in aset:",
"+ dp[1] = 1",
"+for i in range(2, N + 1):",
"+ if i in aset:",
"+ dp[i] = 0",
"+ else:",
"+ dp[i] = (dp[i - 1] + dp[i - 2]) % (10**9 + 7)",
"+print((dp[-1]))"
] | false | 0.038973 | 0.040878 | 0.953419 | [
"s711353569",
"s659481567"
] |
u088553842 | p03834 | python | s056542971 | s996349103 | 28 | 25 | 8,972 | 9,024 | Accepted | Accepted | 10.71 | s=eval(input());print((s[:5],s[6:13],s[14:])) | print((input().replace(',',' '))) | 1 | 1 | 37 | 31 | s = eval(input())
print((s[:5], s[6:13], s[14:]))
| print((input().replace(",", " ")))
| false | 0 | [
"-s = eval(input())",
"-print((s[:5], s[6:13], s[14:]))",
"+print((input().replace(\",\", \" \")))"
] | false | 0.045119 | 0.045613 | 0.989157 | [
"s056542971",
"s996349103"
] |
u481187938 | p02834 | python | s944129198 | s848612382 | 562 | 275 | 270,932 | 107,704 | Accepted | Accepted | 51.07 | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
def parent_children(start, g):
parent, children, depth, q = [-1]*len(g), make_list(len(g), 0), [-1]*len(g), deque([start]); depth[start] = 0
while q:
i = q.popleft()
for j in g[i]:
if depth[j] != -1: parent[i] = j
else: depth[j] = depth[i] + 1; children[i].append(j), q.append(j)
return parent, children, depth
def adjacency_list(N, edges):
g = make_list(N, 0)
for a, b in edges: g[a].append(b), g[b].append(a)
return g
sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")
def main():
N, u, v = LI()
AB = LIR1(N-1)
max_dist = [None] * N
g = adjacency_list(N, AB)
parent, children, depth = parent_children(v-1, g)
def dfs(i):
dist = max([0] + [dfs(j) for j in children[i]])
max_dist[i] = dist
return dist + 1
mid = u-1
for _ in range((depth[u-1] - 1)//2):
mid = parent[mid]
dfs(mid)
print((depth[mid] + max_dist[mid] - 1))
if __name__ == '__main__':
main() | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
def adjacency_list(N, edges):
g = make_list(N, 0)
for a, b in edges: g[a].append(b), g[b].append(a)
return g
def tree_utils(start, g):
parent, children, depth, q = [-1]*len(g), make_list(len(g), 0), [-1]*len(g), deque([start]); depth[start] = 0
while q:
i = q.popleft()
for j in g[i]:
if depth[j] != -1: parent[i] = j
else: depth[j] = depth[i] + 1; children[i].append(j), q.append(j)
return parent, children, depth
def graph_distance(start, g):
dist, q = [-1] * len(g), deque([start]); dist[start] = 0
while q:
i = q.popleft()
for j in g[i]:
if dist[j] == -1: dist[j] = dist[i] + 1; q.append(j)
return dist
sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")
def main():
N, u, v = LI()
AB = LIR1(N-1)
max_dist = [None] * N
g = adjacency_list(N, AB)
udist = graph_distance(u-1, g)
vdist = graph_distance(v-1, g)
visit = [False] * N
ans = vdist[u-1] - 1
q = deque([u-1])
while q:
i = q.popleft()
visit[i] = True
if udist[i] < vdist[i]:
ans = max(ans, vdist[i]-1)
for j in g[i]:
if not visit[j]:
q.append(j)
print(ans)
if __name__ == '__main__':
main() | 65 | 76 | 2,460 | 2,764 | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline().rstrip())
def SL():
return list(sys.stdin.readline().rstrip())
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI1():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def IR(n):
return [I() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def LIR1(n):
return [LI1() for _ in range(n)]
def SR(n):
return [SL() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
def LR(n):
return [L() for _ in range(n)]
def perm(n, r):
return math.factorial(n) // math.factorial(r)
def comb(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
def make_list(n, *args, default=0):
return (
[make_list(*args, default=default) for _ in range(n)]
if len(args) > 0
else [default for _ in range(n)]
)
def parent_children(start, g):
parent, children, depth, q = (
[-1] * len(g),
make_list(len(g), 0),
[-1] * len(g),
deque([start]),
)
depth[start] = 0
while q:
i = q.popleft()
for j in g[i]:
if depth[j] != -1:
parent[i] = j
else:
depth[j] = depth[i] + 1
children[i].append(j), q.append(j)
return parent, children, depth
def adjacency_list(N, edges):
g = make_list(N, 0)
for a, b in edges:
g[a].append(b), g[b].append(a)
return g
sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [
[1, 0],
[1, 1],
[0, 1],
[-1, 1],
[-1, 0],
[-1, -1],
[0, -1],
[1, -1],
]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")
def main():
N, u, v = LI()
AB = LIR1(N - 1)
max_dist = [None] * N
g = adjacency_list(N, AB)
parent, children, depth = parent_children(v - 1, g)
def dfs(i):
dist = max([0] + [dfs(j) for j in children[i]])
max_dist[i] = dist
return dist + 1
mid = u - 1
for _ in range((depth[u - 1] - 1) // 2):
mid = parent[mid]
dfs(mid)
print((depth[mid] + max_dist[mid] - 1))
if __name__ == "__main__":
main()
| #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline().rstrip())
def SL():
return list(sys.stdin.readline().rstrip())
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI1():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def IR(n):
return [I() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def LIR1(n):
return [LI1() for _ in range(n)]
def SR(n):
return [SL() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
def LR(n):
return [L() for _ in range(n)]
def perm(n, r):
return math.factorial(n) // math.factorial(r)
def comb(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
def make_list(n, *args, default=0):
return (
[make_list(*args, default=default) for _ in range(n)]
if len(args) > 0
else [default for _ in range(n)]
)
def adjacency_list(N, edges):
g = make_list(N, 0)
for a, b in edges:
g[a].append(b), g[b].append(a)
return g
def tree_utils(start, g):
parent, children, depth, q = (
[-1] * len(g),
make_list(len(g), 0),
[-1] * len(g),
deque([start]),
)
depth[start] = 0
while q:
i = q.popleft()
for j in g[i]:
if depth[j] != -1:
parent[i] = j
else:
depth[j] = depth[i] + 1
children[i].append(j), q.append(j)
return parent, children, depth
def graph_distance(start, g):
dist, q = [-1] * len(g), deque([start])
dist[start] = 0
while q:
i = q.popleft()
for j in g[i]:
if dist[j] == -1:
dist[j] = dist[i] + 1
q.append(j)
return dist
sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [
[1, 0],
[1, 1],
[0, 1],
[-1, 1],
[-1, 0],
[-1, -1],
[0, -1],
[1, -1],
]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")
def main():
N, u, v = LI()
AB = LIR1(N - 1)
max_dist = [None] * N
g = adjacency_list(N, AB)
udist = graph_distance(u - 1, g)
vdist = graph_distance(v - 1, g)
visit = [False] * N
ans = vdist[u - 1] - 1
q = deque([u - 1])
while q:
i = q.popleft()
visit[i] = True
if udist[i] < vdist[i]:
ans = max(ans, vdist[i] - 1)
for j in g[i]:
if not visit[j]:
q.append(j)
print(ans)
if __name__ == "__main__":
main()
| false | 14.473684 | [
"-def parent_children(start, g):",
"+def adjacency_list(N, edges):",
"+ g = make_list(N, 0)",
"+ for a, b in edges:",
"+ g[a].append(b), g[b].append(a)",
"+ return g",
"+",
"+",
"+def tree_utils(start, g):",
"-def adjacency_list(N, edges):",
"- g = make_list(N, 0)",
"- for a, b in edges:",
"- g[a].append(b), g[b].append(a)",
"- return g",
"+def graph_distance(start, g):",
"+ dist, q = [-1] * len(g), deque([start])",
"+ dist[start] = 0",
"+ while q:",
"+ i = q.popleft()",
"+ for j in g[i]:",
"+ if dist[j] == -1:",
"+ dist[j] = dist[i] + 1",
"+ q.append(j)",
"+ return dist",
"- parent, children, depth = parent_children(v - 1, g)",
"-",
"- def dfs(i):",
"- dist = max([0] + [dfs(j) for j in children[i]])",
"- max_dist[i] = dist",
"- return dist + 1",
"-",
"- mid = u - 1",
"- for _ in range((depth[u - 1] - 1) // 2):",
"- mid = parent[mid]",
"- dfs(mid)",
"- print((depth[mid] + max_dist[mid] - 1))",
"+ udist = graph_distance(u - 1, g)",
"+ vdist = graph_distance(v - 1, g)",
"+ visit = [False] * N",
"+ ans = vdist[u - 1] - 1",
"+ q = deque([u - 1])",
"+ while q:",
"+ i = q.popleft()",
"+ visit[i] = True",
"+ if udist[i] < vdist[i]:",
"+ ans = max(ans, vdist[i] - 1)",
"+ for j in g[i]:",
"+ if not visit[j]:",
"+ q.append(j)",
"+ print(ans)"
] | false | 0.045909 | 0.056258 | 0.81604 | [
"s944129198",
"s848612382"
] |
u685662874 | p03013 | python | s587737412 | s488881027 | 248 | 208 | 9,600 | 7,832 | Accepted | Accepted | 16.13 | N, M=list(map(int, input().split()))
items=[int(eval(input())) for i in range(M)]
mod=10**9+7
dp=[0 for i in range(N+1)]
dp[0] = 1
is_broken =[1 for i in range(N+1)]
for i in range(M):
is_broken[items[i]] = 0
for i in range(N):
if i-1 >= 0:
dp[i+1] = dp[i]*is_broken[i] + dp[i-1]*is_broken[i-1]
else:
dp[i+1] = dp[i]*is_broken[i]
dp[i+1] %= mod
print((dp[N])) | N, M=list(map(int, input().split()))
mod=10**9+7
dp=[0 for i in range(N+2)]
dp[N] = 1
is_broken =[False for i in range(N+1)]
for i in range(M):
a=int(eval(input()))
is_broken[a] = True
for i in reversed(list(range(N))):
if is_broken[i]:
dp[i] = 0
continue
dp[i] = (dp[i+1] + dp[i+2]) % mod
print((dp[0]))
| 18 | 18 | 397 | 341 | N, M = list(map(int, input().split()))
items = [int(eval(input())) for i in range(M)]
mod = 10**9 + 7
dp = [0 for i in range(N + 1)]
dp[0] = 1
is_broken = [1 for i in range(N + 1)]
for i in range(M):
is_broken[items[i]] = 0
for i in range(N):
if i - 1 >= 0:
dp[i + 1] = dp[i] * is_broken[i] + dp[i - 1] * is_broken[i - 1]
else:
dp[i + 1] = dp[i] * is_broken[i]
dp[i + 1] %= mod
print((dp[N]))
| N, M = list(map(int, input().split()))
mod = 10**9 + 7
dp = [0 for i in range(N + 2)]
dp[N] = 1
is_broken = [False for i in range(N + 1)]
for i in range(M):
a = int(eval(input()))
is_broken[a] = True
for i in reversed(list(range(N))):
if is_broken[i]:
dp[i] = 0
continue
dp[i] = (dp[i + 1] + dp[i + 2]) % mod
print((dp[0]))
| false | 0 | [
"-items = [int(eval(input())) for i in range(M)]",
"-dp = [0 for i in range(N + 1)]",
"-dp[0] = 1",
"-is_broken = [1 for i in range(N + 1)]",
"+dp = [0 for i in range(N + 2)]",
"+dp[N] = 1",
"+is_broken = [False for i in range(N + 1)]",
"- is_broken[items[i]] = 0",
"-for i in range(N):",
"- if i - 1 >= 0:",
"- dp[i + 1] = dp[i] * is_broken[i] + dp[i - 1] * is_broken[i - 1]",
"- else:",
"- dp[i + 1] = dp[i] * is_broken[i]",
"- dp[i + 1] %= mod",
"-print((dp[N]))",
"+ a = int(eval(input()))",
"+ is_broken[a] = True",
"+for i in reversed(list(range(N))):",
"+ if is_broken[i]:",
"+ dp[i] = 0",
"+ continue",
"+ dp[i] = (dp[i + 1] + dp[i + 2]) % mod",
"+print((dp[0]))"
] | false | 0.035755 | 0.035104 | 1.018542 | [
"s587737412",
"s488881027"
] |
u102461423 | p03034 | python | s932273539 | s230699006 | 1,634 | 873 | 23,300 | 18,552 | Accepted | Accepted | 46.57 | import numpy as np
N = int(eval(input()))
S = np.array([int(x) for x in input().split()],dtype=np.int64)
# 右移動着地点:等差数列、ゴール含む
# 左移動着地点:等差数列、スタート含む
answer = 0
for d in range(1,N):
# d = A-B
cum_left = np.cumsum(S[::d])
cum_right = np.cumsum(S[::-1][::d])
score = cum_left + cum_right # 等差数列の長さ-1 -> 得点
# あとは、その経路がルール内で実現できるかどうか
for L,s in enumerate(score):
if answer >= s:
continue
# 右左に進んでいることの確認
A = N-1-L*d
B = A-d
if A <= 0:
continue
if A<=B:
continue
if B<=0:
continue
# 同じ場所を取っていないかの確認
# kd = N-1-ldとなるとまずい
# 約数のとき、Ld >= N-Ldだとまずい
if (N-1)%d == 0 and 2*L*d >= N-1:
continue
answer = s
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
S = np.array(read().split(),np.int64)
def F(d):
# 公差を固定
L = S[:-d:d].cumsum()
R = S[::-1][:-d:d].cumsum()
if (N-1)%d == 0:
n = (N-1)//d
x = np.arange(1,n+1)
bl = (x+x <= n+1)
L = L[bl]; R = R[bl]
return (L+R).max()
def G(n):
# 項数n+1を固定
D = (N-1-n)//n
L = np.zeros(D+1,np.int64)
R = np.zeros(D+1,np.int64)
for i in range(1,n+1):
L += S[:i*(D+1):i]
R += S[::-1][:i*(D+1):i]
ok = np.ones(D+1,np.bool)
overlap = (np.arange(D+1) * (n+n) >= N-1)
overlap[1:] &= ((N-1)%np.arange(1,D+1) == 0)
x = L+R
x[overlap] = 0
return x.max()
L = int((N-1)**.5 + 10)
L = min(N-1,L)
x = max(F(n) for n in range(1,L+1))
y = max(G(n) for n in range(1,L+1))
answer = max(x,y)
print(answer) | 35 | 43 | 725 | 980 | import numpy as np
N = int(eval(input()))
S = np.array([int(x) for x in input().split()], dtype=np.int64)
# 右移動着地点:等差数列、ゴール含む
# 左移動着地点:等差数列、スタート含む
answer = 0
for d in range(1, N):
# d = A-B
cum_left = np.cumsum(S[::d])
cum_right = np.cumsum(S[::-1][::d])
score = cum_left + cum_right # 等差数列の長さ-1 -> 得点
# あとは、その経路がルール内で実現できるかどうか
for L, s in enumerate(score):
if answer >= s:
continue
# 右左に進んでいることの確認
A = N - 1 - L * d
B = A - d
if A <= 0:
continue
if A <= B:
continue
if B <= 0:
continue
# 同じ場所を取っていないかの確認
# kd = N-1-ldとなるとまずい
# 約数のとき、Ld >= N-Ldだとまずい
if (N - 1) % d == 0 and 2 * L * d >= N - 1:
continue
answer = s
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
S = np.array(read().split(), np.int64)
def F(d):
# 公差を固定
L = S[:-d:d].cumsum()
R = S[::-1][:-d:d].cumsum()
if (N - 1) % d == 0:
n = (N - 1) // d
x = np.arange(1, n + 1)
bl = x + x <= n + 1
L = L[bl]
R = R[bl]
return (L + R).max()
def G(n):
# 項数n+1を固定
D = (N - 1 - n) // n
L = np.zeros(D + 1, np.int64)
R = np.zeros(D + 1, np.int64)
for i in range(1, n + 1):
L += S[: i * (D + 1) : i]
R += S[::-1][: i * (D + 1) : i]
ok = np.ones(D + 1, np.bool)
overlap = np.arange(D + 1) * (n + n) >= N - 1
overlap[1:] &= (N - 1) % np.arange(1, D + 1) == 0
x = L + R
x[overlap] = 0
return x.max()
L = int((N - 1) ** 0.5 + 10)
L = min(N - 1, L)
x = max(F(n) for n in range(1, L + 1))
y = max(G(n) for n in range(1, L + 1))
answer = max(x, y)
print(answer)
| false | 18.604651 | [
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"-N = int(eval(input()))",
"-S = np.array([int(x) for x in input().split()], dtype=np.int64)",
"-# 右移動着地点:等差数列、ゴール含む",
"-# 左移動着地点:等差数列、スタート含む",
"-answer = 0",
"-for d in range(1, N):",
"- # d = A-B",
"- cum_left = np.cumsum(S[::d])",
"- cum_right = np.cumsum(S[::-1][::d])",
"- score = cum_left + cum_right # 等差数列の長さ-1 -> 得点",
"- # あとは、その経路がルール内で実現できるかどうか",
"- for L, s in enumerate(score):",
"- if answer >= s:",
"- continue",
"- # 右左に進んでいることの確認",
"- A = N - 1 - L * d",
"- B = A - d",
"- if A <= 0:",
"- continue",
"- if A <= B:",
"- continue",
"- if B <= 0:",
"- continue",
"- # 同じ場所を取っていないかの確認",
"- # kd = N-1-ldとなるとまずい",
"- # 約数のとき、Ld >= N-Ldだとまずい",
"- if (N - 1) % d == 0 and 2 * L * d >= N - 1:",
"- continue",
"- answer = s",
"+N = int(readline())",
"+S = np.array(read().split(), np.int64)",
"+",
"+",
"+def F(d):",
"+ # 公差を固定",
"+ L = S[:-d:d].cumsum()",
"+ R = S[::-1][:-d:d].cumsum()",
"+ if (N - 1) % d == 0:",
"+ n = (N - 1) // d",
"+ x = np.arange(1, n + 1)",
"+ bl = x + x <= n + 1",
"+ L = L[bl]",
"+ R = R[bl]",
"+ return (L + R).max()",
"+",
"+",
"+def G(n):",
"+ # 項数n+1を固定",
"+ D = (N - 1 - n) // n",
"+ L = np.zeros(D + 1, np.int64)",
"+ R = np.zeros(D + 1, np.int64)",
"+ for i in range(1, n + 1):",
"+ L += S[: i * (D + 1) : i]",
"+ R += S[::-1][: i * (D + 1) : i]",
"+ ok = np.ones(D + 1, np.bool)",
"+ overlap = np.arange(D + 1) * (n + n) >= N - 1",
"+ overlap[1:] &= (N - 1) % np.arange(1, D + 1) == 0",
"+ x = L + R",
"+ x[overlap] = 0",
"+ return x.max()",
"+",
"+",
"+L = int((N - 1) ** 0.5 + 10)",
"+L = min(N - 1, L)",
"+x = max(F(n) for n in range(1, L + 1))",
"+y = max(G(n) for n in range(1, L + 1))",
"+answer = max(x, y)"
] | false | 0.293432 | 0.537464 | 0.545956 | [
"s932273539",
"s230699006"
] |
u077291787 | p03478 | python | s332745312 | s232528772 | 36 | 31 | 3,060 | 3,064 | Accepted | Accepted | 13.89 | # ABC083B - Some Sums
n, a, b = list(map(int, input().rstrip().split()))
total = 0
for i in range(1, n + 1):
if a <= sum(list(map(int, list(str(i))))) <= b:
total += i
print(total) | # ABC083B - Some Sums
def main():
n, a, b = list(map(int, input().rstrip().split()))
ans = 0
for i in range(1, n + 1):
if a <= sum(map(int, list(str(i)))) <= b:
ans += i
print(ans)
if __name__ == "__main__":
main() | 7 | 12 | 198 | 267 | # ABC083B - Some Sums
n, a, b = list(map(int, input().rstrip().split()))
total = 0
for i in range(1, n + 1):
if a <= sum(list(map(int, list(str(i))))) <= b:
total += i
print(total)
| # ABC083B - Some Sums
def main():
n, a, b = list(map(int, input().rstrip().split()))
ans = 0
for i in range(1, n + 1):
if a <= sum(map(int, list(str(i)))) <= b:
ans += i
print(ans)
if __name__ == "__main__":
main()
| false | 41.666667 | [
"-n, a, b = list(map(int, input().rstrip().split()))",
"-total = 0",
"-for i in range(1, n + 1):",
"- if a <= sum(list(map(int, list(str(i))))) <= b:",
"- total += i",
"-print(total)",
"+def main():",
"+ n, a, b = list(map(int, input().rstrip().split()))",
"+ ans = 0",
"+ for i in range(1, n + 1):",
"+ if a <= sum(map(int, list(str(i)))) <= b:",
"+ ans += i",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.037235 | 0.047054 | 0.791325 | [
"s332745312",
"s232528772"
] |
u312025627 | p02863 | python | s830489041 | s169657058 | 356 | 279 | 146,044 | 145,508 | Accepted | Accepted | 21.63 | def main():
N, T = (int(i) for i in input().split())
AB = [[int(i) for i in input().split()] for j in range(N)]
AB.sort()
A = [a[0] for a in AB]
B = [b[1] for b in AB]
dp1 = [[0]*(T+1) for _ in range(N+1)]
for i in range(N):
for j in range(T):
dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j])
t = j - A[i]
if 0 <= t:
dp1[i+1][j] = max(dp1[i+1][j], dp1[i][t] + B[i])
ans = 0
for i in range(N):
ans = max(ans, dp1[i][T-1] + B[i])
print(ans)
if __name__ == '__main__':
main()
| def main():
N, T = (int(i) for i in input().split())
AB = [[int(i) for i in input().split()] for j in range(N)]
AB.sort()
A = [a[0] for a in AB]
B = [b[1] for b in AB]
ans = 0
dp1 = [[0]*(T+1) for _ in range(N+1)]
for i in range(N):
for j in range(T):
t = j - A[i]
if 0 <= t:
dp1[i+1][j] = max(dp1[i][j], dp1[i][t] + B[i])
else:
dp1[i+1][j] = dp1[i][j]
ans = max(ans, dp1[i][T-1] + B[i])
print(ans)
if __name__ == '__main__':
main()
| 23 | 22 | 604 | 581 | def main():
N, T = (int(i) for i in input().split())
AB = [[int(i) for i in input().split()] for j in range(N)]
AB.sort()
A = [a[0] for a in AB]
B = [b[1] for b in AB]
dp1 = [[0] * (T + 1) for _ in range(N + 1)]
for i in range(N):
for j in range(T):
dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j])
t = j - A[i]
if 0 <= t:
dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][t] + B[i])
ans = 0
for i in range(N):
ans = max(ans, dp1[i][T - 1] + B[i])
print(ans)
if __name__ == "__main__":
main()
| def main():
N, T = (int(i) for i in input().split())
AB = [[int(i) for i in input().split()] for j in range(N)]
AB.sort()
A = [a[0] for a in AB]
B = [b[1] for b in AB]
ans = 0
dp1 = [[0] * (T + 1) for _ in range(N + 1)]
for i in range(N):
for j in range(T):
t = j - A[i]
if 0 <= t:
dp1[i + 1][j] = max(dp1[i][j], dp1[i][t] + B[i])
else:
dp1[i + 1][j] = dp1[i][j]
ans = max(ans, dp1[i][T - 1] + B[i])
print(ans)
if __name__ == "__main__":
main()
| false | 4.347826 | [
"+ ans = 0",
"- dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j])",
"- dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][t] + B[i])",
"- ans = 0",
"- for i in range(N):",
"+ dp1[i + 1][j] = max(dp1[i][j], dp1[i][t] + B[i])",
"+ else:",
"+ dp1[i + 1][j] = dp1[i][j]"
] | false | 0.060137 | 0.107451 | 0.559673 | [
"s830489041",
"s169657058"
] |
u901180556 | p04029 | python | s398516194 | s125699573 | 21 | 17 | 2,940 | 2,940 | Accepted | Accepted | 19.05 | N = int(eval(input()))
num = 0
for i in range(1,N+1):
num += i
print(num) | N = int(eval(input()))
print((sum([i for i in range(1, N+1)]))) | 5 | 2 | 73 | 56 | N = int(eval(input()))
num = 0
for i in range(1, N + 1):
num += i
print(num)
| N = int(eval(input()))
print((sum([i for i in range(1, N + 1)])))
| false | 60 | [
"-num = 0",
"-for i in range(1, N + 1):",
"- num += i",
"-print(num)",
"+print((sum([i for i in range(1, N + 1)])))"
] | false | 0.008131 | 0.042296 | 0.192245 | [
"s398516194",
"s125699573"
] |
u814986259 | p03627 | python | s879006120 | s049549057 | 116 | 96 | 21,412 | 18,592 | Accepted | Accepted | 17.24 | import collections
N = int(eval(input()))
A = list(map(int, input().split()))
dic = collections.defaultdict(int)
for x in A:
dic[x] += 1
dic = list(dic.items())
dic = [x for x in dic if x[1] >= 2]
dic = sorted(dic, reverse=True, key=lambda x: x[0])
if len(dic) >= 2:
if dic[0][1] >= 4:
print((dic[0][0] * dic[0][0]))
else:
print((dic[0][0] * dic[1][0]))
else:
print((0))
| import heapq
import collections
N = int(eval(input()))
A = list(map(int, input().split()))
table = collections.defaultdict(int)
hq = [0, 0]
for x in A:
table[x] += 1
if table[x] == 2:
heapq.heappush(hq, -x)
table[x] = 0
print((heapq.heappop(hq) * heapq.heappop(hq)))
| 21 | 13 | 416 | 296 | import collections
N = int(eval(input()))
A = list(map(int, input().split()))
dic = collections.defaultdict(int)
for x in A:
dic[x] += 1
dic = list(dic.items())
dic = [x for x in dic if x[1] >= 2]
dic = sorted(dic, reverse=True, key=lambda x: x[0])
if len(dic) >= 2:
if dic[0][1] >= 4:
print((dic[0][0] * dic[0][0]))
else:
print((dic[0][0] * dic[1][0]))
else:
print((0))
| import heapq
import collections
N = int(eval(input()))
A = list(map(int, input().split()))
table = collections.defaultdict(int)
hq = [0, 0]
for x in A:
table[x] += 1
if table[x] == 2:
heapq.heappush(hq, -x)
table[x] = 0
print((heapq.heappop(hq) * heapq.heappop(hq)))
| false | 38.095238 | [
"+import heapq",
"-dic = collections.defaultdict(int)",
"+table = collections.defaultdict(int)",
"+hq = [0, 0]",
"- dic[x] += 1",
"-dic = list(dic.items())",
"-dic = [x for x in dic if x[1] >= 2]",
"-dic = sorted(dic, reverse=True, key=lambda x: x[0])",
"-if len(dic) >= 2:",
"- if dic[0][1] >= 4:",
"- print((dic[0][0] * dic[0][0]))",
"- else:",
"- print((dic[0][0] * dic[1][0]))",
"-else:",
"- print((0))",
"+ table[x] += 1",
"+ if table[x] == 2:",
"+ heapq.heappush(hq, -x)",
"+ table[x] = 0",
"+print((heapq.heappop(hq) * heapq.heappop(hq)))"
] | false | 0.046043 | 0.043924 | 1.048246 | [
"s879006120",
"s049549057"
] |
u952708174 | p02861 | python | s957759907 | s252390103 | 375 | 17 | 3,064 | 3,188 | Accepted | Accepted | 95.47 | def c_average_length():
from itertools import permutations
from math import factorial
N = int(eval(input()))
Positions = [[int(i) for i in input().split()] for j in range(N)]
ans = 0.0
for route in permutations(list(range(N)), N):
tmp = 0.0
for i in range(N - 1):
cur_v = route[i]
next_v = route[i + 1]
tmp += ((Positions[next_v][0] - Positions[cur_v][0])**2 +
(Positions[next_v][1] - Positions[cur_v][1])**2)**0.5
ans += tmp
return ans / factorial(N)
print((c_average_length())) | def c_average_length():
N = int(eval(input()))
Positions = [[int(i) for i in input().split()] for j in range(N)]
ans = 0.0
for i in range(N):
for j in range(i + 1, N):
ans += ((Positions[i][0] - Positions[j][0])**2 +
(Positions[i][1] - Positions[j][1])**2)**0.5
return ans * 2 / N
print((c_average_length())) | 18 | 12 | 592 | 373 | def c_average_length():
from itertools import permutations
from math import factorial
N = int(eval(input()))
Positions = [[int(i) for i in input().split()] for j in range(N)]
ans = 0.0
for route in permutations(list(range(N)), N):
tmp = 0.0
for i in range(N - 1):
cur_v = route[i]
next_v = route[i + 1]
tmp += (
(Positions[next_v][0] - Positions[cur_v][0]) ** 2
+ (Positions[next_v][1] - Positions[cur_v][1]) ** 2
) ** 0.5
ans += tmp
return ans / factorial(N)
print((c_average_length()))
| def c_average_length():
N = int(eval(input()))
Positions = [[int(i) for i in input().split()] for j in range(N)]
ans = 0.0
for i in range(N):
for j in range(i + 1, N):
ans += (
(Positions[i][0] - Positions[j][0]) ** 2
+ (Positions[i][1] - Positions[j][1]) ** 2
) ** 0.5
return ans * 2 / N
print((c_average_length()))
| false | 33.333333 | [
"- from itertools import permutations",
"- from math import factorial",
"-",
"- for route in permutations(list(range(N)), N):",
"- tmp = 0.0",
"- for i in range(N - 1):",
"- cur_v = route[i]",
"- next_v = route[i + 1]",
"- tmp += (",
"- (Positions[next_v][0] - Positions[cur_v][0]) ** 2",
"- + (Positions[next_v][1] - Positions[cur_v][1]) ** 2",
"+ for i in range(N):",
"+ for j in range(i + 1, N):",
"+ ans += (",
"+ (Positions[i][0] - Positions[j][0]) ** 2",
"+ + (Positions[i][1] - Positions[j][1]) ** 2",
"- ans += tmp",
"- return ans / factorial(N)",
"+ return ans * 2 / N"
] | false | 0.044517 | 0.038626 | 1.152514 | [
"s957759907",
"s252390103"
] |
u392319141 | p03688 | python | s530222528 | s094308086 | 59 | 53 | 14,008 | 22,636 | Accepted | Accepted | 10.17 | N = int(eval(input()))
A = list(map(int, input().split()))
minColor = min(A)
maxColor = max(A)
if minColor == maxColor:
if minColor == N - 1: # 各色の猫が1匹ずつ
print('Yes')
elif minColor * 2 <= N: # 各色の猫が2匹以上
print('Yes')
else:
print('No')
exit()
if minColor + 1 != maxColor:
print('No')
exit()
minCnt = 0
maxCnt = 0
for a in A:
if a == minColor:
minCnt += 1
elif a == maxColor:
maxCnt += 1
else:
print('No')
exit()
# minCnt : 1匹だけの色
# maxCnt : 2匹以上の色
# 全体でmaxColor個の色
if (maxColor - minCnt) * 2 <= maxCnt and maxColor >= minCnt + 1:
print('Yes')
else:
print('No')
| from collections import Counter
N = int(eval(input()))
A = Counter(list(map(int, input().split())))
if len(list(A.keys())) >= 3:
print('No')
exit()
if len(list(A.keys())) == 1:
p = list(A.keys())[0]
print(('Yes' if 2 * p <= N or p == N - 1 else 'No'))
exit()
p1, p2 = sorted(A.keys())
print(('Yes' if p2 - p1 == 1 and (A[p1] + 1) <= p2 <= (A[p1] + A[p2] // 2) else 'No'))
| 39 | 16 | 700 | 383 | N = int(eval(input()))
A = list(map(int, input().split()))
minColor = min(A)
maxColor = max(A)
if minColor == maxColor:
if minColor == N - 1: # 各色の猫が1匹ずつ
print("Yes")
elif minColor * 2 <= N: # 各色の猫が2匹以上
print("Yes")
else:
print("No")
exit()
if minColor + 1 != maxColor:
print("No")
exit()
minCnt = 0
maxCnt = 0
for a in A:
if a == minColor:
minCnt += 1
elif a == maxColor:
maxCnt += 1
else:
print("No")
exit()
# minCnt : 1匹だけの色
# maxCnt : 2匹以上の色
# 全体でmaxColor個の色
if (maxColor - minCnt) * 2 <= maxCnt and maxColor >= minCnt + 1:
print("Yes")
else:
print("No")
| from collections import Counter
N = int(eval(input()))
A = Counter(list(map(int, input().split())))
if len(list(A.keys())) >= 3:
print("No")
exit()
if len(list(A.keys())) == 1:
p = list(A.keys())[0]
print(("Yes" if 2 * p <= N or p == N - 1 else "No"))
exit()
p1, p2 = sorted(A.keys())
print(("Yes" if p2 - p1 == 1 and (A[p1] + 1) <= p2 <= (A[p1] + A[p2] // 2) else "No"))
| false | 58.974359 | [
"+from collections import Counter",
"+",
"-A = list(map(int, input().split()))",
"-minColor = min(A)",
"-maxColor = max(A)",
"-if minColor == maxColor:",
"- if minColor == N - 1: # 各色の猫が1匹ずつ",
"- print(\"Yes\")",
"- elif minColor * 2 <= N: # 各色の猫が2匹以上",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"- exit()",
"-if minColor + 1 != maxColor:",
"+A = Counter(list(map(int, input().split())))",
"+if len(list(A.keys())) >= 3:",
"-minCnt = 0",
"-maxCnt = 0",
"-for a in A:",
"- if a == minColor:",
"- minCnt += 1",
"- elif a == maxColor:",
"- maxCnt += 1",
"- else:",
"- print(\"No\")",
"- exit()",
"-# minCnt : 1匹だけの色",
"-# maxCnt : 2匹以上の色",
"-# 全体でmaxColor個の色",
"-if (maxColor - minCnt) * 2 <= maxCnt and maxColor >= minCnt + 1:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+if len(list(A.keys())) == 1:",
"+ p = list(A.keys())[0]",
"+ print((\"Yes\" if 2 * p <= N or p == N - 1 else \"No\"))",
"+ exit()",
"+p1, p2 = sorted(A.keys())",
"+print((\"Yes\" if p2 - p1 == 1 and (A[p1] + 1) <= p2 <= (A[p1] + A[p2] // 2) else \"No\"))"
] | false | 0.040494 | 0.041533 | 0.974978 | [
"s530222528",
"s094308086"
] |
u536034761 | p02555 | python | s948602992 | s321910314 | 33 | 29 | 10,164 | 9,144 | Accepted | Accepted | 12.12 | from functools import lru_cache
import sys
sys.setrecursionlimit(2000)
mod = 10 ** 9 + 7
@lru_cache(maxsize=None)
def dp(i):
if i == 1 or i == 2:
return 0
elif i == 3 or i == 4:
return 1
else:
return (dp(i - 3) + dp(i - 1)) % mod
S = int(eval(input()))
print((dp(S)))
| S = int(eval(input()))
if S == 1 or S == 2:
print((0))
elif S == 3:
print((1))
else:
mod = 10 ** 9 + 7
dp = [0 for _ in range(S)]
dp[0] = dp[1] = 0
dp[2] = dp[3] = 1
for i in range(3, S):
dp[i] = (dp[i - 3] + dp[i - 1]) % mod
print((dp[-1])) | 18 | 17 | 317 | 289 | from functools import lru_cache
import sys
sys.setrecursionlimit(2000)
mod = 10**9 + 7
@lru_cache(maxsize=None)
def dp(i):
if i == 1 or i == 2:
return 0
elif i == 3 or i == 4:
return 1
else:
return (dp(i - 3) + dp(i - 1)) % mod
S = int(eval(input()))
print((dp(S)))
| S = int(eval(input()))
if S == 1 or S == 2:
print((0))
elif S == 3:
print((1))
else:
mod = 10**9 + 7
dp = [0 for _ in range(S)]
dp[0] = dp[1] = 0
dp[2] = dp[3] = 1
for i in range(3, S):
dp[i] = (dp[i - 3] + dp[i - 1]) % mod
print((dp[-1]))
| false | 5.555556 | [
"-from functools import lru_cache",
"-import sys",
"-",
"-sys.setrecursionlimit(2000)",
"-mod = 10**9 + 7",
"-",
"-",
"-@lru_cache(maxsize=None)",
"-def dp(i):",
"- if i == 1 or i == 2:",
"- return 0",
"- elif i == 3 or i == 4:",
"- return 1",
"- else:",
"- return (dp(i - 3) + dp(i - 1)) % mod",
"-",
"-",
"-print((dp(S)))",
"+if S == 1 or S == 2:",
"+ print((0))",
"+elif S == 3:",
"+ print((1))",
"+else:",
"+ mod = 10**9 + 7",
"+ dp = [0 for _ in range(S)]",
"+ dp[0] = dp[1] = 0",
"+ dp[2] = dp[3] = 1",
"+ for i in range(3, S):",
"+ dp[i] = (dp[i - 3] + dp[i - 1]) % mod",
"+ print((dp[-1]))"
] | false | 0.046002 | 0.045653 | 1.007642 | [
"s948602992",
"s321910314"
] |
u282228874 | p03062 | python | s220266292 | s992233195 | 104 | 62 | 14,284 | 14,412 | Accepted | Accepted | 40.38 | n = int(eval(input()))
A = list(map(int,input().split()))
cnt = 0
for a in A:
if a < 0:
cnt += 1
res = 0
A = [abs(a) for a in A]
A.sort()
for a in A:
res += a
if cnt%2 == 1:
res -= 2*A[0]
print(res) | n = int(eval(input()))
A = list(map(int,input().split()))
cnt = 0
for a in A:
if a < 0:
cnt += 1
A = [abs(a) for a in A]
res = sum(A)
if cnt%2 == 1:
res -= 2*min(A)
print(res) | 14 | 11 | 229 | 195 | n = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for a in A:
if a < 0:
cnt += 1
res = 0
A = [abs(a) for a in A]
A.sort()
for a in A:
res += a
if cnt % 2 == 1:
res -= 2 * A[0]
print(res)
| n = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for a in A:
if a < 0:
cnt += 1
A = [abs(a) for a in A]
res = sum(A)
if cnt % 2 == 1:
res -= 2 * min(A)
print(res)
| false | 21.428571 | [
"-res = 0",
"-A.sort()",
"-for a in A:",
"- res += a",
"+res = sum(A)",
"- res -= 2 * A[0]",
"+ res -= 2 * min(A)"
] | false | 0.035068 | 0.083991 | 0.417524 | [
"s220266292",
"s992233195"
] |
u860002137 | p02923 | python | s914442328 | s319161948 | 279 | 79 | 23,388 | 20,540 | Accepted | Accepted | 71.68 | import numpy as np
N = int(eval(input()))
H = np.array(list(map(int, input().split())))
diff = H[:-1] - H[1:]
ans = 0
tmp = 0
for d in diff:
if d>=0:
tmp += 1
if ans<tmp:
ans = tmp
else:
tmp = 0
print(ans) | n = int(eval(input()))
h = list(map(int, input().split()))
tmp = 0
ans = 0
for i in range(n - 1):
if h[i] >= h[i + 1]:
tmp += 1
else:
ans = max(ans, tmp)
tmp = 0
ans = max(ans, tmp)
print(ans) | 17 | 14 | 262 | 233 | import numpy as np
N = int(eval(input()))
H = np.array(list(map(int, input().split())))
diff = H[:-1] - H[1:]
ans = 0
tmp = 0
for d in diff:
if d >= 0:
tmp += 1
if ans < tmp:
ans = tmp
else:
tmp = 0
print(ans)
| n = int(eval(input()))
h = list(map(int, input().split()))
tmp = 0
ans = 0
for i in range(n - 1):
if h[i] >= h[i + 1]:
tmp += 1
else:
ans = max(ans, tmp)
tmp = 0
ans = max(ans, tmp)
print(ans)
| false | 17.647059 | [
"-import numpy as np",
"-",
"-N = int(eval(input()))",
"-H = np.array(list(map(int, input().split())))",
"-diff = H[:-1] - H[1:]",
"+n = int(eval(input()))",
"+h = list(map(int, input().split()))",
"+tmp = 0",
"-tmp = 0",
"-for d in diff:",
"- if d >= 0:",
"+for i in range(n - 1):",
"+ if h[i] >= h[i + 1]:",
"- if ans < tmp:",
"- ans = tmp",
"+ ans = max(ans, tmp)",
"+ans = max(ans, tmp)"
] | false | 0.258778 | 0.036736 | 7.044342 | [
"s914442328",
"s319161948"
] |
u642012866 | p02898 | python | s287337429 | s420981340 | 48 | 42 | 11,916 | 9,992 | Accepted | Accepted | 12.5 | N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
cnt = 0
for f in h:
if f >= K:
cnt += 1
print(cnt) | N, K = list(map(int, input().split()))
print((len([0 for x in map(int, input().split()) if x >= K]))) | 7 | 2 | 137 | 94 | N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
cnt = 0
for f in h:
if f >= K:
cnt += 1
print(cnt)
| N, K = list(map(int, input().split()))
print((len([0 for x in map(int, input().split()) if x >= K])))
| false | 71.428571 | [
"-h = list(map(int, input().split()))",
"-cnt = 0",
"-for f in h:",
"- if f >= K:",
"- cnt += 1",
"-print(cnt)",
"+print((len([0 for x in map(int, input().split()) if x >= K])))"
] | false | 0.035566 | 0.036039 | 0.986873 | [
"s287337429",
"s420981340"
] |
u073729602 | p02982 | python | s223066846 | s235492276 | 29 | 25 | 9,456 | 9,336 | Accepted | Accepted | 13.79 | import itertools
n, d = list(map(int, input().split()))
x = []
s = []
for i in range(n):
s.append(i)
a = list(map(int, input().split()))
x.append(a)
ans = 0
for v in itertools.combinations(s, 2):
t = 0
for i in range(d):
t += (x[v[0]][i] - x[v[1]][i])**2
if (t**0.5).is_integer():
ans += 1
print(ans) | # 少しめんどくさい方法です。
import itertools
n, d = list(map(int, input().split()))
x = []
s = [] # 組み合わせ用の変数。
for i in range(n):
s.append(i)
a = list(map(int, input().split()))
x.append(a)
# 単純に組み合わせで判定する。
ans = 0
for v in itertools.combinations(s, 2):
t = 0
# 距離を判定する。
for i in range(d):
t += (x[v[0]][i] - x[v[1]][i])**2
# 少数かどうか?
if (t**0.5).is_integer():
ans += 1
print(ans)
| 17 | 20 | 351 | 430 | import itertools
n, d = list(map(int, input().split()))
x = []
s = []
for i in range(n):
s.append(i)
a = list(map(int, input().split()))
x.append(a)
ans = 0
for v in itertools.combinations(s, 2):
t = 0
for i in range(d):
t += (x[v[0]][i] - x[v[1]][i]) ** 2
if (t**0.5).is_integer():
ans += 1
print(ans)
| # 少しめんどくさい方法です。
import itertools
n, d = list(map(int, input().split()))
x = []
s = [] # 組み合わせ用の変数。
for i in range(n):
s.append(i)
a = list(map(int, input().split()))
x.append(a)
# 単純に組み合わせで判定する。
ans = 0
for v in itertools.combinations(s, 2):
t = 0
# 距離を判定する。
for i in range(d):
t += (x[v[0]][i] - x[v[1]][i]) ** 2
# 少数かどうか?
if (t**0.5).is_integer():
ans += 1
print(ans)
| false | 15 | [
"+# 少しめんどくさい方法です。",
"-s = []",
"+s = [] # 組み合わせ用の変数。",
"+# 単純に組み合わせで判定する。",
"+ # 距離を判定する。",
"+ # 少数かどうか?"
] | false | 0.038007 | 0.037758 | 1.006601 | [
"s223066846",
"s235492276"
] |
u353797797 | p03163 | python | s960002875 | s129759163 | 1,956 | 1,468 | 9,460 | 7,668 | Accepted | Accepted | 24.95 | import sys
input=sys.stdin.readline
n, cap = list(map(int, input().split()))
val =[0]*(cap+1)
def nap(n,cap):
for _ in range(n):
w, v = list(map(int, input().split()))
for wk in range(cap,w-1,-1):
nv=val[wk-w]+v
if val[wk]<nv:
val[wk]=nv
return max(val)
print((nap(n,cap)))
| import sys
input = sys.stdin.readline
def nap(n, cap):
val = [0] * (cap + 1)
for _ in range(n):
w, v = list(map(int, input().split()))
for wk in range(cap, w - 1, -1):
nv = val[wk - w] + v
if val[wk] < nv:
val[wk] = nv
return max(val)
n, cap = list(map(int, input().split()))
print((nap(n, cap)))
| 14 | 18 | 338 | 373 | import sys
input = sys.stdin.readline
n, cap = list(map(int, input().split()))
val = [0] * (cap + 1)
def nap(n, cap):
for _ in range(n):
w, v = list(map(int, input().split()))
for wk in range(cap, w - 1, -1):
nv = val[wk - w] + v
if val[wk] < nv:
val[wk] = nv
return max(val)
print((nap(n, cap)))
| import sys
input = sys.stdin.readline
def nap(n, cap):
val = [0] * (cap + 1)
for _ in range(n):
w, v = list(map(int, input().split()))
for wk in range(cap, w - 1, -1):
nv = val[wk - w] + v
if val[wk] < nv:
val[wk] = nv
return max(val)
n, cap = list(map(int, input().split()))
print((nap(n, cap)))
| false | 22.222222 | [
"-n, cap = list(map(int, input().split()))",
"-val = [0] * (cap + 1)",
"+ val = [0] * (cap + 1)",
"+n, cap = list(map(int, input().split()))"
] | false | 0.043849 | 0.045413 | 0.965554 | [
"s960002875",
"s129759163"
] |
u539692012 | p02659 | python | s555026473 | s400239062 | 24 | 22 | 9,160 | 9,156 | Accepted | Accepted | 8.33 | a, b = input().split()
a = int(a)
b = int(b.replace('.', ''))
c = str(a * b)[:-2]
if c == '':
print((0))
else:
print(c)
| a,b=list(map(int,input().replace('.','').split()))
print((a*b//100)) | 8 | 2 | 133 | 61 | a, b = input().split()
a = int(a)
b = int(b.replace(".", ""))
c = str(a * b)[:-2]
if c == "":
print((0))
else:
print(c)
| a, b = list(map(int, input().replace(".", "").split()))
print((a * b // 100))
| false | 75 | [
"-a, b = input().split()",
"-a = int(a)",
"-b = int(b.replace(\".\", \"\"))",
"-c = str(a * b)[:-2]",
"-if c == \"\":",
"- print((0))",
"-else:",
"- print(c)",
"+a, b = list(map(int, input().replace(\".\", \"\").split()))",
"+print((a * b // 100))"
] | false | 0.033053 | 0.066159 | 0.499605 | [
"s555026473",
"s400239062"
] |
u212328220 | p03835 | python | s750594762 | s430731456 | 1,451 | 1,147 | 3,064 | 9,172 | Accepted | Accepted | 20.95 | K, S = list(map(int, input().split()))
counter = 0
for x in range(K+1):
for y in range(K+1):
z = S - x - y
if 0 <= z <= K:
counter += 1
print(counter)
| k, s = list(map(int,input().split()))
cnt = 0
for x in range(k+1):
for y in range(k+1):
z = s - x - y
if 0 <= z <= k:
cnt += 1
print(cnt) | 9 | 9 | 186 | 172 | K, S = list(map(int, input().split()))
counter = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - x - y
if 0 <= z <= K:
counter += 1
print(counter)
| k, s = list(map(int, input().split()))
cnt = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if 0 <= z <= k:
cnt += 1
print(cnt)
| false | 0 | [
"-K, S = list(map(int, input().split()))",
"-counter = 0",
"-for x in range(K + 1):",
"- for y in range(K + 1):",
"- z = S - x - y",
"- if 0 <= z <= K:",
"- counter += 1",
"-print(counter)",
"+k, s = list(map(int, input().split()))",
"+cnt = 0",
"+for x in range(k + 1):",
"+ for y in range(k + 1):",
"+ z = s - x - y",
"+ if 0 <= z <= k:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.055409 | 0.054698 | 1.012986 | [
"s750594762",
"s430731456"
] |
u775586391 | p00044 | python | s446622175 | s223461181 | 150 | 70 | 8,216 | 7,924 | Accepted | Accepted | 53.33 | import sys
def furui(n):
l = [1 for i in range(n+1)]
l[0] = 0
l[1] = 0
for i in range(2,n+1):
if l[i] == 1:
for j in range(2,n//i+1):
l[i*j] = 0
l2 = []
for i in range (len(l)):
if l[i] == 1:
l2.append(i)
return l2
for line in sys.stdin:
n = int(line)
l = furui(n)
if max(l) == n:
i1 = l[len(l)-2]
else:
i1 = max(l)
i2 = n
while True:
i2 += 1
flag = 1
for i in l:
if i2 % i == 0:
flag = 0
break
if flag:
break
print((str(i1) + " " + str(i2))) | MAX = 60000
lst = [i for i in range(MAX)]
lst[0] = lst[1] = 0
for i in range(MAX):
if lst[i] != 0:
for j in range(i * 2, MAX, i):
lst[j] = 0
while 0 == 0:
try:
n = int(eval(input()))
i = n - 1
j = n + 1
while lst[i] == 0:
i -= 1
while lst[j] == 0:
j += 1
print((str(lst[i]) + " " + str(lst[j])))
except EOFError:
break
| 34 | 19 | 583 | 385 | import sys
def furui(n):
l = [1 for i in range(n + 1)]
l[0] = 0
l[1] = 0
for i in range(2, n + 1):
if l[i] == 1:
for j in range(2, n // i + 1):
l[i * j] = 0
l2 = []
for i in range(len(l)):
if l[i] == 1:
l2.append(i)
return l2
for line in sys.stdin:
n = int(line)
l = furui(n)
if max(l) == n:
i1 = l[len(l) - 2]
else:
i1 = max(l)
i2 = n
while True:
i2 += 1
flag = 1
for i in l:
if i2 % i == 0:
flag = 0
break
if flag:
break
print((str(i1) + " " + str(i2)))
| MAX = 60000
lst = [i for i in range(MAX)]
lst[0] = lst[1] = 0
for i in range(MAX):
if lst[i] != 0:
for j in range(i * 2, MAX, i):
lst[j] = 0
while 0 == 0:
try:
n = int(eval(input()))
i = n - 1
j = n + 1
while lst[i] == 0:
i -= 1
while lst[j] == 0:
j += 1
print((str(lst[i]) + " " + str(lst[j])))
except EOFError:
break
| false | 44.117647 | [
"-import sys",
"-",
"-",
"-def furui(n):",
"- l = [1 for i in range(n + 1)]",
"- l[0] = 0",
"- l[1] = 0",
"- for i in range(2, n + 1):",
"- if l[i] == 1:",
"- for j in range(2, n // i + 1):",
"- l[i * j] = 0",
"- l2 = []",
"- for i in range(len(l)):",
"- if l[i] == 1:",
"- l2.append(i)",
"- return l2",
"-",
"-",
"-for line in sys.stdin:",
"- n = int(line)",
"- l = furui(n)",
"- if max(l) == n:",
"- i1 = l[len(l) - 2]",
"- else:",
"- i1 = max(l)",
"- i2 = n",
"- while True:",
"- i2 += 1",
"- flag = 1",
"- for i in l:",
"- if i2 % i == 0:",
"- flag = 0",
"- break",
"- if flag:",
"- break",
"- print((str(i1) + \" \" + str(i2)))",
"+MAX = 60000",
"+lst = [i for i in range(MAX)]",
"+lst[0] = lst[1] = 0",
"+for i in range(MAX):",
"+ if lst[i] != 0:",
"+ for j in range(i * 2, MAX, i):",
"+ lst[j] = 0",
"+while 0 == 0:",
"+ try:",
"+ n = int(eval(input()))",
"+ i = n - 1",
"+ j = n + 1",
"+ while lst[i] == 0:",
"+ i -= 1",
"+ while lst[j] == 0:",
"+ j += 1",
"+ print((str(lst[i]) + \" \" + str(lst[j])))",
"+ except EOFError:",
"+ break"
] | false | 0.041708 | 0.076095 | 0.548107 | [
"s446622175",
"s223461181"
] |
u369133448 | p02584 | python | s421986675 | s138616180 | 36 | 32 | 9,152 | 9,128 | Accepted | Accepted | 11.11 | x,k,d=list(map(int,input().split()))
x=abs(x)
sa=x//d
ans=x
pbk,mbk=0,0
bk1,bk2,bk3=1,1,1
mansbk,pansbk=0,0
if sa>=k:
ans=x-d*k
else:
ans=x-d*sa
k=k-sa
for i in range(k):
mansbk=abs(ans-d)
pansbk=abs(ans+d)
if mansbk!=pansbk:
ans=min(mansbk,pansbk)
if bk3!=1:
bk1=min(mansbk,pansbk)
bk2=max(mansbk,pansbk)
ans=mbk if (k-i)%2==0 else bk1
break
else:
bk3=max(mansbk,pansbk)
else:
ans=0 if (k-i)%2==0 else d
break
pbk=max(mansbk,pansbk)
mbk=min(mansbk,pansbk)
print(ans) | x,k,d=list(map(int,input().split()))
x=abs(x)
m=min(k,x//d)
x-=d*m
k-=m
k%=2
x-=d*k
print((abs(x))) | 30 | 8 | 593 | 98 | x, k, d = list(map(int, input().split()))
x = abs(x)
sa = x // d
ans = x
pbk, mbk = 0, 0
bk1, bk2, bk3 = 1, 1, 1
mansbk, pansbk = 0, 0
if sa >= k:
ans = x - d * k
else:
ans = x - d * sa
k = k - sa
for i in range(k):
mansbk = abs(ans - d)
pansbk = abs(ans + d)
if mansbk != pansbk:
ans = min(mansbk, pansbk)
if bk3 != 1:
bk1 = min(mansbk, pansbk)
bk2 = max(mansbk, pansbk)
ans = mbk if (k - i) % 2 == 0 else bk1
break
else:
bk3 = max(mansbk, pansbk)
else:
ans = 0 if (k - i) % 2 == 0 else d
break
pbk = max(mansbk, pansbk)
mbk = min(mansbk, pansbk)
print(ans)
| x, k, d = list(map(int, input().split()))
x = abs(x)
m = min(k, x // d)
x -= d * m
k -= m
k %= 2
x -= d * k
print((abs(x)))
| false | 73.333333 | [
"-sa = x // d",
"-ans = x",
"-pbk, mbk = 0, 0",
"-bk1, bk2, bk3 = 1, 1, 1",
"-mansbk, pansbk = 0, 0",
"-if sa >= k:",
"- ans = x - d * k",
"-else:",
"- ans = x - d * sa",
"- k = k - sa",
"- for i in range(k):",
"- mansbk = abs(ans - d)",
"- pansbk = abs(ans + d)",
"- if mansbk != pansbk:",
"- ans = min(mansbk, pansbk)",
"- if bk3 != 1:",
"- bk1 = min(mansbk, pansbk)",
"- bk2 = max(mansbk, pansbk)",
"- ans = mbk if (k - i) % 2 == 0 else bk1",
"- break",
"- else:",
"- bk3 = max(mansbk, pansbk)",
"- else:",
"- ans = 0 if (k - i) % 2 == 0 else d",
"- break",
"- pbk = max(mansbk, pansbk)",
"- mbk = min(mansbk, pansbk)",
"-print(ans)",
"+m = min(k, x // d)",
"+x -= d * m",
"+k -= m",
"+k %= 2",
"+x -= d * k",
"+print((abs(x)))"
] | false | 0.046057 | 0.045852 | 1.004476 | [
"s421986675",
"s138616180"
] |
u254871849 | p03416 | python | s838954646 | s673810390 | 20 | 18 | 3,064 | 3,064 | Accepted | Accepted | 10 | import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r
a, b = list(map(int, sys.stdin.readline().split()))
def main():
palindromic_nums = []
for i in range(1, 10):
for j in range(10):
for k in range(10):
x = [i, j, k, j, i]
palindromic_nums.append(int(''.join(list(map(str, x)))))
return bi_r(palindromic_nums, b) - bi_l(palindromic_nums, a)
if __name__ == '__main__':
ans = main()
print(ans) | import sys
def cnt(n):
m = str(n)
l = len(m)
if l == 1: return n + 1
tot = 0
tot += pow(10, (l - 1) // 2) * (int(m[0]) - 1)
tot += pow(10, l // 2) - 1 - 9 * pow(10, l // 2 - 1) * (l & 1 ^ 1)
while l >= 2:
l -= 2
if l == 0: tot += m[1] >= m[0]
elif l == 1: tot += int(m[1]) + 1 - (m[-1] < m[0])
else:
m = str(int(m[1:-1]) - (m[-1] < m[0]))
m = '0' * (l - len(m)) + m
tot += int(m[0]) * pow(10, (l - 1) // 2)
return tot
a, b = list(map(int, sys.stdin.readline().split()))
def main():
print((cnt(b) - cnt(a-1)))
if __name__ == '__main__':
main() | 18 | 26 | 512 | 672 | import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r
a, b = list(map(int, sys.stdin.readline().split()))
def main():
palindromic_nums = []
for i in range(1, 10):
for j in range(10):
for k in range(10):
x = [i, j, k, j, i]
palindromic_nums.append(int("".join(list(map(str, x)))))
return bi_r(palindromic_nums, b) - bi_l(palindromic_nums, a)
if __name__ == "__main__":
ans = main()
print(ans)
| import sys
def cnt(n):
m = str(n)
l = len(m)
if l == 1:
return n + 1
tot = 0
tot += pow(10, (l - 1) // 2) * (int(m[0]) - 1)
tot += pow(10, l // 2) - 1 - 9 * pow(10, l // 2 - 1) * (l & 1 ^ 1)
while l >= 2:
l -= 2
if l == 0:
tot += m[1] >= m[0]
elif l == 1:
tot += int(m[1]) + 1 - (m[-1] < m[0])
else:
m = str(int(m[1:-1]) - (m[-1] < m[0]))
m = "0" * (l - len(m)) + m
tot += int(m[0]) * pow(10, (l - 1) // 2)
return tot
a, b = list(map(int, sys.stdin.readline().split()))
def main():
print((cnt(b) - cnt(a - 1)))
if __name__ == "__main__":
main()
| false | 30.769231 | [
"-from bisect import bisect_left as bi_l, bisect_right as bi_r",
"+",
"+",
"+def cnt(n):",
"+ m = str(n)",
"+ l = len(m)",
"+ if l == 1:",
"+ return n + 1",
"+ tot = 0",
"+ tot += pow(10, (l - 1) // 2) * (int(m[0]) - 1)",
"+ tot += pow(10, l // 2) - 1 - 9 * pow(10, l // 2 - 1) * (l & 1 ^ 1)",
"+ while l >= 2:",
"+ l -= 2",
"+ if l == 0:",
"+ tot += m[1] >= m[0]",
"+ elif l == 1:",
"+ tot += int(m[1]) + 1 - (m[-1] < m[0])",
"+ else:",
"+ m = str(int(m[1:-1]) - (m[-1] < m[0]))",
"+ m = \"0\" * (l - len(m)) + m",
"+ tot += int(m[0]) * pow(10, (l - 1) // 2)",
"+ return tot",
"+",
"- palindromic_nums = []",
"- for i in range(1, 10):",
"- for j in range(10):",
"- for k in range(10):",
"- x = [i, j, k, j, i]",
"- palindromic_nums.append(int(\"\".join(list(map(str, x)))))",
"- return bi_r(palindromic_nums, b) - bi_l(palindromic_nums, a)",
"+ print((cnt(b) - cnt(a - 1)))",
"- ans = main()",
"- print(ans)",
"+ main()"
] | false | 0.045957 | 0.037793 | 1.216003 | [
"s838954646",
"s673810390"
] |
u969850098 | p02762 | python | s331439565 | s101550108 | 1,573 | 1,198 | 110,112 | 31,872 | Accepted | Accepted | 23.84 | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
N, M, K = map(int, input().split())
num_friends = [0 for _ in range(N)]
blocks = [[] for _ in range(N)]
uf = UnionFind(N)
for _ in range(M):
a, b = map(int, input().split())
num_friends[a-1] += 1
num_friends[b-1] += 1
uf.union(a-1, b-1)
for _ in range(K):
a, b = map(int, input().split())
blocks[a-1].append(b-1)
blocks[b-1].append(a-1)
for i in range(N):
cnt = uf.size(i) - 1 - num_friends[i]
for j in blocks[i]:
if uf.same(i, j):
cnt -= 1
print(cnt, end=' ')
if __name__ == "__main__":
main()
| class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
N, M, K = list(map(int, input().split()))
num_friends = [0 for _ in range(N)]
blocks = [[] for _ in range(N)]
uf = UnionFind(N)
for _ in range(M):
a, b = list(map(int, input().split()))
num_friends[a-1] += 1
num_friends[b-1] += 1
uf.union(a-1, b-1)
for _ in range(K):
a, b = list(map(int, input().split()))
blocks[a-1].append(b-1)
blocks[b-1].append(a-1)
ans = []
for i in range(N):
cnt = uf.size(i) - 1 - num_friends[i]
for j in blocks[i]:
if uf.same(i, j):
cnt -= 1
ans.append(cnt)
print((*ans))
if __name__ == "__main__":
main() | 73 | 76 | 1,869 | 1,902 | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
N, M, K = map(int, input().split())
num_friends = [0 for _ in range(N)]
blocks = [[] for _ in range(N)]
uf = UnionFind(N)
for _ in range(M):
a, b = map(int, input().split())
num_friends[a - 1] += 1
num_friends[b - 1] += 1
uf.union(a - 1, b - 1)
for _ in range(K):
a, b = map(int, input().split())
blocks[a - 1].append(b - 1)
blocks[b - 1].append(a - 1)
for i in range(N):
cnt = uf.size(i) - 1 - num_friends[i]
for j in blocks[i]:
if uf.same(i, j):
cnt -= 1
print(cnt, end=" ")
if __name__ == "__main__":
main()
| class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
N, M, K = list(map(int, input().split()))
num_friends = [0 for _ in range(N)]
blocks = [[] for _ in range(N)]
uf = UnionFind(N)
for _ in range(M):
a, b = list(map(int, input().split()))
num_friends[a - 1] += 1
num_friends[b - 1] += 1
uf.union(a - 1, b - 1)
for _ in range(K):
a, b = list(map(int, input().split()))
blocks[a - 1].append(b - 1)
blocks[b - 1].append(a - 1)
ans = []
for i in range(N):
cnt = uf.size(i) - 1 - num_friends[i]
for j in blocks[i]:
if uf.same(i, j):
cnt -= 1
ans.append(cnt)
print((*ans))
if __name__ == "__main__":
main()
| false | 3.947368 | [
"- N, M, K = map(int, input().split())",
"+ N, M, K = list(map(int, input().split()))",
"- a, b = map(int, input().split())",
"+ a, b = list(map(int, input().split()))",
"- a, b = map(int, input().split())",
"+ a, b = list(map(int, input().split()))",
"+ ans = []",
"- print(cnt, end=\" \")",
"+ ans.append(cnt)",
"+ print((*ans))"
] | false | 0.037009 | 0.036465 | 1.014904 | [
"s331439565",
"s101550108"
] |
u470560351 | p02793 | python | s011528002 | s791623598 | 1,894 | 1,658 | 6,136 | 6,200 | Accepted | Accepted | 12.46 | from fractions import gcd
N=int(eval(input()))
a_list = tuple(int(i) for i in input().split())
MOD = 10**9+7
def cal_lcm(a, b):
return int(a*b//gcd(a,b))
lcm = 1
for i in range(N):
lcm = cal_lcm(lcm, a_list[i])
ans = 0
for i in range(N):
ans += lcm//a_list[i]
print((ans%MOD)) | import sys
input = sys.stdin.readline
from fractions import gcd
N=int(eval(input()))
a_list = list(map(int, input().split()))
MOD = 10**9+7
def cal_lcm(a, b):
return int(a*b//gcd(a,b))
lcm = 1
ans = 0
for i in range(N):
lcm_ = cal_lcm(lcm, a_list[i])
ans = ans*(lcm_//lcm)
ans = (ans + (lcm_//a_list[i]))
lcm = lcm_
print((ans%MOD)) | 17 | 20 | 297 | 359 | from fractions import gcd
N = int(eval(input()))
a_list = tuple(int(i) for i in input().split())
MOD = 10**9 + 7
def cal_lcm(a, b):
return int(a * b // gcd(a, b))
lcm = 1
for i in range(N):
lcm = cal_lcm(lcm, a_list[i])
ans = 0
for i in range(N):
ans += lcm // a_list[i]
print((ans % MOD))
| import sys
input = sys.stdin.readline
from fractions import gcd
N = int(eval(input()))
a_list = list(map(int, input().split()))
MOD = 10**9 + 7
def cal_lcm(a, b):
return int(a * b // gcd(a, b))
lcm = 1
ans = 0
for i in range(N):
lcm_ = cal_lcm(lcm, a_list[i])
ans = ans * (lcm_ // lcm)
ans = ans + (lcm_ // a_list[i])
lcm = lcm_
print((ans % MOD))
| false | 15 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-a_list = tuple(int(i) for i in input().split())",
"+a_list = list(map(int, input().split()))",
"-for i in range(N):",
"- lcm = cal_lcm(lcm, a_list[i])",
"- ans += lcm // a_list[i]",
"+ lcm_ = cal_lcm(lcm, a_list[i])",
"+ ans = ans * (lcm_ // lcm)",
"+ ans = ans + (lcm_ // a_list[i])",
"+ lcm = lcm_"
] | false | 0.058931 | 0.060342 | 0.976619 | [
"s011528002",
"s791623598"
] |
u547167033 | p03608 | python | s241084985 | s545397695 | 674 | 458 | 18,868 | 46,840 | Accepted | Accepted | 32.05 | from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall
n,m,r=list(map(int,input().split()))
vis=list(map(int,input().split()))
INF=10**18
path=[[INF]*n for i in range(n)]
for i in range(m):
a,b,c=list(map(int,input().split()))
path[a-1][b-1]=c
path[b-1][a-1]=c
path=floyd_warshall(path)
ans=10**18
for root in permutations(vis):
cnt=0
for j in range(1,r):
cnt+=path[root[j-1]-1][root[j]-1]
ans=min(ans,cnt)
print((int(ans))) | import itertools
n,m,r=list(map(int,input().split()))
point=list(map(int,input().split()))
g=[[10**9]*n for i in range(n)]
for _ in range(m):
u,v,c=list(map(int,input().split()))
g[u-1][v-1]=g[v-1][u-1]=c
for k in range(n):
for i in range(n):
for j in range(n):
g[i][j]=min(g[i][j],g[i][k]+g[k][j])
for i in range(n):
g[i][i]=0
ans=10**18
for v in itertools.permutations(point):
tmp=0
for i in range(r-1):
tmp+=g[v[i]-1][v[i+1]-1]
ans=min(ans,tmp)
print(ans) | 18 | 20 | 471 | 493 | from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall
n, m, r = list(map(int, input().split()))
vis = list(map(int, input().split()))
INF = 10**18
path = [[INF] * n for i in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
path[a - 1][b - 1] = c
path[b - 1][a - 1] = c
path = floyd_warshall(path)
ans = 10**18
for root in permutations(vis):
cnt = 0
for j in range(1, r):
cnt += path[root[j - 1] - 1][root[j] - 1]
ans = min(ans, cnt)
print((int(ans)))
| import itertools
n, m, r = list(map(int, input().split()))
point = list(map(int, input().split()))
g = [[10**9] * n for i in range(n)]
for _ in range(m):
u, v, c = list(map(int, input().split()))
g[u - 1][v - 1] = g[v - 1][u - 1] = c
for k in range(n):
for i in range(n):
for j in range(n):
g[i][j] = min(g[i][j], g[i][k] + g[k][j])
for i in range(n):
g[i][i] = 0
ans = 10**18
for v in itertools.permutations(point):
tmp = 0
for i in range(r - 1):
tmp += g[v[i] - 1][v[i + 1] - 1]
ans = min(ans, tmp)
print(ans)
| false | 10 | [
"-from itertools import permutations",
"-from scipy.sparse.csgraph import floyd_warshall",
"+import itertools",
"-vis = list(map(int, input().split()))",
"-INF = 10**18",
"-path = [[INF] * n for i in range(n)]",
"-for i in range(m):",
"- a, b, c = list(map(int, input().split()))",
"- path[a - 1][b - 1] = c",
"- path[b - 1][a - 1] = c",
"-path = floyd_warshall(path)",
"+point = list(map(int, input().split()))",
"+g = [[10**9] * n for i in range(n)]",
"+for _ in range(m):",
"+ u, v, c = list(map(int, input().split()))",
"+ g[u - 1][v - 1] = g[v - 1][u - 1] = c",
"+for k in range(n):",
"+ for i in range(n):",
"+ for j in range(n):",
"+ g[i][j] = min(g[i][j], g[i][k] + g[k][j])",
"+for i in range(n):",
"+ g[i][i] = 0",
"-for root in permutations(vis):",
"- cnt = 0",
"- for j in range(1, r):",
"- cnt += path[root[j - 1] - 1][root[j] - 1]",
"- ans = min(ans, cnt)",
"-print((int(ans)))",
"+for v in itertools.permutations(point):",
"+ tmp = 0",
"+ for i in range(r - 1):",
"+ tmp += g[v[i] - 1][v[i + 1] - 1]",
"+ ans = min(ans, tmp)",
"+print(ans)"
] | false | 0.343318 | 0.036406 | 9.43021 | [
"s241084985",
"s545397695"
] |
u373047809 | p02744 | python | s756898408 | s118686402 | 156 | 135 | 24,176 | 24,436 | Accepted | Accepted | 13.46 | k = "a",
for _ in range(int(eval(input())) - 1):
k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
for i in sorted(k):print(i) | k = "a",
for _ in range(int(eval(input())) - 1):
k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
print((*sorted(k))) | 4 | 4 | 132 | 122 | k = ("a",)
for _ in range(int(eval(input())) - 1):
k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
for i in sorted(k):
print(i)
| k = ("a",)
for _ in range(int(eval(input())) - 1):
k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
print((*sorted(k)))
| false | 0 | [
"-for i in sorted(k):",
"- print(i)",
"+print((*sorted(k)))"
] | false | 0.037045 | 0.118021 | 0.313882 | [
"s756898408",
"s118686402"
] |
u268793453 | p03295 | python | s501197200 | s638001266 | 568 | 440 | 29,964 | 22,916 | Accepted | Accepted | 22.54 | from operator import itemgetter
n, m = [int(i) for i in input().split()]
A, B = list(zip(*[[int(i) for i in input().split()] for j in range(m)]))
A, B = list(zip(*sorted(zip(A, B), key=itemgetter(1, 0))))
last = -1
ans = 0
for a, b in zip(A, B):
if last <= a:
ans += 1
last = b
print(ans) | n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.sort(key=lambda a:a[1])
ans = 0
i = 0
while i < m:
b = A[i][1]
ans += 1
i += 1
while i < m:
if A[i][0] >= b:
break
i += 1
print(ans) | 16 | 17 | 316 | 296 | from operator import itemgetter
n, m = [int(i) for i in input().split()]
A, B = list(zip(*[[int(i) for i in input().split()] for j in range(m)]))
A, B = list(zip(*sorted(zip(A, B), key=itemgetter(1, 0))))
last = -1
ans = 0
for a, b in zip(A, B):
if last <= a:
ans += 1
last = b
print(ans)
| n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.sort(key=lambda a: a[1])
ans = 0
i = 0
while i < m:
b = A[i][1]
ans += 1
i += 1
while i < m:
if A[i][0] >= b:
break
i += 1
print(ans)
| false | 5.882353 | [
"-from operator import itemgetter",
"-",
"-A, B = list(zip(*[[int(i) for i in input().split()] for j in range(m)]))",
"-A, B = list(zip(*sorted(zip(A, B), key=itemgetter(1, 0))))",
"-last = -1",
"+A = [[int(i) for i in input().split()] for j in range(m)]",
"+A.sort(key=lambda a: a[1])",
"-for a, b in zip(A, B):",
"- if last <= a:",
"- ans += 1",
"- last = b",
"+i = 0",
"+while i < m:",
"+ b = A[i][1]",
"+ ans += 1",
"+ i += 1",
"+ while i < m:",
"+ if A[i][0] >= b:",
"+ break",
"+ i += 1"
] | false | 0.042228 | 0.048889 | 0.863754 | [
"s501197200",
"s638001266"
] |
u102461423 | p03822 | python | s815454261 | s044325287 | 400 | 339 | 28,244 | 32,312 | Accepted | Accepted | 15.25 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,*P = list(map(int,read().split()))
graph = [[] for _ in range(N+1)]
for i,x in enumerate(P,2):
graph[i].append(x)
graph[x].append(i)
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
dp = [0] * (N+1)
for v in order[::-1]:
p = parent[v]
A = [dp[c] for c in graph[v] if c != p]
if not A:
continue
A.sort(reverse = True)
A = [x + i for i,x in enumerate(A,1)]
dp[v] = max(A)
answer = dp[1]
print(answer) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def dfs_order(G, root=1):
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in G[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
return parent, order
N, *A = list(map(int, read().split()))
G = [[] for _ in range(N + 1)]
for i, x in enumerate(A, 2):
G[x].append(i)
G[i].append(x)
parent, order = dfs_order(G)
dp = [0] * (N + 1)
for v in order[::-1]:
p = parent[v]
nums = [dp[w] for w in G[v] if w != p]
if not nums:
continue
nums.sort()
n = len(nums)
for i in range(n):
nums[i] += n - i
dp[v] = max(nums)
print((dp[1])) | 37 | 41 | 768 | 884 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, *P = list(map(int, read().split()))
graph = [[] for _ in range(N + 1)]
for i, x in enumerate(P, 2):
graph[i].append(x)
graph[x].append(i)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
dp = [0] * (N + 1)
for v in order[::-1]:
p = parent[v]
A = [dp[c] for c in graph[v] if c != p]
if not A:
continue
A.sort(reverse=True)
A = [x + i for i, x in enumerate(A, 1)]
dp[v] = max(A)
answer = dp[1]
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def dfs_order(G, root=1):
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in G[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
return parent, order
N, *A = list(map(int, read().split()))
G = [[] for _ in range(N + 1)]
for i, x in enumerate(A, 2):
G[x].append(i)
G[i].append(x)
parent, order = dfs_order(G)
dp = [0] * (N + 1)
for v in order[::-1]:
p = parent[v]
nums = [dp[w] for w in G[v] if w != p]
if not nums:
continue
nums.sort()
n = len(nums)
for i in range(n):
nums[i] += n - i
dp[v] = max(nums)
print((dp[1]))
| false | 9.756098 | [
"-N, *P = list(map(int, read().split()))",
"-graph = [[] for _ in range(N + 1)]",
"-for i, x in enumerate(P, 2):",
"- graph[i].append(x)",
"- graph[x].append(i)",
"-root = 1",
"-parent = [0] * (N + 1)",
"-order = []",
"-stack = [root]",
"-while stack:",
"- x = stack.pop()",
"- order.append(x)",
"- for y in graph[x]:",
"- if y == parent[x]:",
"- continue",
"- parent[y] = x",
"- stack.append(y)",
"+",
"+",
"+def dfs_order(G, root=1):",
"+ parent = [0] * (N + 1)",
"+ order = []",
"+ stack = [root]",
"+ while stack:",
"+ x = stack.pop()",
"+ order.append(x)",
"+ for y in G[x]:",
"+ if y == parent[x]:",
"+ continue",
"+ parent[y] = x",
"+ stack.append(y)",
"+ return parent, order",
"+",
"+",
"+N, *A = list(map(int, read().split()))",
"+G = [[] for _ in range(N + 1)]",
"+for i, x in enumerate(A, 2):",
"+ G[x].append(i)",
"+ G[i].append(x)",
"+parent, order = dfs_order(G)",
"- A = [dp[c] for c in graph[v] if c != p]",
"- if not A:",
"+ nums = [dp[w] for w in G[v] if w != p]",
"+ if not nums:",
"- A.sort(reverse=True)",
"- A = [x + i for i, x in enumerate(A, 1)]",
"- dp[v] = max(A)",
"-answer = dp[1]",
"-print(answer)",
"+ nums.sort()",
"+ n = len(nums)",
"+ for i in range(n):",
"+ nums[i] += n - i",
"+ dp[v] = max(nums)",
"+print((dp[1]))"
] | false | 0.071408 | 0.048246 | 1.480096 | [
"s815454261",
"s044325287"
] |
u117078923 | p02923 | python | s720827408 | s571532174 | 95 | 80 | 15,020 | 15,020 | Accepted | Accepted | 15.79 | N=int(eval(input()))
H=list(map(int,input().split()))
ans=0
tmp=0
for i in range(N-1):
if H[i]>=H[i+1]:
tmp+=1
else:
tmp=0
ans=max(ans,tmp)
print(ans) | n=int(eval(input()))
h=list(int(x) for x in input().split())
length=0
max_length=0
for i in range(n-1):
if h[i]>=h[i+1]:
length+=1
if length>max_length:
max_length=length
else:
length=0
print(max_length) | 11 | 14 | 182 | 234 | N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
tmp = 0
for i in range(N - 1):
if H[i] >= H[i + 1]:
tmp += 1
else:
tmp = 0
ans = max(ans, tmp)
print(ans)
| n = int(eval(input()))
h = list(int(x) for x in input().split())
length = 0
max_length = 0
for i in range(n - 1):
if h[i] >= h[i + 1]:
length += 1
if length > max_length:
max_length = length
else:
length = 0
print(max_length)
| false | 21.428571 | [
"-N = int(eval(input()))",
"-H = list(map(int, input().split()))",
"-ans = 0",
"-tmp = 0",
"-for i in range(N - 1):",
"- if H[i] >= H[i + 1]:",
"- tmp += 1",
"+n = int(eval(input()))",
"+h = list(int(x) for x in input().split())",
"+length = 0",
"+max_length = 0",
"+for i in range(n - 1):",
"+ if h[i] >= h[i + 1]:",
"+ length += 1",
"+ if length > max_length:",
"+ max_length = length",
"- tmp = 0",
"- ans = max(ans, tmp)",
"-print(ans)",
"+ length = 0",
"+print(max_length)"
] | false | 0.039031 | 0.038736 | 1.007621 | [
"s720827408",
"s571532174"
] |
u066692421 | p03069 | python | s486716032 | s363173521 | 138 | 118 | 3,500 | 3,500 | Accepted | Accepted | 14.49 | n = int(eval(input()))
s = eval(input())
white = 0
black = 0
for i in range(n):
if s[i] == ".":
white += 1
ans = float("inf")
for j in range(n + 1):
if white + black < ans:
ans = white + black
if j == n:
break
if s[j] == ".":
white -= 1
else:
black += 1
print(ans) | n = int(eval(input()))
s = eval(input())
white = 0
black = 0
for i in range(n):
if s[i] == ".":
white += 1
ans = white + black
for j in range(n):
if s[j] == ".":
white -= 1
else:
black += 1
if white + black < ans:
ans = white + black
print(ans) | 18 | 16 | 329 | 295 | n = int(eval(input()))
s = eval(input())
white = 0
black = 0
for i in range(n):
if s[i] == ".":
white += 1
ans = float("inf")
for j in range(n + 1):
if white + black < ans:
ans = white + black
if j == n:
break
if s[j] == ".":
white -= 1
else:
black += 1
print(ans)
| n = int(eval(input()))
s = eval(input())
white = 0
black = 0
for i in range(n):
if s[i] == ".":
white += 1
ans = white + black
for j in range(n):
if s[j] == ".":
white -= 1
else:
black += 1
if white + black < ans:
ans = white + black
print(ans)
| false | 11.111111 | [
"-ans = float(\"inf\")",
"-for j in range(n + 1):",
"- if white + black < ans:",
"- ans = white + black",
"- if j == n:",
"- break",
"+ans = white + black",
"+for j in range(n):",
"+ if white + black < ans:",
"+ ans = white + black"
] | false | 0.036165 | 0.038927 | 0.929032 | [
"s486716032",
"s363173521"
] |
u002459665 | p02843 | python | s490279732 | s928059205 | 30 | 18 | 3,060 | 3,060 | Accepted | Accepted | 40 | import math
def main():
X = int(eval(input()))
ans = False
for i in range(X+1):
mx = 105 * i
mn = 100 * i
if mn <= X <= mx:
ans = True
if ans:
print((1))
else:
print((0))
if __name__ == "__main__":
main() | import math
def main():
X = int(eval(input()))
# ans = False
c = X // 100
mx = 105 * c
mn = 100 * c
if mn <= X <= mx:
print((1))
else:
print((0))
if __name__ == "__main__":
main() | 17 | 15 | 288 | 233 | import math
def main():
X = int(eval(input()))
ans = False
for i in range(X + 1):
mx = 105 * i
mn = 100 * i
if mn <= X <= mx:
ans = True
if ans:
print((1))
else:
print((0))
if __name__ == "__main__":
main()
| import math
def main():
X = int(eval(input()))
# ans = False
c = X // 100
mx = 105 * c
mn = 100 * c
if mn <= X <= mx:
print((1))
else:
print((0))
if __name__ == "__main__":
main()
| false | 11.764706 | [
"- ans = False",
"- for i in range(X + 1):",
"- mx = 105 * i",
"- mn = 100 * i",
"- if mn <= X <= mx:",
"- ans = True",
"- if ans:",
"+ # ans = False",
"+ c = X // 100",
"+ mx = 105 * c",
"+ mn = 100 * c",
"+ if mn <= X <= mx:"
] | false | 0.118486 | 0.041998 | 2.821231 | [
"s490279732",
"s928059205"
] |
u113835532 | p03378 | python | s072309587 | s129407543 | 29 | 26 | 8,912 | 9,076 | Accepted | Accepted | 10.34 | import bisect
x = int(input().split()[2])
a = list(map(int, input().split()))
i = bisect.bisect(a, x)
print((min(i, len(a) - i))) | import bisect
def answer(n: int, m: int, x: int, a: []) -> int:
i = bisect.bisect_left(a, x)
return min(i, len(a) - i)
def main():
n, m, x = list(map(int, input().split()))
a = list(map(int, input().split()))
print((answer(n, m, x, a)))
if __name__ == '__main__':
main() | 7 | 16 | 135 | 307 | import bisect
x = int(input().split()[2])
a = list(map(int, input().split()))
i = bisect.bisect(a, x)
print((min(i, len(a) - i)))
| import bisect
def answer(n: int, m: int, x: int, a: []) -> int:
i = bisect.bisect_left(a, x)
return min(i, len(a) - i)
def main():
n, m, x = list(map(int, input().split()))
a = list(map(int, input().split()))
print((answer(n, m, x, a)))
if __name__ == "__main__":
main()
| false | 56.25 | [
"-x = int(input().split()[2])",
"-a = list(map(int, input().split()))",
"-i = bisect.bisect(a, x)",
"-print((min(i, len(a) - i)))",
"+",
"+def answer(n: int, m: int, x: int, a: []) -> int:",
"+ i = bisect.bisect_left(a, x)",
"+ return min(i, len(a) - i)",
"+",
"+",
"+def main():",
"+ n, m, x = list(map(int, input().split()))",
"+ a = list(map(int, input().split()))",
"+ print((answer(n, m, x, a)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.045442 | 0.113854 | 0.399122 | [
"s072309587",
"s129407543"
] |
u330799501 | p02885 | python | s449682758 | s698591512 | 32 | 27 | 9,088 | 9,148 | Accepted | Accepted | 15.62 | a, b = list(map(int, input().split()))
ans = a - b * 2
if ans < 0:
ans = 0
print (ans)
| #k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
a, b = list(map(int, input().split()))
ans = a - b * 2
if (ans >= 0):
print(ans)
else:
print((0))
| 8 | 15 | 95 | 252 | a, b = list(map(int, input().split()))
ans = a - b * 2
if ans < 0:
ans = 0
print(ans)
| # k = int(input())
# s = input()
# a, b = map(int, input().split())
# s, t = map(str, input().split())
# l = list(map(int, input().split()))
a, b = list(map(int, input().split()))
ans = a - b * 2
if ans >= 0:
print(ans)
else:
print((0))
| false | 46.666667 | [
"+# k = int(input())",
"+# s = input()",
"+# a, b = map(int, input().split())",
"+# s, t = map(str, input().split())",
"+# l = list(map(int, input().split()))",
"-if ans < 0:",
"- ans = 0",
"-print(ans)",
"+if ans >= 0:",
"+ print(ans)",
"+else:",
"+ print((0))"
] | false | 0.035848 | 0.084397 | 0.424757 | [
"s449682758",
"s698591512"
] |
u759518460 | p02582 | python | s598386341 | s780903886 | 75 | 65 | 61,888 | 61,776 | Accepted | Accepted | 13.33 | import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
S = eval(input())
ans = 0
if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':
ans = 3
elif (S[0] == 'R' and S[1] == 'R') or S[1] == 'R' and S[2] == 'R':
ans = 2
elif 'R' in S:
ans = 1
else:
ans = 0
print(ans)
if __name__ == '__main__':
main()
| import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
S = eval(input())
ans = 0
cnt = 0
for i in range(len(S)):
if S[i] == 'R':
cnt += 1
ans = max(ans, cnt)
else:
cnt = 0
# if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':
# ans = 3
# elif (S[0] == 'R' and S[1] == 'R') or S[1] == 'R' and S[2] == 'R':
# ans = 2
# elif 'R' in S:
# ans = 1
# else:
# ans = 0
print(ans)
if __name__ == '__main__':
main()
| 18 | 25 | 385 | 559 | import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
S = eval(input())
ans = 0
if S[0] == "R" and S[1] == "R" and S[2] == "R":
ans = 3
elif (S[0] == "R" and S[1] == "R") or S[1] == "R" and S[2] == "R":
ans = 2
elif "R" in S:
ans = 1
else:
ans = 0
print(ans)
if __name__ == "__main__":
main()
| import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
S = eval(input())
ans = 0
cnt = 0
for i in range(len(S)):
if S[i] == "R":
cnt += 1
ans = max(ans, cnt)
else:
cnt = 0
# if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':
# ans = 3
# elif (S[0] == 'R' and S[1] == 'R') or S[1] == 'R' and S[2] == 'R':
# ans = 2
# elif 'R' in S:
# ans = 1
# else:
# ans = 0
print(ans)
if __name__ == "__main__":
main()
| false | 28 | [
"- if S[0] == \"R\" and S[1] == \"R\" and S[2] == \"R\":",
"- ans = 3",
"- elif (S[0] == \"R\" and S[1] == \"R\") or S[1] == \"R\" and S[2] == \"R\":",
"- ans = 2",
"- elif \"R\" in S:",
"- ans = 1",
"- else:",
"- ans = 0",
"+ cnt = 0",
"+ for i in range(len(S)):",
"+ if S[i] == \"R\":",
"+ cnt += 1",
"+ ans = max(ans, cnt)",
"+ else:",
"+ cnt = 0",
"+ # if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':",
"+ # ans = 3",
"+ # elif (S[0] == 'R' and S[1] == 'R') or S[1] == 'R' and S[2] == 'R':",
"+ # ans = 2",
"+ # elif 'R' in S:",
"+ # ans = 1",
"+ # else:",
"+ # ans = 0"
] | false | 0.040324 | 0.064155 | 0.628542 | [
"s598386341",
"s780903886"
] |
u197615397 | p02343 | python | s284207260 | s669768932 | 750 | 320 | 8,492 | 7,232 | Accepted | Accepted | 57.33 | n, q = map(int, input().split())
forest = [-1]*n
def get_root(x: int) -> int:
if forest[x] < 0:
return x
else:
forest[x] = get_root(forest[x])
return forest[x]
def unite(x: int, y: int) -> None:
root_x, root_y = get_root(x), get_root(y)
if root_x != root_y:
bigroot, smallroot = \
(root_x, root_y) if forest[root_x] < forest[root_y]\
else (root_y, root_x)
forest[bigroot] += forest[smallroot]
forest[smallroot] = bigroot
for _ in [None]*q:
c, x, y = map(int, input().split())
if c == 0:
unite(x, y)
else:
print(1 if get_root(x) == get_root(y) else 0)
| def get_root(nodes, x: int) -> int:
if nodes[x] < 0:
return x
else:
nodes[x] = get_root(nodes, nodes[x])
return nodes[x]
def unite(nodes, x: int, y: int) -> None:
root_x, root_y = get_root(nodes, x), get_root(nodes, y)
if root_x != root_y:
bigroot, smallroot = \
(root_x, root_y) if nodes[root_x] < nodes[root_y] else (root_y, root_x)
nodes[bigroot] += nodes[smallroot]
nodes[smallroot] = bigroot
if __name__ == "__main__":
import sys
N, Q = map(int, input().split())
nodes = [-1]*N
result = []
append = result.append
for p, a, b in (map(int, l.split()) for l in sys.stdin):
if not p:
unite(nodes, a, b)
else:
append(1 if get_root(nodes, a) == get_root(nodes, b) else 0)
print(*result, sep="\n")
| 27 | 31 | 697 | 876 | n, q = map(int, input().split())
forest = [-1] * n
def get_root(x: int) -> int:
if forest[x] < 0:
return x
else:
forest[x] = get_root(forest[x])
return forest[x]
def unite(x: int, y: int) -> None:
root_x, root_y = get_root(x), get_root(y)
if root_x != root_y:
bigroot, smallroot = (
(root_x, root_y) if forest[root_x] < forest[root_y] else (root_y, root_x)
)
forest[bigroot] += forest[smallroot]
forest[smallroot] = bigroot
for _ in [None] * q:
c, x, y = map(int, input().split())
if c == 0:
unite(x, y)
else:
print(1 if get_root(x) == get_root(y) else 0)
| def get_root(nodes, x: int) -> int:
if nodes[x] < 0:
return x
else:
nodes[x] = get_root(nodes, nodes[x])
return nodes[x]
def unite(nodes, x: int, y: int) -> None:
root_x, root_y = get_root(nodes, x), get_root(nodes, y)
if root_x != root_y:
bigroot, smallroot = (
(root_x, root_y) if nodes[root_x] < nodes[root_y] else (root_y, root_x)
)
nodes[bigroot] += nodes[smallroot]
nodes[smallroot] = bigroot
if __name__ == "__main__":
import sys
N, Q = map(int, input().split())
nodes = [-1] * N
result = []
append = result.append
for p, a, b in (map(int, l.split()) for l in sys.stdin):
if not p:
unite(nodes, a, b)
else:
append(1 if get_root(nodes, a) == get_root(nodes, b) else 0)
print(*result, sep="\n")
| false | 12.903226 | [
"-n, q = map(int, input().split())",
"-forest = [-1] * n",
"+def get_root(nodes, x: int) -> int:",
"+ if nodes[x] < 0:",
"+ return x",
"+ else:",
"+ nodes[x] = get_root(nodes, nodes[x])",
"+ return nodes[x]",
"-def get_root(x: int) -> int:",
"- if forest[x] < 0:",
"- return x",
"- else:",
"- forest[x] = get_root(forest[x])",
"- return forest[x]",
"+def unite(nodes, x: int, y: int) -> None:",
"+ root_x, root_y = get_root(nodes, x), get_root(nodes, y)",
"+ if root_x != root_y:",
"+ bigroot, smallroot = (",
"+ (root_x, root_y) if nodes[root_x] < nodes[root_y] else (root_y, root_x)",
"+ )",
"+ nodes[bigroot] += nodes[smallroot]",
"+ nodes[smallroot] = bigroot",
"-def unite(x: int, y: int) -> None:",
"- root_x, root_y = get_root(x), get_root(y)",
"- if root_x != root_y:",
"- bigroot, smallroot = (",
"- (root_x, root_y) if forest[root_x] < forest[root_y] else (root_y, root_x)",
"- )",
"- forest[bigroot] += forest[smallroot]",
"- forest[smallroot] = bigroot",
"+if __name__ == \"__main__\":",
"+ import sys",
"-",
"-for _ in [None] * q:",
"- c, x, y = map(int, input().split())",
"- if c == 0:",
"- unite(x, y)",
"- else:",
"- print(1 if get_root(x) == get_root(y) else 0)",
"+ N, Q = map(int, input().split())",
"+ nodes = [-1] * N",
"+ result = []",
"+ append = result.append",
"+ for p, a, b in (map(int, l.split()) for l in sys.stdin):",
"+ if not p:",
"+ unite(nodes, a, b)",
"+ else:",
"+ append(1 if get_root(nodes, a) == get_root(nodes, b) else 0)",
"+ print(*result, sep=\"\\n\")"
] | false | 0.101739 | 0.034584 | 2.941798 | [
"s284207260",
"s669768932"
] |
u139614630 | p02948 | python | s886508584 | s142807556 | 1,736 | 440 | 20,024 | 21,788 | Accepted | Accepted | 74.65 | #!/usr/bin/env python3
from collections import deque
class PriorityQueue:
def __init__(self, size):
self.tree = [None] * size
self.bottom = 0
def add(self, data):
n = self.bottom
self.bottom += 1
self.tree[n] = data
while n != 0:
parent = (n - 1) // 2
if self.tree[parent][1] < self.tree[n][1]:
self.tree[parent], self.tree[n] = (
self.tree[n],
self.tree[parent],
)
n = parent
else:
return
def top(self):
return self.tree[0]
def size(self):
return self.bottom
def pop_top(self):
rv = self.tree[0]
self.tree[0] = self.tree[self.bottom - 1]
self.bottom -= 1
n = 0
while True:
child1 = 2 * n + 1
if child1 >= self.bottom:
return rv
child2 = 2 * n + 2
if child2 >= self.bottom:
child2 = child1
if (
self.tree[n][1] > self.tree[child1][1]
and self.tree[n][1] > self.tree[child2][1]
):
return rv
elif self.tree[child1][1] > self.tree[child2][1]:
self.tree[n], self.tree[child1] = (
self.tree[child1],
self.tree[n],
)
n = child1
else:
self.tree[n], self.tree[child2] = (
self.tree[child2],
self.tree[n],
)
n = child2
return rv
def solve(N, M, A, B):
ans = 0
# 日付順にソートする
all_works = deque(sorted(zip(A, B), key=lambda x: x[0]))
pq = PriorityQueue(N)
for d in range(1, M+1):
# print('d=', d)
# 今日が期限の仕事があれば追加
while all_works and all_works[0][0] == d:
work = all_works.popleft()
pq.add(work)
# print('all_works', all_works)
# print('pq=', pq.tree)
# 優先キューから最優先の仕事を選択する
if pq.size():
work = pq.pop_top()
ans += work[1]
return ans
if __name__ == '__main__':
N, M = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for idx in range(N):
A[idx], B[idx] = list(map(int, input().split()))
ans = solve(N, M, A, B)
print(ans)
| #!/usr/bin/env python3
from collections import deque
import heapq
def solve(N, M, A, B):
ans = 0
# 日付順にソートする
all_works = deque(sorted(zip(A, B), key=lambda x: x[0]))
pq = []
for d in range(1, M+1):
# print('d=', d)
# 今日が期限の仕事があれば追加
while all_works and all_works[0][0] == d:
work = all_works.popleft()
# 最小値優先なのでマイナスをつける
heapq.heappush(pq, -work[1])
if pq:
work = heapq.heappop(pq)
ans -= work
return ans
if __name__ == '__main__':
N, M = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for idx in range(N):
A[idx], B[idx] = list(map(int, input().split()))
ans = solve(N, M, A, B)
print(ans)
| 96 | 36 | 2,497 | 779 | #!/usr/bin/env python3
from collections import deque
class PriorityQueue:
def __init__(self, size):
self.tree = [None] * size
self.bottom = 0
def add(self, data):
n = self.bottom
self.bottom += 1
self.tree[n] = data
while n != 0:
parent = (n - 1) // 2
if self.tree[parent][1] < self.tree[n][1]:
self.tree[parent], self.tree[n] = (
self.tree[n],
self.tree[parent],
)
n = parent
else:
return
def top(self):
return self.tree[0]
def size(self):
return self.bottom
def pop_top(self):
rv = self.tree[0]
self.tree[0] = self.tree[self.bottom - 1]
self.bottom -= 1
n = 0
while True:
child1 = 2 * n + 1
if child1 >= self.bottom:
return rv
child2 = 2 * n + 2
if child2 >= self.bottom:
child2 = child1
if (
self.tree[n][1] > self.tree[child1][1]
and self.tree[n][1] > self.tree[child2][1]
):
return rv
elif self.tree[child1][1] > self.tree[child2][1]:
self.tree[n], self.tree[child1] = (
self.tree[child1],
self.tree[n],
)
n = child1
else:
self.tree[n], self.tree[child2] = (
self.tree[child2],
self.tree[n],
)
n = child2
return rv
def solve(N, M, A, B):
ans = 0
# 日付順にソートする
all_works = deque(sorted(zip(A, B), key=lambda x: x[0]))
pq = PriorityQueue(N)
for d in range(1, M + 1):
# print('d=', d)
# 今日が期限の仕事があれば追加
while all_works and all_works[0][0] == d:
work = all_works.popleft()
pq.add(work)
# print('all_works', all_works)
# print('pq=', pq.tree)
# 優先キューから最優先の仕事を選択する
if pq.size():
work = pq.pop_top()
ans += work[1]
return ans
if __name__ == "__main__":
N, M = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for idx in range(N):
A[idx], B[idx] = list(map(int, input().split()))
ans = solve(N, M, A, B)
print(ans)
| #!/usr/bin/env python3
from collections import deque
import heapq
def solve(N, M, A, B):
ans = 0
# 日付順にソートする
all_works = deque(sorted(zip(A, B), key=lambda x: x[0]))
pq = []
for d in range(1, M + 1):
# print('d=', d)
# 今日が期限の仕事があれば追加
while all_works and all_works[0][0] == d:
work = all_works.popleft()
# 最小値優先なのでマイナスをつける
heapq.heappush(pq, -work[1])
if pq:
work = heapq.heappop(pq)
ans -= work
return ans
if __name__ == "__main__":
N, M = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for idx in range(N):
A[idx], B[idx] = list(map(int, input().split()))
ans = solve(N, M, A, B)
print(ans)
| false | 62.5 | [
"-",
"-",
"-class PriorityQueue:",
"- def __init__(self, size):",
"- self.tree = [None] * size",
"- self.bottom = 0",
"-",
"- def add(self, data):",
"- n = self.bottom",
"- self.bottom += 1",
"- self.tree[n] = data",
"- while n != 0:",
"- parent = (n - 1) // 2",
"- if self.tree[parent][1] < self.tree[n][1]:",
"- self.tree[parent], self.tree[n] = (",
"- self.tree[n],",
"- self.tree[parent],",
"- )",
"- n = parent",
"- else:",
"- return",
"-",
"- def top(self):",
"- return self.tree[0]",
"-",
"- def size(self):",
"- return self.bottom",
"-",
"- def pop_top(self):",
"- rv = self.tree[0]",
"- self.tree[0] = self.tree[self.bottom - 1]",
"- self.bottom -= 1",
"- n = 0",
"- while True:",
"- child1 = 2 * n + 1",
"- if child1 >= self.bottom:",
"- return rv",
"- child2 = 2 * n + 2",
"- if child2 >= self.bottom:",
"- child2 = child1",
"- if (",
"- self.tree[n][1] > self.tree[child1][1]",
"- and self.tree[n][1] > self.tree[child2][1]",
"- ):",
"- return rv",
"- elif self.tree[child1][1] > self.tree[child2][1]:",
"- self.tree[n], self.tree[child1] = (",
"- self.tree[child1],",
"- self.tree[n],",
"- )",
"- n = child1",
"- else:",
"- self.tree[n], self.tree[child2] = (",
"- self.tree[child2],",
"- self.tree[n],",
"- )",
"- n = child2",
"- return rv",
"+import heapq",
"- pq = PriorityQueue(N)",
"+ pq = []",
"- pq.add(work)",
"- # print('all_works', all_works)",
"- # print('pq=', pq.tree)",
"- # 優先キューから最優先の仕事を選択する",
"- if pq.size():",
"- work = pq.pop_top()",
"- ans += work[1]",
"+ # 最小値優先なのでマイナスをつける",
"+ heapq.heappush(pq, -work[1])",
"+ if pq:",
"+ work = heapq.heappop(pq)",
"+ ans -= work"
] | false | 0.040578 | 0.041233 | 0.984128 | [
"s886508584",
"s142807556"
] |
u046187684 | p02814 | python | s698737535 | s701945041 | 494 | 159 | 17,132 | 17,132 | Accepted | Accepted | 67.81 | from fractions import gcd
from functools import reduce
def lcm(a, b):
return a * b // gcd(a, b)
def count(n):
c = 0
while n % 2 == 0:
c += 1
n //= 2
return c
def solve(string):
n, m, *a = list(map(int, string.split()))
c = len(bin(a[0]).split("1")[-1])
for _a in a:
if count(_a) != c:
return "0"
l = reduce(lcm, a)
return str(max((m - l // 2) // l + 1, 0))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| from fractions import gcd
def lcm(a, b):
return a * b // gcd(a, b)
def solve(string):
n, m, *a = list(map(int, string.split()))
c = 2**len(bin(a[0]).split("1")[-1])
l = a[0]
for _a in a:
if _a % c or not _a // c % 2:
return "0"
l = lcm(l, _a)
return str(max((m - l // 2) // l + 1, 0))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| 29 | 21 | 544 | 442 | from fractions import gcd
from functools import reduce
def lcm(a, b):
return a * b // gcd(a, b)
def count(n):
c = 0
while n % 2 == 0:
c += 1
n //= 2
return c
def solve(string):
n, m, *a = list(map(int, string.split()))
c = len(bin(a[0]).split("1")[-1])
for _a in a:
if count(_a) != c:
return "0"
l = reduce(lcm, a)
return str(max((m - l // 2) // l + 1, 0))
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| from fractions import gcd
def lcm(a, b):
return a * b // gcd(a, b)
def solve(string):
n, m, *a = list(map(int, string.split()))
c = 2 ** len(bin(a[0]).split("1")[-1])
l = a[0]
for _a in a:
if _a % c or not _a // c % 2:
return "0"
l = lcm(l, _a)
return str(max((m - l // 2) // l + 1, 0))
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| false | 27.586207 | [
"-from functools import reduce",
"-def count(n):",
"- c = 0",
"- while n % 2 == 0:",
"- c += 1",
"- n //= 2",
"- return c",
"-",
"-",
"- c = len(bin(a[0]).split(\"1\")[-1])",
"+ c = 2 ** len(bin(a[0]).split(\"1\")[-1])",
"+ l = a[0]",
"- if count(_a) != c:",
"+ if _a % c or not _a // c % 2:",
"- l = reduce(lcm, a)",
"+ l = lcm(l, _a)"
] | false | 0.055111 | 0.107997 | 0.510302 | [
"s698737535",
"s701945041"
] |
u577170763 | p03160 | python | s341389179 | s175919977 | 135 | 112 | 13,924 | 13,924 | Accepted | Accepted | 17.04 | # import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))
N = gete(int)
h = geta(int)
dp = [0 for _ in range(N)]
dp[0], dp[1] = 0, abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
dp[i - 1] + abs(h[i] - h[i - 1]))
print((dp[N - 1]))
| # import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))
def main():
N = gete(int)
h = geta(int)
dp = [0 for _ in range(N)]
dp[0], dp[1] = 0, abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
dp[i - 1] + abs(h[i] - h[i - 1]))
print((dp[N - 1]))
if __name__ == "__main__":
main() | 17 | 22 | 410 | 498 | # import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))
N = gete(int)
h = geta(int)
dp = [0 for _ in range(N)]
dp[0], dp[1] = 0, abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))
print((dp[N - 1]))
| # import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))
def main():
N = gete(int)
h = geta(int)
dp = [0 for _ in range(N)]
dp[0], dp[1] = 0, abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))
print((dp[N - 1]))
if __name__ == "__main__":
main()
| false | 22.727273 | [
"-N = gete(int)",
"-h = geta(int)",
"-dp = [0 for _ in range(N)]",
"-dp[0], dp[1] = 0, abs(h[0] - h[1])",
"-for i in range(2, N):",
"- dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))",
"-print((dp[N - 1]))",
"+",
"+",
"+def main():",
"+ N = gete(int)",
"+ h = geta(int)",
"+ dp = [0 for _ in range(N)]",
"+ dp[0], dp[1] = 0, abs(h[0] - h[1])",
"+ for i in range(2, N):",
"+ dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))",
"+ print((dp[N - 1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.10025 | 0.076919 | 1.303312 | [
"s341389179",
"s175919977"
] |
u419686324 | p03545 | python | s711133516 | s178739335 | 23 | 17 | 3,572 | 3,060 | Accepted | Accepted | 26.09 | s = [int(x) for x in eval(input())]
import functools
@functools.lru_cache(maxsize=None)
def f(c, n):
if n == 4:
if c == 7:
return []
else:
return None
v = s[n]
for o in ['+', '-']:
ret = f(eval('%d%s%d'% (c,o,v)), n + 1)
if ret is not None:
return [o, v] + ret
print((''.join([str(x) for x in ([s[0]] + f(s[0], 1))]) + '=7')) | s = [int(x) for x in eval(input())]
def f(c, n):
if n == 4:
if eval(c) == 7:
return c + "=7"
else:
return None
v = s[n]
for o in ['+', '-']:
ret = f('%s%s%d' % (c,o,v), n + 1)
if ret:
return ret
print((f(str(s[0]), 1))) | 16 | 14 | 413 | 306 | s = [int(x) for x in eval(input())]
import functools
@functools.lru_cache(maxsize=None)
def f(c, n):
if n == 4:
if c == 7:
return []
else:
return None
v = s[n]
for o in ["+", "-"]:
ret = f(eval("%d%s%d" % (c, o, v)), n + 1)
if ret is not None:
return [o, v] + ret
print(("".join([str(x) for x in ([s[0]] + f(s[0], 1))]) + "=7"))
| s = [int(x) for x in eval(input())]
def f(c, n):
if n == 4:
if eval(c) == 7:
return c + "=7"
else:
return None
v = s[n]
for o in ["+", "-"]:
ret = f("%s%s%d" % (c, o, v), n + 1)
if ret:
return ret
print((f(str(s[0]), 1)))
| false | 12.5 | [
"-import functools",
"[email protected]_cache(maxsize=None)",
"- if c == 7:",
"- return []",
"+ if eval(c) == 7:",
"+ return c + \"=7\"",
"- ret = f(eval(\"%d%s%d\" % (c, o, v)), n + 1)",
"- if ret is not None:",
"- return [o, v] + ret",
"+ ret = f(\"%s%s%d\" % (c, o, v), n + 1)",
"+ if ret:",
"+ return ret",
"-print((\"\".join([str(x) for x in ([s[0]] + f(s[0], 1))]) + \"=7\"))",
"+print((f(str(s[0]), 1)))"
] | false | 0.040343 | 0.045799 | 0.880862 | [
"s711133516",
"s178739335"
] |
u634079249 | p03673 | python | s794839020 | s567054869 | 222 | 120 | 24,052 | 29,124 | Accepted | Accepted | 45.95 | import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: x * y / math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
ret = collections.deque()
for n in range(N):
if N % 2 == (n+1) % 2:
ret.appendleft(A[n])
else:
ret.append(A[n])
print((*ret))
if __name__ == '__main__':
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
if N % 2 == 0:
print((*A[1::2][::-1], *A[::2]))
else:
print((*A[::2][::-1], *A[1::2]))
if __name__ == '__main__':
main()
| 43 | 39 | 1,053 | 1,169 | import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: x * y / math.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
ret = collections.deque()
for n in range(N):
if N % 2 == (n + 1) % 2:
ret.appendleft(A[n])
else:
ret.append(A[n])
print((*ret))
if __name__ == "__main__":
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
if N % 2 == 0:
print((*A[1::2][::-1], *A[::2]))
else:
print((*A[::2][::-1], *A[1::2]))
if __name__ == "__main__":
main()
| false | 9.302326 | [
"-import sys",
"-import os",
"-import math",
"-import bisect",
"-import collections",
"-import itertools",
"-import heapq",
"-import re",
"-import queue",
"+import sys, os, math, bisect, itertools, collections, heapq, queue",
"+# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall",
"+from decimal import Decimal",
"+from collections import defaultdict",
"+",
"+# import fractions",
"+sys.setrecursionlimit(10000000)",
"-lcm = lambda x, y: x * y / math.gcd(x, y)",
"+lcm = lambda x, y: (x * y) // math.gcd(x, y)",
"+# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)",
"- ret = collections.deque()",
"- for n in range(N):",
"- if N % 2 == (n + 1) % 2:",
"- ret.appendleft(A[n])",
"- else:",
"- ret.append(A[n])",
"- print((*ret))",
"+ if N % 2 == 0:",
"+ print((*A[1::2][::-1], *A[::2]))",
"+ else:",
"+ print((*A[::2][::-1], *A[1::2]))"
] | false | 0.054174 | 0.040275 | 1.345104 | [
"s794839020",
"s567054869"
] |
u595289165 | p03045 | python | s661734624 | s792752501 | 496 | 360 | 7,856 | 81,652 | Accepted | Accepted | 27.42 | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
n, m = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(m):
x, y, z = list(map(int, input().split()))
uf.union(x-1, y-1)
print((uf.group_count())) | class UnionFind1:
def __init__(self, n):
self.n = n
self.par = [-1] * (n+1)
def root(self, x):
if self.par[x] < 0:
return x
self.par[x] = self.root(self.par[x])
return self.par[x]
def unite(self, x, y):
if self.same(x, y):
return
x = self.root(x)
y = self.root(y)
if self.par[x] > self.par[y]:
x, y = y, x
self.par[x] += self.par[y]
self.par[y] = x
def same(self, x, y):
return self.root(x) == self.root(y)
def size(self, x):
return -self.par[self.root(x)]
n, m = list(map(int, input().split()))
uf = UnionFind1(n)
for _ in range(m):
x, y, z = list(map(int, input().split()))
uf.unite(x, y)
cost = 0
for i in range(1, n+1):
if uf.root(i) == i:
cost += 1
print(cost)
| 40 | 42 | 884 | 885 | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
n, m = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(m):
x, y, z = list(map(int, input().split()))
uf.union(x - 1, y - 1)
print((uf.group_count()))
| class UnionFind1:
def __init__(self, n):
self.n = n
self.par = [-1] * (n + 1)
def root(self, x):
if self.par[x] < 0:
return x
self.par[x] = self.root(self.par[x])
return self.par[x]
def unite(self, x, y):
if self.same(x, y):
return
x = self.root(x)
y = self.root(y)
if self.par[x] > self.par[y]:
x, y = y, x
self.par[x] += self.par[y]
self.par[y] = x
def same(self, x, y):
return self.root(x) == self.root(y)
def size(self, x):
return -self.par[self.root(x)]
n, m = list(map(int, input().split()))
uf = UnionFind1(n)
for _ in range(m):
x, y, z = list(map(int, input().split()))
uf.unite(x, y)
cost = 0
for i in range(1, n + 1):
if uf.root(i) == i:
cost += 1
print(cost)
| false | 4.761905 | [
"-class UnionFind:",
"+class UnionFind1:",
"- self.parents = [-1] * n",
"+ self.par = [-1] * (n + 1)",
"- def find(self, x):",
"- if self.parents[x] < 0:",
"+ def root(self, x):",
"+ if self.par[x] < 0:",
"- else:",
"- self.parents[x] = self.find(self.parents[x])",
"- return self.parents[x]",
"+ self.par[x] = self.root(self.par[x])",
"+ return self.par[x]",
"- def union(self, x, y):",
"- x = self.find(x)",
"- y = self.find(y)",
"- if x == y:",
"+ def unite(self, x, y):",
"+ if self.same(x, y):",
"- if self.parents[x] > self.parents[y]:",
"+ x = self.root(x)",
"+ y = self.root(y)",
"+ if self.par[x] > self.par[y]:",
"- self.parents[x] += self.parents[y]",
"- self.parents[y] = x",
"+ self.par[x] += self.par[y]",
"+ self.par[y] = x",
"- def roots(self):",
"- return [i for i, x in enumerate(self.parents) if x < 0]",
"+ def same(self, x, y):",
"+ return self.root(x) == self.root(y)",
"- def group_count(self):",
"- return len(self.roots())",
"+ def size(self, x):",
"+ return -self.par[self.root(x)]",
"-uf = UnionFind(n)",
"+uf = UnionFind1(n)",
"- uf.union(x - 1, y - 1)",
"-print((uf.group_count()))",
"+ uf.unite(x, y)",
"+cost = 0",
"+for i in range(1, n + 1):",
"+ if uf.root(i) == i:",
"+ cost += 1",
"+print(cost)"
] | false | 0.061341 | 0.039006 | 1.57261 | [
"s661734624",
"s792752501"
] |
u396495667 | p02958 | python | s858820227 | s313061512 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | n = int(eval(input()))
p = [int(x) for x in input().split()]
cnt =0
for i in range(n):
if p[i] ==(i+1):
continue
else:
cnt +=1
if cnt <= 2:
print('YES')
else:
print('NO') | n =int(eval(input()))
p = [int(_) for _ in input().split()]
cnt =0
for i in range(len(p)):
if p[i] !=(i+1):
cnt +=1
print(('YES' if cnt <=2 else 'NO')) | 14 | 7 | 195 | 156 | n = int(eval(input()))
p = [int(x) for x in input().split()]
cnt = 0
for i in range(n):
if p[i] == (i + 1):
continue
else:
cnt += 1
if cnt <= 2:
print("YES")
else:
print("NO")
| n = int(eval(input()))
p = [int(_) for _ in input().split()]
cnt = 0
for i in range(len(p)):
if p[i] != (i + 1):
cnt += 1
print(("YES" if cnt <= 2 else "NO"))
| false | 50 | [
"-p = [int(x) for x in input().split()]",
"+p = [int(_) for _ in input().split()]",
"-for i in range(n):",
"- if p[i] == (i + 1):",
"- continue",
"- else:",
"+for i in range(len(p)):",
"+ if p[i] != (i + 1):",
"-if cnt <= 2:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+print((\"YES\" if cnt <= 2 else \"NO\"))"
] | false | 0.06997 | 0.051955 | 1.346724 | [
"s858820227",
"s313061512"
] |
u389910364 | p03837 | python | s946878743 | s914551203 | 303 | 163 | 19,904 | 12,748 | Accepted | Accepted | 46.2 | import os
import sys
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
N, M = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
D = np.zeros((N, N))
for a, b, c in ABC:
D[a - 1][b - 1] = c
min_dist = dijkstra(csgraph_from_dense(D), directed=False)
print(((min_dist < D).sum()))
| import os
import sys
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
N, M = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
D = np.full((N, N), IINF)
for a, b, c in ABC:
D[a - 1][b - 1] = c
D[b - 1][a - 1] = c
# warshall floyd
for via in range(N):
D = np.minimum(D, sum(np.meshgrid(D[via], D[via], sparse=True)))
ans = 0
for a, b, c in ABC:
if D[a - 1][b - 1] < c:
ans += 1
print(ans)
| 22 | 29 | 533 | 612 | import os
import sys
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
N, M = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
D = np.zeros((N, N))
for a, b, c in ABC:
D[a - 1][b - 1] = c
min_dist = dijkstra(csgraph_from_dense(D), directed=False)
print(((min_dist < D).sum()))
| import os
import sys
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
N, M = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
D = np.full((N, N), IINF)
for a, b, c in ABC:
D[a - 1][b - 1] = c
D[b - 1][a - 1] = c
# warshall floyd
for via in range(N):
D = np.minimum(D, sum(np.meshgrid(D[via], D[via], sparse=True)))
ans = 0
for a, b, c in ABC:
if D[a - 1][b - 1] < c:
ans += 1
print(ans)
| false | 24.137931 | [
"-from scipy.sparse.csgraph import csgraph_from_dense, dijkstra",
"-D = np.zeros((N, N))",
"+D = np.full((N, N), IINF)",
"-min_dist = dijkstra(csgraph_from_dense(D), directed=False)",
"-print(((min_dist < D).sum()))",
"+ D[b - 1][a - 1] = c",
"+# warshall floyd",
"+for via in range(N):",
"+ D = np.minimum(D, sum(np.meshgrid(D[via], D[via], sparse=True)))",
"+ans = 0",
"+for a, b, c in ABC:",
"+ if D[a - 1][b - 1] < c:",
"+ ans += 1",
"+print(ans)"
] | false | 0.736744 | 1.088422 | 0.676892 | [
"s946878743",
"s914551203"
] |
u463950771 | p03078 | python | s177030648 | s015361432 | 2,000 | 654 | 160,584 | 8,708 | Accepted | Accepted | 67.3 | x,y,z,k = list(map(int,input().split()))
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
for nu in lisa:
an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
for nu in an:
ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
print((ans[i]))
| X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
result = []
for i in range(X):
for j in range(Y):
for k in range(Z):
if (i + 1) * (j + 1) * (k + 1) <= K:
result.append(A[i] + B[j] + C[k])
else:
break
result.sort(reverse=True)
for rs in result[:K]:
print(rs) | 20 | 20 | 492 | 512 | x, y, z, k = list(map(int, input().split()))
lisa = list(map(int, input().split()))
lisb = list(map(int, input().split()))
lisc = list(map(int, input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
for nu in lisa:
an.append(num + nu)
an.sort(reverse=True)
an = an[: min(3001, x * y * z + 1)]
for num in lisc:
for nu in an:
ans.append(num + nu)
ans.sort(reverse=True)
for i in range(k):
print((ans[i]))
| X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
result = []
for i in range(X):
for j in range(Y):
for k in range(Z):
if (i + 1) * (j + 1) * (k + 1) <= K:
result.append(A[i] + B[j] + C[k])
else:
break
result.sort(reverse=True)
for rs in result[:K]:
print(rs)
| false | 0 | [
"-x, y, z, k = list(map(int, input().split()))",
"-lisa = list(map(int, input().split()))",
"-lisb = list(map(int, input().split()))",
"-lisc = list(map(int, input().split()))",
"-lisa.sort(reverse=True)",
"-lisb.sort(reverse=True)",
"-lisc.sort(reverse=True)",
"-an = []",
"-ans = []",
"-for num in lisb:",
"- for nu in lisa:",
"- an.append(num + nu)",
"-an.sort(reverse=True)",
"-an = an[: min(3001, x * y * z + 1)]",
"-for num in lisc:",
"- for nu in an:",
"- ans.append(num + nu)",
"-ans.sort(reverse=True)",
"-for i in range(k):",
"- print((ans[i]))",
"+X, Y, Z, K = list(map(int, input().split()))",
"+A = list(map(int, input().split()))",
"+B = list(map(int, input().split()))",
"+C = list(map(int, input().split()))",
"+A.sort(reverse=True)",
"+B.sort(reverse=True)",
"+C.sort(reverse=True)",
"+result = []",
"+for i in range(X):",
"+ for j in range(Y):",
"+ for k in range(Z):",
"+ if (i + 1) * (j + 1) * (k + 1) <= K:",
"+ result.append(A[i] + B[j] + C[k])",
"+ else:",
"+ break",
"+result.sort(reverse=True)",
"+for rs in result[:K]:",
"+ print(rs)"
] | false | 0.04328 | 0.070196 | 0.61656 | [
"s177030648",
"s015361432"
] |
u064027771 | p02861 | python | s421513244 | s006261427 | 11 | 10 | 2,692 | 2,568 | Accepted | Accepted | 9.09 | def d(a,b):
return ((a[0]-b[0])**2+(a[1]-b[1])**2)**(.5)
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
s = 0
for i in range(n):
for j in range(n):
if i !=j:
s += d(l[i],l[j])
print(s/n) | n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
print(sum(((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**(.5) for i in range(n) for j in range(n) if i !=j)/n) | 10 | 3 | 249 | 183 | def d(a, b):
return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** (0.5)
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
s = 0
for i in range(n):
for j in range(n):
if i != j:
s += d(l[i], l[j])
print(s / n)
| n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
print(
sum(
((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1]) ** 2) ** (0.5)
for i in range(n)
for j in range(n)
if i != j
)
/ n
)
| false | 70 | [
"-def d(a, b):",
"- return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** (0.5)",
"-",
"-",
"-s = 0",
"-for i in range(n):",
"- for j in range(n):",
"- if i != j:",
"- s += d(l[i], l[j])",
"-print(s / n)",
"+print(",
"+ sum(",
"+ ((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1]) ** 2) ** (0.5)",
"+ for i in range(n)",
"+ for j in range(n)",
"+ if i != j",
"+ )",
"+ / n",
"+)"
] | false | 0.043122 | 0.043623 | 0.988525 | [
"s421513244",
"s006261427"
] |
u334712262 | p02698 | python | s495896796 | s752448516 | 1,814 | 1,321 | 551,636 | 383,228 | Accepted | Accepted | 27.18 | # -*- coding: utf-8 -*-
import bisect
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
ans = [-1] * (2*10**5+1)
@mt
def slv(N, A, UV):
A.insert(0, -1)
g = [list() for _ in range(0, N+1)]
for u, v in UV:
g[u].append(v)
g[v].append(u)
def dfs(u, p, dp):
global ans
for v in g[u]:
if v == p:
continue
i = bisect.bisect_left(dp, A[v])
if len(dp) <= i:
dp.append(A[v])
ans[v] = len(dp)
dfs(v, u, dp)
dp.pop()
else:
b = dp[i]
dp[i] = A[v]
ans[v] = len(dp)
dfs(v, u, dp)
dp[i] = b
dp = [A[1]]
dfs(1, 0, dp)
ans[1] = 1
for i in range(1, N+1):
print(ans[i])
# return ans[:N]
def main():
N = read_int()
A = read_int_n()
UV = [read_int_n() for _ in range(N-1)]
(slv(N, A, UV))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import bisect
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
ans = [-1] * (2*10**5+1)
@mt
def slv(N, A, UV):
A.insert(0, -1)
g = [list() for _ in range(0, N+1)]
for u, v in UV:
g[u].append(v)
g[v].append(u)
def dfs(u, p, dp):
global ans
for v in g[u]:
if v == p:
continue
i = bisect.bisect_left(dp, A[v])
b = dp[i]
dp[i] = A[v]
ans[v] = bisect.bisect_left(dp, INF)
dfs(v, u, dp)
dp[i] = b
dp = [INF] * (N+2)
dp[0] = A[1]
# dp[1] = A[1]
dfs(1, 0, dp)
ans[1] = 1
for i in range(1, N+1):
print(ans[i])
def main():
N = read_int()
A = read_int_n()
UV = [read_int_n() for _ in range(N-1)]
slv(N, A, UV)
if __name__ == '__main__':
main()
| 100 | 94 | 1,756 | 1,602 | # -*- coding: utf-8 -*-
import bisect
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline
INF = 2**62 - 1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
ans = [-1] * (2 * 10**5 + 1)
@mt
def slv(N, A, UV):
A.insert(0, -1)
g = [list() for _ in range(0, N + 1)]
for u, v in UV:
g[u].append(v)
g[v].append(u)
def dfs(u, p, dp):
global ans
for v in g[u]:
if v == p:
continue
i = bisect.bisect_left(dp, A[v])
if len(dp) <= i:
dp.append(A[v])
ans[v] = len(dp)
dfs(v, u, dp)
dp.pop()
else:
b = dp[i]
dp[i] = A[v]
ans[v] = len(dp)
dfs(v, u, dp)
dp[i] = b
dp = [A[1]]
dfs(1, 0, dp)
ans[1] = 1
for i in range(1, N + 1):
print(ans[i])
# return ans[:N]
def main():
N = read_int()
A = read_int_n()
UV = [read_int_n() for _ in range(N - 1)]
(slv(N, A, UV))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import bisect
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline
INF = 2**62 - 1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
ans = [-1] * (2 * 10**5 + 1)
@mt
def slv(N, A, UV):
A.insert(0, -1)
g = [list() for _ in range(0, N + 1)]
for u, v in UV:
g[u].append(v)
g[v].append(u)
def dfs(u, p, dp):
global ans
for v in g[u]:
if v == p:
continue
i = bisect.bisect_left(dp, A[v])
b = dp[i]
dp[i] = A[v]
ans[v] = bisect.bisect_left(dp, INF)
dfs(v, u, dp)
dp[i] = b
dp = [INF] * (N + 2)
dp[0] = A[1]
# dp[1] = A[1]
dfs(1, 0, dp)
ans[1] = 1
for i in range(1, N + 1):
print(ans[i])
def main():
N = read_int()
A = read_int_n()
UV = [read_int_n() for _ in range(N - 1)]
slv(N, A, UV)
if __name__ == "__main__":
main()
| false | 6 | [
"- if len(dp) <= i:",
"- dp.append(A[v])",
"- ans[v] = len(dp)",
"- dfs(v, u, dp)",
"- dp.pop()",
"- else:",
"- b = dp[i]",
"- dp[i] = A[v]",
"- ans[v] = len(dp)",
"- dfs(v, u, dp)",
"- dp[i] = b",
"+ b = dp[i]",
"+ dp[i] = A[v]",
"+ ans[v] = bisect.bisect_left(dp, INF)",
"+ dfs(v, u, dp)",
"+ dp[i] = b",
"- dp = [A[1]]",
"+ dp = [INF] * (N + 2)",
"+ dp[0] = A[1]",
"+ # dp[1] = A[1]",
"- # return ans[:N]",
"- (slv(N, A, UV))",
"+ slv(N, A, UV)"
] | false | 0.047109 | 0.040136 | 1.173731 | [
"s495896796",
"s752448516"
] |
u773265208 | p02848 | python | s428031713 | s124842687 | 33 | 30 | 4,468 | 3,060 | Accepted | Accepted | 9.09 | n = int(input())
s = input()
for i in range(len(s)):
num = int(ord(s[i])+n)
if num > 90:
num -= 26
print(chr(num),end="")
| n = int(eval(input()))
s = eval(input())
ans = ""
for i in range(len(s)):
num = ord(s[i])+n
if num > 90:
num -= 26
ans += chr(num)
print(ans)
| 9 | 12 | 137 | 149 | n = int(input())
s = input()
for i in range(len(s)):
num = int(ord(s[i]) + n)
if num > 90:
num -= 26
print(chr(num), end="")
| n = int(eval(input()))
s = eval(input())
ans = ""
for i in range(len(s)):
num = ord(s[i]) + n
if num > 90:
num -= 26
ans += chr(num)
print(ans)
| false | 25 | [
"-n = int(input())",
"-s = input()",
"+n = int(eval(input()))",
"+s = eval(input())",
"+ans = \"\"",
"- num = int(ord(s[i]) + n)",
"+ num = ord(s[i]) + n",
"- print(chr(num), end=\"\")",
"+ ans += chr(num)",
"+print(ans)"
] | false | 0.076986 | 0.056397 | 1.365076 | [
"s428031713",
"s124842687"
] |
u968404618 | p03254 | python | s099743674 | s155367407 | 33 | 28 | 9,132 | 9,088 | Accepted | Accepted | 15.15 | import sys
input = lambda :sys.stdin.readline().rstrip()
N, x = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
if x > sum(A):
cnt = -1
else:
cnt = 0
for i in range(N):
if x - A[i] >= 0:
cnt += 1
x -= A[i]
if x <= 0:
break
#print(cnt, x)
print(cnt) | n, x = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
if sum(A) < x:
cnt = -1
else:
cnt = 0
for a in A:
x -= a
if x >= 0:
cnt += 1
if x <= 0:
print(cnt)
exit()
print(cnt) | 20 | 16 | 335 | 258 | import sys
input = lambda: sys.stdin.readline().rstrip()
N, x = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
if x > sum(A):
cnt = -1
else:
cnt = 0
for i in range(N):
if x - A[i] >= 0:
cnt += 1
x -= A[i]
if x <= 0:
break
# print(cnt, x)
print(cnt)
| n, x = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
if sum(A) < x:
cnt = -1
else:
cnt = 0
for a in A:
x -= a
if x >= 0:
cnt += 1
if x <= 0:
print(cnt)
exit()
print(cnt)
| false | 20 | [
"-import sys",
"-",
"-input = lambda: sys.stdin.readline().rstrip()",
"-N, x = list(map(int, input().split()))",
"+n, x = list(map(int, input().split()))",
"-if x > sum(A):",
"+if sum(A) < x:",
"-for i in range(N):",
"- if x - A[i] >= 0:",
"+for a in A:",
"+ x -= a",
"+ if x >= 0:",
"- x -= A[i]",
"- break",
"- # print(cnt, x)",
"+ print(cnt)",
"+ exit()"
] | false | 0.046456 | 0.090875 | 0.511206 | [
"s099743674",
"s155367407"
] |
u729133443 | p02921 | python | s274739459 | s279388613 | 166 | 31 | 38,256 | 9,072 | Accepted | Accepted | 81.33 | print((sum(i==j for i,j in zip(*open(0)))-1)) | print((3-sum(i!=j for i,j in zip(*open(0))))) | 1 | 1 | 43 | 43 | print((sum(i == j for i, j in zip(*open(0))) - 1))
| print((3 - sum(i != j for i, j in zip(*open(0)))))
| false | 0 | [
"-print((sum(i == j for i, j in zip(*open(0))) - 1))",
"+print((3 - sum(i != j for i, j in zip(*open(0)))))"
] | false | 0.036541 | 0.096582 | 0.378341 | [
"s274739459",
"s279388613"
] |
u796842765 | p02773 | python | s159723614 | s010007478 | 781 | 720 | 54,276 | 49,224 | Accepted | Accepted | 7.81 | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
import collections
max = max(collections.Counter(S).values())
letter = [a for a , b in collections.Counter(S).most_common() if b == max]
for a in sorted(letter):
print(a) | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
import collections
c = collections.Counter(S)
A = sorted(list(c.items()), key=lambda x: x[1], reverse=True)
count = 0
B = []
for a, b in A:
if b >= count:
B.append(a)
count = b
else:
break
C = sorted(B)
for a in C:
print(a) | 7 | 17 | 229 | 319 | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
import collections
max = max(collections.Counter(S).values())
letter = [a for a, b in collections.Counter(S).most_common() if b == max]
for a in sorted(letter):
print(a)
| N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
import collections
c = collections.Counter(S)
A = sorted(list(c.items()), key=lambda x: x[1], reverse=True)
count = 0
B = []
for a, b in A:
if b >= count:
B.append(a)
count = b
else:
break
C = sorted(B)
for a in C:
print(a)
| false | 58.823529 | [
"-max = max(collections.Counter(S).values())",
"-letter = [a for a, b in collections.Counter(S).most_common() if b == max]",
"-for a in sorted(letter):",
"+c = collections.Counter(S)",
"+A = sorted(list(c.items()), key=lambda x: x[1], reverse=True)",
"+count = 0",
"+B = []",
"+for a, b in A:",
"+ if b >= count:",
"+ B.append(a)",
"+ count = b",
"+ else:",
"+ break",
"+C = sorted(B)",
"+for a in C:"
] | false | 0.008666 | 0.075191 | 0.115254 | [
"s159723614",
"s010007478"
] |
u285891772 | p02845 | python | s271836893 | s610524992 | 110 | 97 | 22,328 | 22,488 | Accepted | Accepted | 11.82 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = LIST()
ans = 1
cnt = [0, 0, 0]
for i in range(N):
ans = ans * cnt.count(A[i]) % mod
if A[i] in cnt:
cnt[cnt.index(A[i])] += 1
else:
print((0))
exit()
print(ans) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = LIST()
cnt = [0]*(max(A)+2)
cnt[0] = 3
ans = 1
for a in A:
ans *= cnt[a] - cnt[a+1]
cnt[a+1] += 1
ans %= mod
print(ans) | 36 | 34 | 1,124 | 1,077 | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
N = INT()
A = LIST()
ans = 1
cnt = [0, 0, 0]
for i in range(N):
ans = ans * cnt.count(A[i]) % mod
if A[i] in cnt:
cnt[cnt.index(A[i])] += 1
else:
print((0))
exit()
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
N = INT()
A = LIST()
cnt = [0] * (max(A) + 2)
cnt[0] = 3
ans = 1
for a in A:
ans *= cnt[a] - cnt[a + 1]
cnt[a + 1] += 1
ans %= mod
print(ans)
| false | 5.555556 | [
"+cnt = [0] * (max(A) + 2)",
"+cnt[0] = 3",
"-cnt = [0, 0, 0]",
"-for i in range(N):",
"- ans = ans * cnt.count(A[i]) % mod",
"- if A[i] in cnt:",
"- cnt[cnt.index(A[i])] += 1",
"- else:",
"- print((0))",
"- exit()",
"+for a in A:",
"+ ans *= cnt[a] - cnt[a + 1]",
"+ cnt[a + 1] += 1",
"+ ans %= mod"
] | false | 0.047487 | 0.047709 | 0.995344 | [
"s271836893",
"s610524992"
] |
u883040023 | p02629 | python | s984087344 | s921572121 | 30 | 27 | 9,224 | 8,904 | Accepted | Accepted | 10 | n = int(eval(input()))
kugiri = [0,26,702,18278,475254,12356630,321272406,8353082582,217180147158,5646683826134,146813779479510,3817158266467286]
ans = ""
for i in range(len(kugiri)):
if n <= kugiri[i]:
keta = i
break
n -= kugiri[i-1]
for i in range(keta):
moji = -(-n // 26**(keta-1))
ans += chr(moji+96)
n -= (moji-1) * 26**(keta-1)
keta -= 1
print(ans) | N = int(eval(input()))
ans = ''
for i in range(1, 99):
if N <= 26 ** i:
N -= 1
for j in range(i):
ans += chr(ord('a') + N % 26)
N //= 26
break
else:
N -= 26 ** i
print((ans[::-1])) | 18 | 17 | 418 | 285 | n = int(eval(input()))
kugiri = [
0,
26,
702,
18278,
475254,
12356630,
321272406,
8353082582,
217180147158,
5646683826134,
146813779479510,
3817158266467286,
]
ans = ""
for i in range(len(kugiri)):
if n <= kugiri[i]:
keta = i
break
n -= kugiri[i - 1]
for i in range(keta):
moji = -(-n // 26 ** (keta - 1))
ans += chr(moji + 96)
n -= (moji - 1) * 26 ** (keta - 1)
keta -= 1
print(ans)
| N = int(eval(input()))
ans = ""
for i in range(1, 99):
if N <= 26**i:
N -= 1
for j in range(i):
ans += chr(ord("a") + N % 26)
N //= 26
break
else:
N -= 26**i
print((ans[::-1]))
| false | 5.555556 | [
"-n = int(eval(input()))",
"-kugiri = [",
"- 0,",
"- 26,",
"- 702,",
"- 18278,",
"- 475254,",
"- 12356630,",
"- 321272406,",
"- 8353082582,",
"- 217180147158,",
"- 5646683826134,",
"- 146813779479510,",
"- 3817158266467286,",
"-]",
"+N = int(eval(input()))",
"-for i in range(len(kugiri)):",
"- if n <= kugiri[i]:",
"- keta = i",
"+for i in range(1, 99):",
"+ if N <= 26**i:",
"+ N -= 1",
"+ for j in range(i):",
"+ ans += chr(ord(\"a\") + N % 26)",
"+ N //= 26",
"-n -= kugiri[i - 1]",
"-for i in range(keta):",
"- moji = -(-n // 26 ** (keta - 1))",
"- ans += chr(moji + 96)",
"- n -= (moji - 1) * 26 ** (keta - 1)",
"- keta -= 1",
"-print(ans)",
"+ else:",
"+ N -= 26**i",
"+print((ans[::-1]))"
] | false | 0.040121 | 0.041426 | 0.968495 | [
"s984087344",
"s921572121"
] |
u244416763 | p02989 | python | s092571771 | s366450051 | 83 | 76 | 14,556 | 14,396 | Accepted | Accepted | 8.43 | n = int(eval(input()))
d = list(map(int, input().split()))
if(len(d)%2 == 0):
d.sort()
t = int(len(d)/2)-1
s = d[t]
m = s
i = t
while (d[t+1] > s):
s += 1
print((s-m))
else:
print((0)) | n = int(eval(input()))
d = list(map(int, input().split()))
if(len(d)%2 == 0):
d.sort()
t = int(len(d)/2)-1
print((d[t+1] - d[t]))
else:
print((0)) | 13 | 8 | 226 | 159 | n = int(eval(input()))
d = list(map(int, input().split()))
if len(d) % 2 == 0:
d.sort()
t = int(len(d) / 2) - 1
s = d[t]
m = s
i = t
while d[t + 1] > s:
s += 1
print((s - m))
else:
print((0))
| n = int(eval(input()))
d = list(map(int, input().split()))
if len(d) % 2 == 0:
d.sort()
t = int(len(d) / 2) - 1
print((d[t + 1] - d[t]))
else:
print((0))
| false | 38.461538 | [
"- s = d[t]",
"- m = s",
"- i = t",
"- while d[t + 1] > s:",
"- s += 1",
"- print((s - m))",
"+ print((d[t + 1] - d[t]))"
] | false | 0.113523 | 0.068792 | 1.650228 | [
"s092571771",
"s366450051"
] |
u934442292 | p03044 | python | s622099751 | s821838482 | 533 | 299 | 79,408 | 50,080 | Accepted | Accepted | 43.9 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
N = int(eval(input()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
G[u].append((v, w))
G[v].append((u, w))
C = [-1] * N
def dfs(pos, color):
C[pos] = color
for e in G[pos]:
if C[e[0]] != -1:
continue
# odd
if e[1] & 1:
c = 1 - color
dfs(e[0], c)
# even
else:
c = color
dfs(e[0], c)
dfs(0, 0)
for c in C:
print(c)
| import sys
from collections import deque
input = sys.stdin.readline
def main():
N = int(eval(input()))
G = [[] for _ in range(N)]
for i in range(N - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
G[u].append((v, w))
G[v].append((u, w))
ans = [-1] * N
ans[0] = 0
stack = deque([(-1, 0)])
while stack:
p, u = stack.pop()
for v, w in G[u]:
if v == p:
continue
if w % 2 == 0:
ans[v] = ans[u]
else:
ans[v] = (ans[u] + 1) % 2
stack.append((u, v))
print(("\n".join(map(str, ans))))
if __name__ == "__main__":
main()
| 34 | 35 | 602 | 737 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
N = int(eval(input()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
G[u].append((v, w))
G[v].append((u, w))
C = [-1] * N
def dfs(pos, color):
C[pos] = color
for e in G[pos]:
if C[e[0]] != -1:
continue
# odd
if e[1] & 1:
c = 1 - color
dfs(e[0], c)
# even
else:
c = color
dfs(e[0], c)
dfs(0, 0)
for c in C:
print(c)
| import sys
from collections import deque
input = sys.stdin.readline
def main():
N = int(eval(input()))
G = [[] for _ in range(N)]
for i in range(N - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
G[u].append((v, w))
G[v].append((u, w))
ans = [-1] * N
ans[0] = 0
stack = deque([(-1, 0)])
while stack:
p, u = stack.pop()
for v, w in G[u]:
if v == p:
continue
if w % 2 == 0:
ans[v] = ans[u]
else:
ans[v] = (ans[u] + 1) % 2
stack.append((u, v))
print(("\n".join(map(str, ans))))
if __name__ == "__main__":
main()
| false | 2.857143 | [
"+from collections import deque",
"-sys.setrecursionlimit(100000)",
"-N = int(eval(input()))",
"-G = [[] for _ in range(N)]",
"-for _ in range(N - 1):",
"- u, v, w = list(map(int, input().split()))",
"- u -= 1",
"- v -= 1",
"- G[u].append((v, w))",
"- G[v].append((u, w))",
"-C = [-1] * N",
"-def dfs(pos, color):",
"- C[pos] = color",
"- for e in G[pos]:",
"- if C[e[0]] != -1:",
"- continue",
"- # odd",
"- if e[1] & 1:",
"- c = 1 - color",
"- dfs(e[0], c)",
"- # even",
"- else:",
"- c = color",
"- dfs(e[0], c)",
"+def main():",
"+ N = int(eval(input()))",
"+ G = [[] for _ in range(N)]",
"+ for i in range(N - 1):",
"+ u, v, w = list(map(int, input().split()))",
"+ u -= 1",
"+ v -= 1",
"+ G[u].append((v, w))",
"+ G[v].append((u, w))",
"+ ans = [-1] * N",
"+ ans[0] = 0",
"+ stack = deque([(-1, 0)])",
"+ while stack:",
"+ p, u = stack.pop()",
"+ for v, w in G[u]:",
"+ if v == p:",
"+ continue",
"+ if w % 2 == 0:",
"+ ans[v] = ans[u]",
"+ else:",
"+ ans[v] = (ans[u] + 1) % 2",
"+ stack.append((u, v))",
"+ print((\"\\n\".join(map(str, ans))))",
"-dfs(0, 0)",
"-for c in C:",
"- print(c)",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.111378 | 0.088771 | 1.254662 | [
"s622099751",
"s821838482"
] |
u707124227 | p02709 | python | s142304741 | s628140163 | 1,202 | 367 | 50,140 | 100,744 | Accepted | Accepted | 69.47 | import sys
import numpy as np
def f(n,a_):
a=[]
for i,ai in enumerate(a_):
a.append([1+i,ai])
a.sort(key=lambda x:x[1],reverse=True)
dp=np.zeros((n+1,n+1),np.int64) #dp[i,j]:i人目までを配置し終えていて、そのうちj人を右に置いた時の最大値。j<=i
dp[1,1]=a[0][1]*(n-a[0][0])
dp[1,0]=a[0][1]*(a[0][0]-1)
for i in range(2,n+1):#i人目の幼児。a[i-1]
dp[i,0]=dp[i-1,0]+a[i-1][1]*abs((a[i-1][0]-1-(i-1))) #i人目を左にする。その時左に溜まっているのはi-1人
dp[i,i]=dp[i-1,i-1]+a[i-1][1]*abs((n-a[i-1][0]-(i-1))) #i人目を右にする。その時右に溜まっているのはi-1人
#i人目を左に
l=dp[i-1,1:i]+[a[i-1][1]*abs((a[i-1][0]-1-j))for j in range(i-2,-1,-1)] #j:左に溜まっている人数
#i人目を右に
r=dp[i-1,:i-1]+[a[i-1][1]*abs((n-a[i-1][0]-j)) for j in range(i-1)] #j:右に溜まっている人数
dp[i,1:i]=np.maximum(l,r)
return max(dp[n])
if __name__ == '__main__':
input = sys.stdin.readline
n=int(eval(input()))
a_=list(map(int,input().split()))
print((f(n,a_)))
| n=int(eval(input()))
a_=list(map(int,input().split()))
a=[[i+1,ai] for i,ai in enumerate(a_)]
a.sort(key=lambda x:x[1],reverse=True)
dp=[[0]*(n+1) for _ in range(n+1)]
# dp[i][j]:大きい順にi+j人のうち、i人を左に、j人を右に移した時の最大値。
dp[1][0]=a[0][1]*abs(a[0][0]-1)
dp[0][1]=a[0][1]*abs(a[0][0]-n)
for k in range(2,n+1):
for i in range(k+1):
j=k-i
if j==0:
dp[i][j]=dp[i-1][j]+a[i+j-1][1]*abs(a[i+j-1][0]-i)
elif i==0:
dp[i][j]=dp[i][j-1]+a[i+j-1][1]*abs(n-a[i+j-1][0]-j+1)
else:
dp[i][j]=max(dp[i-1][j]+a[i+j-1][1]*abs(a[i+j-1][0]-i),dp[i][j-1]+a[i+j-1][1]*abs(n-a[i+j-1][0]-j+1))
ans=0
for i in range(n+1):
ans=max(dp[i][n-i],ans)
print(ans)
| 25 | 22 | 1,008 | 715 | import sys
import numpy as np
def f(n, a_):
a = []
for i, ai in enumerate(a_):
a.append([1 + i, ai])
a.sort(key=lambda x: x[1], reverse=True)
dp = np.zeros(
(n + 1, n + 1), np.int64
) # dp[i,j]:i人目までを配置し終えていて、そのうちj人を右に置いた時の最大値。j<=i
dp[1, 1] = a[0][1] * (n - a[0][0])
dp[1, 0] = a[0][1] * (a[0][0] - 1)
for i in range(2, n + 1): # i人目の幼児。a[i-1]
dp[i, 0] = dp[i - 1, 0] + a[i - 1][1] * abs(
(a[i - 1][0] - 1 - (i - 1))
) # i人目を左にする。その時左に溜まっているのはi-1人
dp[i, i] = dp[i - 1, i - 1] + a[i - 1][1] * abs(
(n - a[i - 1][0] - (i - 1))
) # i人目を右にする。その時右に溜まっているのはi-1人
# i人目を左に
l = dp[i - 1, 1:i] + [
a[i - 1][1] * abs((a[i - 1][0] - 1 - j)) for j in range(i - 2, -1, -1)
] # j:左に溜まっている人数
# i人目を右に
r = dp[i - 1, : i - 1] + [
a[i - 1][1] * abs((n - a[i - 1][0] - j)) for j in range(i - 1)
] # j:右に溜まっている人数
dp[i, 1:i] = np.maximum(l, r)
return max(dp[n])
if __name__ == "__main__":
input = sys.stdin.readline
n = int(eval(input()))
a_ = list(map(int, input().split()))
print((f(n, a_)))
| n = int(eval(input()))
a_ = list(map(int, input().split()))
a = [[i + 1, ai] for i, ai in enumerate(a_)]
a.sort(key=lambda x: x[1], reverse=True)
dp = [[0] * (n + 1) for _ in range(n + 1)]
# dp[i][j]:大きい順にi+j人のうち、i人を左に、j人を右に移した時の最大値。
dp[1][0] = a[0][1] * abs(a[0][0] - 1)
dp[0][1] = a[0][1] * abs(a[0][0] - n)
for k in range(2, n + 1):
for i in range(k + 1):
j = k - i
if j == 0:
dp[i][j] = dp[i - 1][j] + a[i + j - 1][1] * abs(a[i + j - 1][0] - i)
elif i == 0:
dp[i][j] = dp[i][j - 1] + a[i + j - 1][1] * abs(n - a[i + j - 1][0] - j + 1)
else:
dp[i][j] = max(
dp[i - 1][j] + a[i + j - 1][1] * abs(a[i + j - 1][0] - i),
dp[i][j - 1] + a[i + j - 1][1] * abs(n - a[i + j - 1][0] - j + 1),
)
ans = 0
for i in range(n + 1):
ans = max(dp[i][n - i], ans)
print(ans)
| false | 12 | [
"-import sys",
"-import numpy as np",
"-",
"-",
"-def f(n, a_):",
"- a = []",
"- for i, ai in enumerate(a_):",
"- a.append([1 + i, ai])",
"- a.sort(key=lambda x: x[1], reverse=True)",
"- dp = np.zeros(",
"- (n + 1, n + 1), np.int64",
"- ) # dp[i,j]:i人目までを配置し終えていて、そのうちj人を右に置いた時の最大値。j<=i",
"- dp[1, 1] = a[0][1] * (n - a[0][0])",
"- dp[1, 0] = a[0][1] * (a[0][0] - 1)",
"- for i in range(2, n + 1): # i人目の幼児。a[i-1]",
"- dp[i, 0] = dp[i - 1, 0] + a[i - 1][1] * abs(",
"- (a[i - 1][0] - 1 - (i - 1))",
"- ) # i人目を左にする。その時左に溜まっているのはi-1人",
"- dp[i, i] = dp[i - 1, i - 1] + a[i - 1][1] * abs(",
"- (n - a[i - 1][0] - (i - 1))",
"- ) # i人目を右にする。その時右に溜まっているのはi-1人",
"- # i人目を左に",
"- l = dp[i - 1, 1:i] + [",
"- a[i - 1][1] * abs((a[i - 1][0] - 1 - j)) for j in range(i - 2, -1, -1)",
"- ] # j:左に溜まっている人数",
"- # i人目を右に",
"- r = dp[i - 1, : i - 1] + [",
"- a[i - 1][1] * abs((n - a[i - 1][0] - j)) for j in range(i - 1)",
"- ] # j:右に溜まっている人数",
"- dp[i, 1:i] = np.maximum(l, r)",
"- return max(dp[n])",
"-",
"-",
"-if __name__ == \"__main__\":",
"- input = sys.stdin.readline",
"- n = int(eval(input()))",
"- a_ = list(map(int, input().split()))",
"- print((f(n, a_)))",
"+n = int(eval(input()))",
"+a_ = list(map(int, input().split()))",
"+a = [[i + 1, ai] for i, ai in enumerate(a_)]",
"+a.sort(key=lambda x: x[1], reverse=True)",
"+dp = [[0] * (n + 1) for _ in range(n + 1)]",
"+# dp[i][j]:大きい順にi+j人のうち、i人を左に、j人を右に移した時の最大値。",
"+dp[1][0] = a[0][1] * abs(a[0][0] - 1)",
"+dp[0][1] = a[0][1] * abs(a[0][0] - n)",
"+for k in range(2, n + 1):",
"+ for i in range(k + 1):",
"+ j = k - i",
"+ if j == 0:",
"+ dp[i][j] = dp[i - 1][j] + a[i + j - 1][1] * abs(a[i + j - 1][0] - i)",
"+ elif i == 0:",
"+ dp[i][j] = dp[i][j - 1] + a[i + j - 1][1] * abs(n - a[i + j - 1][0] - j + 1)",
"+ else:",
"+ dp[i][j] = max(",
"+ dp[i - 1][j] + a[i + j - 1][1] * abs(a[i + j - 1][0] - i),",
"+ dp[i][j - 1] + a[i + j - 1][1] * abs(n - a[i + j - 1][0] - j + 1),",
"+ )",
"+ans = 0",
"+for i in range(n + 1):",
"+ ans = max(dp[i][n - i], ans)",
"+print(ans)"
] | false | 0.315265 | 0.037751 | 8.351186 | [
"s142304741",
"s628140163"
] |
u923279197 | p02763 | python | s040905389 | s725344817 | 1,870 | 756 | 394,184 | 79,892 | Accepted | Accepted | 59.57 | class Binary_Indexed_Tree:
def __init__(self, n):
self.size = n
self.tree = [0 for _ in range(n+1)]
# a[i]にxを加算(1 <= i <= n) 1-indexed
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & (-i)
# a[1] から a[t] までの合計を得る (1 <= t <= n)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & (-i)
return s
alpha_small_dict = {chr(i):i-97 for i in range(97, 97+26)} #辞書ver
n = int(eval(input()))
S = eval(input())
data = [[0 for i in range(n)] for j in range(26)]
bit = [Binary_Indexed_Tree(n) for i in range(26)]
for i,x in enumerate(S):
bit[alpha_small_dict[x]].add(i+1,1)
data[alpha_small_dict[x]][i] = 1
q = int(eval(input()))
for i in range(q):
x,y,z = input().split()
x,y = int(x),int(y)
#print(x,y,z)
if x == 1:
num = alpha_small_dict[z]
for j in range(26):
if data[j][y-1] == 1:
data[j][y-1] = 0
bit[j].add(y,-1)
break
data[num][y-1] = 1
bit[num].add(y,1)
else:
z = int(z)
ans = 0
for j in range(26):
if bit[j].sum(z)-bit[j].sum(y-1) >= 1:
ans += 1
print(ans) | class OR_seg:
def __init__(self,n,init_val,ide_ele = 0):
# set_val
self.ide_ele = ide_ele
self.n = n
self.num = 2 ** (self.n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
# built
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.seg[2 * i + 1] | self.seg[2 * i + 2]
def update(self,k, x):
k += self.num - 1
self.seg[k] = x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2]
def add(self,k, x):
k += self.num - 1
self.seg[k] += x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2]
def query(self,p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res |= self.seg[p]
if q & 1 == 1:
res |= self.seg[q]
q -= 1
p = p // 2
q = (q - 1) // 2
res = res | self.seg[p]|self.seg[q]
return res
def bit_count(x): #立ってるビットの本数を出力
n = 0
while x:
n += 1
x &= x-1
return n
alpha_small_dict = {chr(i):i-97 for i in range(97, 97+26)} #辞書ver
n = int(eval(input()))
S = eval(input())
init = [2**alpha_small_dict[x] for x in S]
#print(init)
seg = OR_seg(n,init)
q = int(eval(input()))
for i in range(q):
x,y,z = input().split()
x,y = int(x),int(y)
#print(x,y,z)
if x == 1:
num = alpha_small_dict[z]
seg.update(y-1,2**num)
else:
z = int(z)
ans = seg.query(y-1,z)
print((bit_count(ans))) | 50 | 74 | 1,318 | 1,904 | class Binary_Indexed_Tree:
def __init__(self, n):
self.size = n
self.tree = [0 for _ in range(n + 1)]
# a[i]にxを加算(1 <= i <= n) 1-indexed
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & (-i)
# a[1] から a[t] までの合計を得る (1 <= t <= n)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & (-i)
return s
alpha_small_dict = {chr(i): i - 97 for i in range(97, 97 + 26)} # 辞書ver
n = int(eval(input()))
S = eval(input())
data = [[0 for i in range(n)] for j in range(26)]
bit = [Binary_Indexed_Tree(n) for i in range(26)]
for i, x in enumerate(S):
bit[alpha_small_dict[x]].add(i + 1, 1)
data[alpha_small_dict[x]][i] = 1
q = int(eval(input()))
for i in range(q):
x, y, z = input().split()
x, y = int(x), int(y)
# print(x,y,z)
if x == 1:
num = alpha_small_dict[z]
for j in range(26):
if data[j][y - 1] == 1:
data[j][y - 1] = 0
bit[j].add(y, -1)
break
data[num][y - 1] = 1
bit[num].add(y, 1)
else:
z = int(z)
ans = 0
for j in range(26):
if bit[j].sum(z) - bit[j].sum(y - 1) >= 1:
ans += 1
print(ans)
| class OR_seg:
def __init__(self, n, init_val, ide_ele=0):
# set_val
self.ide_ele = ide_ele
self.n = n
self.num = 2 ** (self.n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
# built
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.seg[2 * i + 1] | self.seg[2 * i + 2]
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2]
def add(self, k, x):
k += self.num - 1
self.seg[k] += x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2]
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res |= self.seg[p]
if q & 1 == 1:
res |= self.seg[q]
q -= 1
p = p // 2
q = (q - 1) // 2
res = res | self.seg[p] | self.seg[q]
return res
def bit_count(x): # 立ってるビットの本数を出力
n = 0
while x:
n += 1
x &= x - 1
return n
alpha_small_dict = {chr(i): i - 97 for i in range(97, 97 + 26)} # 辞書ver
n = int(eval(input()))
S = eval(input())
init = [2 ** alpha_small_dict[x] for x in S]
# print(init)
seg = OR_seg(n, init)
q = int(eval(input()))
for i in range(q):
x, y, z = input().split()
x, y = int(x), int(y)
# print(x,y,z)
if x == 1:
num = alpha_small_dict[z]
seg.update(y - 1, 2**num)
else:
z = int(z)
ans = seg.query(y - 1, z)
print((bit_count(ans)))
| false | 32.432432 | [
"-class Binary_Indexed_Tree:",
"- def __init__(self, n):",
"- self.size = n",
"- self.tree = [0 for _ in range(n + 1)]",
"+class OR_seg:",
"+ def __init__(self, n, init_val, ide_ele=0):",
"+ # set_val",
"+ self.ide_ele = ide_ele",
"+ self.n = n",
"+ self.num = 2 ** (self.n - 1).bit_length()",
"+ self.seg = [self.ide_ele] * 2 * self.num",
"+ for i in range(n):",
"+ self.seg[i + self.num - 1] = init_val[i]",
"+ # built",
"+ for i in range(self.num - 2, -1, -1):",
"+ self.seg[i] = self.seg[2 * i + 1] | self.seg[2 * i + 2]",
"- # a[i]にxを加算(1 <= i <= n) 1-indexed",
"- def add(self, i, x):",
"- while i <= self.size:",
"- self.tree[i] += x",
"- i += i & (-i)",
"+ def update(self, k, x):",
"+ k += self.num - 1",
"+ self.seg[k] = x",
"+ while k + 1:",
"+ k = (k - 1) // 2",
"+ self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2]",
"- # a[1] から a[t] までの合計を得る (1 <= t <= n)",
"- def sum(self, i):",
"- s = 0",
"- while i > 0:",
"- s += self.tree[i]",
"- i -= i & (-i)",
"- return s",
"+ def add(self, k, x):",
"+ k += self.num - 1",
"+ self.seg[k] += x",
"+ while k + 1:",
"+ k = (k - 1) // 2",
"+ self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2]",
"+",
"+ def query(self, p, q):",
"+ if q <= p:",
"+ return self.ide_ele",
"+ p += self.num - 1",
"+ q += self.num - 2",
"+ res = self.ide_ele",
"+ while q - p > 1:",
"+ if p & 1 == 0:",
"+ res |= self.seg[p]",
"+ if q & 1 == 1:",
"+ res |= self.seg[q]",
"+ q -= 1",
"+ p = p // 2",
"+ q = (q - 1) // 2",
"+ res = res | self.seg[p] | self.seg[q]",
"+ return res",
"+",
"+",
"+def bit_count(x): # 立ってるビットの本数を出力",
"+ n = 0",
"+ while x:",
"+ n += 1",
"+ x &= x - 1",
"+ return n",
"-data = [[0 for i in range(n)] for j in range(26)]",
"-bit = [Binary_Indexed_Tree(n) for i in range(26)]",
"-for i, x in enumerate(S):",
"- bit[alpha_small_dict[x]].add(i + 1, 1)",
"- data[alpha_small_dict[x]][i] = 1",
"+init = [2 ** alpha_small_dict[x] for x in S]",
"+# print(init)",
"+seg = OR_seg(n, init)",
"- for j in range(26):",
"- if data[j][y - 1] == 1:",
"- data[j][y - 1] = 0",
"- bit[j].add(y, -1)",
"- break",
"- data[num][y - 1] = 1",
"- bit[num].add(y, 1)",
"+ seg.update(y - 1, 2**num)",
"- ans = 0",
"- for j in range(26):",
"- if bit[j].sum(z) - bit[j].sum(y - 1) >= 1:",
"- ans += 1",
"- print(ans)",
"+ ans = seg.query(y - 1, z)",
"+ print((bit_count(ans)))"
] | false | 0.066669 | 0.041339 | 1.61275 | [
"s040905389",
"s725344817"
] |
u231095456 | p03295 | python | s455921627 | s639502528 | 372 | 282 | 18,260 | 23,884 | Accepted | Accepted | 24.19 | N, M = list(map(int,input().split()))
ls = [tuple(map(int,input().split())) for _ in range(M)]
ls.sort(key=lambda x:x[1])
l = 0
ans = 0
for a,b in ls:
if l <= a:
l = b
ans += 1
print(ans) | N,M = list(map(int,input().split()))
ls = [tuple(map(int,input().split())) for _ in range(M)]
ls.sort(key=lambda x:x[1],reverse=True)
ls.sort(key=lambda x:x[0],reverse=True)
r = N
cnt = 0
for i in range(M):
a,b = ls[i]
if b <= r:
cnt += 1
r = a
print(cnt) | 10 | 12 | 210 | 284 | N, M = list(map(int, input().split()))
ls = [tuple(map(int, input().split())) for _ in range(M)]
ls.sort(key=lambda x: x[1])
l = 0
ans = 0
for a, b in ls:
if l <= a:
l = b
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
ls = [tuple(map(int, input().split())) for _ in range(M)]
ls.sort(key=lambda x: x[1], reverse=True)
ls.sort(key=lambda x: x[0], reverse=True)
r = N
cnt = 0
for i in range(M):
a, b = ls[i]
if b <= r:
cnt += 1
r = a
print(cnt)
| false | 16.666667 | [
"-ls.sort(key=lambda x: x[1])",
"-l = 0",
"-ans = 0",
"-for a, b in ls:",
"- if l <= a:",
"- l = b",
"- ans += 1",
"-print(ans)",
"+ls.sort(key=lambda x: x[1], reverse=True)",
"+ls.sort(key=lambda x: x[0], reverse=True)",
"+r = N",
"+cnt = 0",
"+for i in range(M):",
"+ a, b = ls[i]",
"+ if b <= r:",
"+ cnt += 1",
"+ r = a",
"+print(cnt)"
] | false | 0.070276 | 0.038009 | 1.848895 | [
"s455921627",
"s639502528"
] |
u644907318 | p02767 | python | s873256562 | s266120440 | 73 | 62 | 63,776 | 63,732 | Accepted | Accepted | 15.07 | N = int(eval(input()))
X = list(map(int,input().split()))
cmin = 10**6
for i in range(1,101):
cnt = 0
for j in range(N):
cnt += (i-X[j])**2
cmin = min(cmin,cnt)
print(cmin) | N = int(eval(input()))
X = list(map(int,input().split()))
cmin = 10**6+10
for i in range(101):
cnt = 0
for j in range(N):
cnt += (i-X[j])**2
cmin = min(cmin,cnt)
print(cmin) | 9 | 9 | 194 | 195 | N = int(eval(input()))
X = list(map(int, input().split()))
cmin = 10**6
for i in range(1, 101):
cnt = 0
for j in range(N):
cnt += (i - X[j]) ** 2
cmin = min(cmin, cnt)
print(cmin)
| N = int(eval(input()))
X = list(map(int, input().split()))
cmin = 10**6 + 10
for i in range(101):
cnt = 0
for j in range(N):
cnt += (i - X[j]) ** 2
cmin = min(cmin, cnt)
print(cmin)
| false | 0 | [
"-cmin = 10**6",
"-for i in range(1, 101):",
"+cmin = 10**6 + 10",
"+for i in range(101):"
] | false | 0.040874 | 0.124043 | 0.329514 | [
"s873256562",
"s266120440"
] |
u250944591 | p03844 | python | s677452376 | s293961854 | 32 | 29 | 9,028 | 8,956 | Accepted | Accepted | 9.38 | print((eval(input().replace(' ','')))) | print((eval(input()))) | 1 | 1 | 36 | 20 | print((eval(input().replace(" ", ""))))
| print((eval(input())))
| false | 0 | [
"-print((eval(input().replace(\" \", \"\"))))",
"+print((eval(input())))"
] | false | 0.107609 | 0.109204 | 0.985393 | [
"s677452376",
"s293961854"
] |
u027685417 | p02850 | python | s927636009 | s609164105 | 1,406 | 574 | 61,968 | 96,424 | Accepted | Accepted | 59.17 | import sys
input = sys.stdin.readline
n = int(eval(input()))
GRAPH = {i:[] for i in range(1, n + 1)}
EDGES = []
for _ in range(n - 1):
a, b = list(map(int, input().split()))
GRAPH[a].append(b)
GRAPH[b].append(a)
EDGES.append((a, b))
PREV = {1:0}
Q = [1]
while Q:
now = Q.pop(0)
for vertex in GRAPH[now]:
if vertex == PREV[now]:
continue
next = vertex
PREV[next] = now
Q.append(next)
COLORS = {(0, 1):0}
Q = [1]
while Q:
now = Q.pop(0)
prev = PREV[now]
a, b = min(now, prev), max(now, prev)
used = COLORS[(a, b)]
color = 1
for vertex in GRAPH[now]:
if vertex == prev:
continue
next = vertex
a, b = min(now, next), max(now, next)
if color == used:
color += 1
COLORS[(a, b)] = color
color += 1
else:
COLORS[(a, b)] = color
color += 1
Q.append(next)
print((max(COLORS.values())))
for edge in EDGES:
print((COLORS[edge]))
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
n = int(eval(input()))
GRAPH = {i:[] for i in range(1, n + 1)}
EDGES = []
for _ in range(n - 1):
a, b = list(map(int, input().split()))
GRAPH[a].append(b)
GRAPH[b].append(a)
EDGES.append((a, b))
def dfs(now, prev = 0):
a, b = min(now, prev), max(now, prev)
used = COLORS[(a, b)]
color = 1
for v in GRAPH[now]:
if v == prev:
continue
next = v
a, b = min(now, next), max(now, next)
if color == used:
color += 1
COLORS[(a, b)] = color
color += 1
else:
COLORS[(a, b)] = color
color += 1
for v in GRAPH[now]:
if v == prev:
continue
next = v
dfs(next, now)
COLORS = {(0, 1):0}
dfs(1)
print((max(COLORS.values())))
for edge in EDGES:
print((COLORS[edge]))
| 51 | 44 | 1,078 | 942 | import sys
input = sys.stdin.readline
n = int(eval(input()))
GRAPH = {i: [] for i in range(1, n + 1)}
EDGES = []
for _ in range(n - 1):
a, b = list(map(int, input().split()))
GRAPH[a].append(b)
GRAPH[b].append(a)
EDGES.append((a, b))
PREV = {1: 0}
Q = [1]
while Q:
now = Q.pop(0)
for vertex in GRAPH[now]:
if vertex == PREV[now]:
continue
next = vertex
PREV[next] = now
Q.append(next)
COLORS = {(0, 1): 0}
Q = [1]
while Q:
now = Q.pop(0)
prev = PREV[now]
a, b = min(now, prev), max(now, prev)
used = COLORS[(a, b)]
color = 1
for vertex in GRAPH[now]:
if vertex == prev:
continue
next = vertex
a, b = min(now, next), max(now, next)
if color == used:
color += 1
COLORS[(a, b)] = color
color += 1
else:
COLORS[(a, b)] = color
color += 1
Q.append(next)
print((max(COLORS.values())))
for edge in EDGES:
print((COLORS[edge]))
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
n = int(eval(input()))
GRAPH = {i: [] for i in range(1, n + 1)}
EDGES = []
for _ in range(n - 1):
a, b = list(map(int, input().split()))
GRAPH[a].append(b)
GRAPH[b].append(a)
EDGES.append((a, b))
def dfs(now, prev=0):
a, b = min(now, prev), max(now, prev)
used = COLORS[(a, b)]
color = 1
for v in GRAPH[now]:
if v == prev:
continue
next = v
a, b = min(now, next), max(now, next)
if color == used:
color += 1
COLORS[(a, b)] = color
color += 1
else:
COLORS[(a, b)] = color
color += 1
for v in GRAPH[now]:
if v == prev:
continue
next = v
dfs(next, now)
COLORS = {(0, 1): 0}
dfs(1)
print((max(COLORS.values())))
for edge in EDGES:
print((COLORS[edge]))
| false | 13.72549 | [
"+sys.setrecursionlimit(10**9)",
"-PREV = {1: 0}",
"-Q = [1]",
"-while Q:",
"- now = Q.pop(0)",
"- for vertex in GRAPH[now]:",
"- if vertex == PREV[now]:",
"- continue",
"- next = vertex",
"- PREV[next] = now",
"- Q.append(next)",
"-COLORS = {(0, 1): 0}",
"-Q = [1]",
"-while Q:",
"- now = Q.pop(0)",
"- prev = PREV[now]",
"+",
"+",
"+def dfs(now, prev=0):",
"- for vertex in GRAPH[now]:",
"- if vertex == prev:",
"+ for v in GRAPH[now]:",
"+ if v == prev:",
"- next = vertex",
"+ next = v",
"- Q.append(next)",
"+ for v in GRAPH[now]:",
"+ if v == prev:",
"+ continue",
"+ next = v",
"+ dfs(next, now)",
"+",
"+",
"+COLORS = {(0, 1): 0}",
"+dfs(1)"
] | false | 0.039058 | 0.038802 | 1.006602 | [
"s927636009",
"s609164105"
] |
u984730891 | p03447 | python | s416777865 | s672167237 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
print(((x - a) % b)) | n = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
print(((n - a) % b)) | 4 | 4 | 72 | 72 | x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
print(((x - a) % b))
| n = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
print(((n - a) % b))
| false | 0 | [
"-x = int(eval(input()))",
"+n = int(eval(input()))",
"-print(((x - a) % b))",
"+print(((n - a) % b))"
] | false | 0.060363 | 0.068808 | 0.877263 | [
"s416777865",
"s672167237"
] |
u075012704 | p03283 | python | s690849471 | s229290674 | 1,820 | 1,681 | 33,932 | 76,504 | Accepted | Accepted | 7.64 | N, M, Q = list(map(int, input().split()))
class Ruisekiwa2D:
def __init__(self, h, w):
self.H = h
self.W = w
self.G = [[0] * w for _ in range(h)]
def load(self, points):
# 問題によってイメージしやすいよう書き換えてください
# load終了時にcalcが呼ばれることに注意してください
for x, y in points:
self.G[x][y] += 1
self.calc()
def load_imos(self, points):
# pointsは[[左上h, 左上w, 右下h, 右下w], ...]であること
for i1, j1, i2, j2 in points:
self.G[i1][j1] += 1 # 左上
if j2 + 1 < self.W: # 右上
self.G[i1][j2+1] -= 1
if i2 + 1 < self.H:
self.G[i2+1][j1] -= 1 # 左下
if j2 + 1 < self.W and i2 + 1 < self.H: # 右下
self.G[i2+1][j2+1] += 1
self.calc()
def calc(self):
for y in range(self.W):
for x in range(1, self.H):
self.G[x][y] += self.G[x-1][y]
for y in range(1, self.W):
for x in range(self.H):
self.G[x][y] += self.G[x][y-1]
def get(self, i1, j1, i2, j2):
if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
return 0
elif i1 > 0 and j1 > 0:
return self.G[i2][j2] - self.G[i1-1][j2] - self.G[i2][j1-1] + self.G[i1-1][j1-1]
elif i1 <= 0 < j1:
return self.G[i2][j2] - self.G[i2][j1-1]
elif j1 <= 0 < i1:
return self.G[i2][j2] - self.G[i1 - 1][j2]
else:
return self.G[i2][j2]
R2D = Ruisekiwa2D(N, N)
I = []
for i in range(M):
l, r = list(map(int, input().split()))
l, r = l -1, r- 1
I.append((l, r))
R2D.load(I)
for i in range(Q):
p, q = [int(x) - 1 for x in input().split()]
print((R2D.get(p, p, q, q)))
| N, M, Q = list(map(int, input().split()))
X = []
for i in range(M):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
X.append((l, r))
class Ruisekiwa2D:
def __init__(self, h, w):
self.H = h
self.W = w
self.G = [[0] * w for _ in range(h)]
def load(self, points):
# 問題によってイメージしやすいよう書き換えてください
for x, y in points:
self.G[x][y] += 1
def load_imos(self, points):
# pointsは[[左上h, 左上w, 右下h, 右下w], ...]であること
for i1, j1, i2, j2 in points:
self.G[i1][j1] += 1 # 左上
if j2 + 1 < self.W: # 右上
self.G[i1][j2+1] -= 1
if i2 + 1 < self.H:
self.G[i2+1][j1] -= 1 # 左下
if j2 + 1 < self.W and i2 + 1 < self.H: # 右下
self.G[i2+1][j2+1] += 1
def calc(self):
for y in range(self.W):
for x in range(1, self.H):
self.G[x][y] += self.G[x-1][y]
for y in range(1, self.W):
for x in range(self.H):
self.G[x][y] += self.G[x][y-1]
def get(self, i1, j1, i2, j2):
if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
return 0
elif i1 > 0 and j1 > 0:
return self.G[i2][j2] - self.G[i1-1][j2] - self.G[i2][j1-1] + self.G[i1-1][j1-1]
elif i1 <= 0 < j1:
return self.G[i2][j2] - self.G[i2][j1-1]
elif j1 <= 0 < i1:
return self.G[i2][j2] - self.G[i1 - 1][j2]
else:
return self.G[i2][j2]
R2D = Ruisekiwa2D(N, N)
R2D.load(X)
R2D.calc()
for q in range(Q):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
print((R2D.get(p, p, q, q)))
| 63 | 60 | 1,816 | 1,752 | N, M, Q = list(map(int, input().split()))
class Ruisekiwa2D:
def __init__(self, h, w):
self.H = h
self.W = w
self.G = [[0] * w for _ in range(h)]
def load(self, points):
# 問題によってイメージしやすいよう書き換えてください
# load終了時にcalcが呼ばれることに注意してください
for x, y in points:
self.G[x][y] += 1
self.calc()
def load_imos(self, points):
# pointsは[[左上h, 左上w, 右下h, 右下w], ...]であること
for i1, j1, i2, j2 in points:
self.G[i1][j1] += 1 # 左上
if j2 + 1 < self.W: # 右上
self.G[i1][j2 + 1] -= 1
if i2 + 1 < self.H:
self.G[i2 + 1][j1] -= 1 # 左下
if j2 + 1 < self.W and i2 + 1 < self.H: # 右下
self.G[i2 + 1][j2 + 1] += 1
self.calc()
def calc(self):
for y in range(self.W):
for x in range(1, self.H):
self.G[x][y] += self.G[x - 1][y]
for y in range(1, self.W):
for x in range(self.H):
self.G[x][y] += self.G[x][y - 1]
def get(self, i1, j1, i2, j2):
if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
return 0
elif i1 > 0 and j1 > 0:
return (
self.G[i2][j2]
- self.G[i1 - 1][j2]
- self.G[i2][j1 - 1]
+ self.G[i1 - 1][j1 - 1]
)
elif i1 <= 0 < j1:
return self.G[i2][j2] - self.G[i2][j1 - 1]
elif j1 <= 0 < i1:
return self.G[i2][j2] - self.G[i1 - 1][j2]
else:
return self.G[i2][j2]
R2D = Ruisekiwa2D(N, N)
I = []
for i in range(M):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
I.append((l, r))
R2D.load(I)
for i in range(Q):
p, q = [int(x) - 1 for x in input().split()]
print((R2D.get(p, p, q, q)))
| N, M, Q = list(map(int, input().split()))
X = []
for i in range(M):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
X.append((l, r))
class Ruisekiwa2D:
def __init__(self, h, w):
self.H = h
self.W = w
self.G = [[0] * w for _ in range(h)]
def load(self, points):
# 問題によってイメージしやすいよう書き換えてください
for x, y in points:
self.G[x][y] += 1
def load_imos(self, points):
# pointsは[[左上h, 左上w, 右下h, 右下w], ...]であること
for i1, j1, i2, j2 in points:
self.G[i1][j1] += 1 # 左上
if j2 + 1 < self.W: # 右上
self.G[i1][j2 + 1] -= 1
if i2 + 1 < self.H:
self.G[i2 + 1][j1] -= 1 # 左下
if j2 + 1 < self.W and i2 + 1 < self.H: # 右下
self.G[i2 + 1][j2 + 1] += 1
def calc(self):
for y in range(self.W):
for x in range(1, self.H):
self.G[x][y] += self.G[x - 1][y]
for y in range(1, self.W):
for x in range(self.H):
self.G[x][y] += self.G[x][y - 1]
def get(self, i1, j1, i2, j2):
if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
return 0
elif i1 > 0 and j1 > 0:
return (
self.G[i2][j2]
- self.G[i1 - 1][j2]
- self.G[i2][j1 - 1]
+ self.G[i1 - 1][j1 - 1]
)
elif i1 <= 0 < j1:
return self.G[i2][j2] - self.G[i2][j1 - 1]
elif j1 <= 0 < i1:
return self.G[i2][j2] - self.G[i1 - 1][j2]
else:
return self.G[i2][j2]
R2D = Ruisekiwa2D(N, N)
R2D.load(X)
R2D.calc()
for q in range(Q):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
print((R2D.get(p, p, q, q)))
| false | 4.761905 | [
"+X = []",
"+for i in range(M):",
"+ l, r = list(map(int, input().split()))",
"+ l, r = l - 1, r - 1",
"+ X.append((l, r))",
"- # load終了時にcalcが呼ばれることに注意してください",
"- self.calc()",
"- self.calc()",
"-I = []",
"-for i in range(M):",
"- l, r = list(map(int, input().split()))",
"- l, r = l - 1, r - 1",
"- I.append((l, r))",
"-R2D.load(I)",
"-for i in range(Q):",
"- p, q = [int(x) - 1 for x in input().split()]",
"+R2D.load(X)",
"+R2D.calc()",
"+for q in range(Q):",
"+ p, q = list(map(int, input().split()))",
"+ p, q = p - 1, q - 1"
] | false | 0.04574 | 0.077787 | 0.58801 | [
"s690849471",
"s229290674"
] |
u794544096 | p02707 | python | s222143487 | s744885005 | 187 | 172 | 92,312 | 92,168 | Accepted | Accepted | 8.02 | n = int(eval(input()))
a = list(map(int, input().split()))
list= [0]*n
for i in a:
list[i-1] += 1
for j in list:
print(j) | n = int(eval(input()))
a = list(map(int, input().split()))
li = [0]*n
for i in a:
li[i-1] += 1
#print(li)
for j in li:
print(j) | 9 | 12 | 133 | 144 | n = int(eval(input()))
a = list(map(int, input().split()))
list = [0] * n
for i in a:
list[i - 1] += 1
for j in list:
print(j)
| n = int(eval(input()))
a = list(map(int, input().split()))
li = [0] * n
for i in a:
li[i - 1] += 1
# print(li)
for j in li:
print(j)
| false | 25 | [
"-list = [0] * n",
"+li = [0] * n",
"- list[i - 1] += 1",
"-for j in list:",
"+ li[i - 1] += 1",
"+# print(li)",
"+for j in li:"
] | false | 0.086253 | 0.038934 | 2.215346 | [
"s222143487",
"s744885005"
] |
u863370423 | p03447 | python | s042990466 | s481703759 | 17 | 10 | 2,940 | 2,568 | Accepted | Accepted | 41.18 | x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
x = x-a
num = x//b
print((x-(num*b))) | x = eval(input())
a = eval(input())
b = eval(input())
x -= a
print(x % b) | 8 | 5 | 95 | 58 | x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
x = x - a
num = x // b
print((x - (num * b)))
| x = eval(input())
a = eval(input())
b = eval(input())
x -= a
print(x % b)
| false | 37.5 | [
"-x = int(eval(input()))",
"-a = int(eval(input()))",
"-b = int(eval(input()))",
"-x = x - a",
"-num = x // b",
"-print((x - (num * b)))",
"+x = eval(input())",
"+a = eval(input())",
"+b = eval(input())",
"+x -= a",
"+print(x % b)"
] | false | 0.03611 | 0.036467 | 0.990213 | [
"s042990466",
"s481703759"
] |
u875291233 | p02564 | python | s708668677 | s757263595 | 1,405 | 1,170 | 232,608 | 187,704 | Accepted | Accepted | 16.73 | def SCC_Tarjan(g):
def dfs(v):
nonlocal idx
pre[v] = low[v] = idx
idx += 1
S.append(v)
#onS[v] = 1
for c in g[v]:
if pre[c] == -1:
dfs(c)
low[v] = min(low[v], low[c])
#elif onS[c]:
else:
low[v] = min(low[v], pre[c])
if low[v] == pre[v]:
cc = []
while True:
w = S.pop()
#onS[w] = 0
pre[w] = n
cc.append(w)
if w==v: break
scc.append(cc)
n = len(g)
pre = [-1]*n # 負なら未処理、[0,n) ならpre-order, n ならvisited
low = [0]*n
onS = [0]*n
idx = 0
S = []
scc = []
for i in range(n):
if pre[i] == -1:
dfs(i)
#print(g)
#print("idx",pre)
#print("low",low)
#print(scc)
return scc
###########################################################################
###########################################################################
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10**6)
#n,*w = [int(i) for i in read().split()]
n,m = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for _ in range(m):
a,b = list(map(int, readline().split()))
g[a].append(b)
gp = SCC_Tarjan(g)
print((len(gp)))
for lst in gp[::-1]:
print((*([len(lst)]+lst)))
| def SCC_Tarjan(g):
n = len(g)
order = [-1]*n # 負なら未処理、[0,n) ならpre-order, n ならvisited
low = [0]*n
ord_now = 0
parent = [-1]*n
gp = [0]*n
gp_num = 0
S = []
q = []
for i in range(n):
if order[i] == -1:
q.append(i)
while q:
v = q.pop()
if v >= 0:
if order[v] != -1: continue
order[v] = low[v] = ord_now
ord_now += 1
S.append(v)
q.append(~v)
for c in g[v]:
if order[c] == -1:
q.append(c)
parent[c] = v
else:
low[v] = min(low[v], order[c])
else:
v = ~v
if parent[v] != -1:
low[parent[v]] = min(low[parent[v]], low[v])
if low[v] == order[v]:
while True:
w = S.pop()
order[w] = n
gp[w] = gp_num
if w==v: break
gp_num += 1
scc = [[] for _ in range(gp_num)]
for i in range(n):
gp[i] = gp_num-gp[i]-1
scc[gp[i]].append(i)
#print(gp)
return scc
###########################################################################
###########################################################################
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,m = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for _ in range(m):
a,b = list(map(int, readline().split()))
g[a].append(b)
scc = SCC_Tarjan(g)
print((len(scc)))
for lst in scc:
print((*([len(lst)]+lst)))
| 66 | 69 | 1,581 | 1,988 | def SCC_Tarjan(g):
def dfs(v):
nonlocal idx
pre[v] = low[v] = idx
idx += 1
S.append(v)
# onS[v] = 1
for c in g[v]:
if pre[c] == -1:
dfs(c)
low[v] = min(low[v], low[c])
# elif onS[c]:
else:
low[v] = min(low[v], pre[c])
if low[v] == pre[v]:
cc = []
while True:
w = S.pop()
# onS[w] = 0
pre[w] = n
cc.append(w)
if w == v:
break
scc.append(cc)
n = len(g)
pre = [-1] * n # 負なら未処理、[0,n) ならpre-order, n ならvisited
low = [0] * n
onS = [0] * n
idx = 0
S = []
scc = []
for i in range(n):
if pre[i] == -1:
dfs(i)
# print(g)
# print("idx",pre)
# print("low",low)
# print(scc)
return scc
###########################################################################
###########################################################################
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10**6)
# n,*w = [int(i) for i in read().split()]
n, m = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, readline().split()))
g[a].append(b)
gp = SCC_Tarjan(g)
print((len(gp)))
for lst in gp[::-1]:
print((*([len(lst)] + lst)))
| def SCC_Tarjan(g):
n = len(g)
order = [-1] * n # 負なら未処理、[0,n) ならpre-order, n ならvisited
low = [0] * n
ord_now = 0
parent = [-1] * n
gp = [0] * n
gp_num = 0
S = []
q = []
for i in range(n):
if order[i] == -1:
q.append(i)
while q:
v = q.pop()
if v >= 0:
if order[v] != -1:
continue
order[v] = low[v] = ord_now
ord_now += 1
S.append(v)
q.append(~v)
for c in g[v]:
if order[c] == -1:
q.append(c)
parent[c] = v
else:
low[v] = min(low[v], order[c])
else:
v = ~v
if parent[v] != -1:
low[parent[v]] = min(low[parent[v]], low[v])
if low[v] == order[v]:
while True:
w = S.pop()
order[w] = n
gp[w] = gp_num
if w == v:
break
gp_num += 1
scc = [[] for _ in range(gp_num)]
for i in range(n):
gp[i] = gp_num - gp[i] - 1
scc[gp[i]].append(i)
# print(gp)
return scc
###########################################################################
###########################################################################
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n, m = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, readline().split()))
g[a].append(b)
scc = SCC_Tarjan(g)
print((len(scc)))
for lst in scc:
print((*([len(lst)] + lst)))
| false | 4.347826 | [
"- def dfs(v):",
"- nonlocal idx",
"- pre[v] = low[v] = idx",
"- idx += 1",
"- S.append(v)",
"- # onS[v] = 1",
"- for c in g[v]:",
"- if pre[c] == -1:",
"- dfs(c)",
"- low[v] = min(low[v], low[c])",
"- # elif onS[c]:",
"- else:",
"- low[v] = min(low[v], pre[c])",
"- if low[v] == pre[v]:",
"- cc = []",
"- while True:",
"- w = S.pop()",
"- # onS[w] = 0",
"- pre[w] = n",
"- cc.append(w)",
"- if w == v:",
"- break",
"- scc.append(cc)",
"-",
"- pre = [-1] * n # 負なら未処理、[0,n) ならpre-order, n ならvisited",
"+ order = [-1] * n # 負なら未処理、[0,n) ならpre-order, n ならvisited",
"- onS = [0] * n",
"- idx = 0",
"+ ord_now = 0",
"+ parent = [-1] * n",
"+ gp = [0] * n",
"+ gp_num = 0",
"- scc = []",
"+ q = []",
"- if pre[i] == -1:",
"- dfs(i)",
"- # print(g)",
"- # print(\"idx\",pre)",
"- # print(\"low\",low)",
"- # print(scc)",
"+ if order[i] == -1:",
"+ q.append(i)",
"+ while q:",
"+ v = q.pop()",
"+ if v >= 0:",
"+ if order[v] != -1:",
"+ continue",
"+ order[v] = low[v] = ord_now",
"+ ord_now += 1",
"+ S.append(v)",
"+ q.append(~v)",
"+ for c in g[v]:",
"+ if order[c] == -1:",
"+ q.append(c)",
"+ parent[c] = v",
"+ else:",
"+ low[v] = min(low[v], order[c])",
"+ else:",
"+ v = ~v",
"+ if parent[v] != -1:",
"+ low[parent[v]] = min(low[parent[v]], low[v])",
"+ if low[v] == order[v]:",
"+ while True:",
"+ w = S.pop()",
"+ order[w] = n",
"+ gp[w] = gp_num",
"+ if w == v:",
"+ break",
"+ gp_num += 1",
"+ scc = [[] for _ in range(gp_num)]",
"+ for i in range(n):",
"+ gp[i] = gp_num - gp[i] - 1",
"+ scc[gp[i]].append(i)",
"+ # print(gp)",
"-sys.setrecursionlimit(10**6)",
"-# n,*w = [int(i) for i in read().split()]",
"-gp = SCC_Tarjan(g)",
"-print((len(gp)))",
"-for lst in gp[::-1]:",
"+scc = SCC_Tarjan(g)",
"+print((len(scc)))",
"+for lst in scc:"
] | false | 0.038054 | 0.038718 | 0.982847 | [
"s708668677",
"s757263595"
] |
u888092736 | p03426 | python | s934791981 | s596945433 | 609 | 557 | 36,256 | 27,368 | Accepted | Accepted | 8.54 | from itertools import accumulate
def get_dist(cur, nxt):
return abs(cur[0] - nxt[0]) + abs(cur[1] - nxt[1])
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
pos = {}
for i in range(H):
for j in range(W):
pos[A[i][j] - 1] = (i, j)
acc = []
for i in range(D):
res = [0]
now = i
while now + D < H * W:
nxt = now + D
res.append(get_dist(pos[now], pos[nxt]))
now = nxt
acc.append(list(accumulate(res)))
Q = int(eval(input()))
for _ in range(Q):
ans = 0
L, R = list(map(int, input().split()))
L -= 1
R -= 1
path = acc[L % D]
print((path[R // D] - path[L // D]))
| def get_dist(cur, nxt):
return abs(cur[0] - nxt[0]) + abs(cur[1] - nxt[1])
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
pos = {}
for i in range(H):
for j in range(W):
pos[A[i][j]] = (i, j)
acc = [0] * (H * W + 1)
for i in range(D + 1, H * W + 1):
acc[i] = acc[i - D] + get_dist(pos[i - D], pos[i])
Q = int(eval(input()))
for _ in range(Q):
ans = 0
L, R = list(map(int, input().split()))
print((acc[R] - acc[L]))
| 33 | 21 | 704 | 502 | from itertools import accumulate
def get_dist(cur, nxt):
return abs(cur[0] - nxt[0]) + abs(cur[1] - nxt[1])
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
pos = {}
for i in range(H):
for j in range(W):
pos[A[i][j] - 1] = (i, j)
acc = []
for i in range(D):
res = [0]
now = i
while now + D < H * W:
nxt = now + D
res.append(get_dist(pos[now], pos[nxt]))
now = nxt
acc.append(list(accumulate(res)))
Q = int(eval(input()))
for _ in range(Q):
ans = 0
L, R = list(map(int, input().split()))
L -= 1
R -= 1
path = acc[L % D]
print((path[R // D] - path[L // D]))
| def get_dist(cur, nxt):
return abs(cur[0] - nxt[0]) + abs(cur[1] - nxt[1])
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
pos = {}
for i in range(H):
for j in range(W):
pos[A[i][j]] = (i, j)
acc = [0] * (H * W + 1)
for i in range(D + 1, H * W + 1):
acc[i] = acc[i - D] + get_dist(pos[i - D], pos[i])
Q = int(eval(input()))
for _ in range(Q):
ans = 0
L, R = list(map(int, input().split()))
print((acc[R] - acc[L]))
| false | 36.363636 | [
"-from itertools import accumulate",
"-",
"-",
"- pos[A[i][j] - 1] = (i, j)",
"-acc = []",
"-for i in range(D):",
"- res = [0]",
"- now = i",
"- while now + D < H * W:",
"- nxt = now + D",
"- res.append(get_dist(pos[now], pos[nxt]))",
"- now = nxt",
"- acc.append(list(accumulate(res)))",
"+ pos[A[i][j]] = (i, j)",
"+acc = [0] * (H * W + 1)",
"+for i in range(D + 1, H * W + 1):",
"+ acc[i] = acc[i - D] + get_dist(pos[i - D], pos[i])",
"- L -= 1",
"- R -= 1",
"- path = acc[L % D]",
"- print((path[R // D] - path[L // D]))",
"+ print((acc[R] - acc[L]))"
] | false | 0.067501 | 0.039231 | 1.720609 | [
"s934791981",
"s596945433"
] |
u873482706 | p00180 | python | s445988015 | s127671285 | 30 | 20 | 4,332 | 4,316 | Accepted | Accepted | 33.33 | def f(s, cost, route, ans):
route.append(s)
ans += cost[s]
del cost[s]
for k, c in list(data.items()):
a, b = k
if s == a:
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
elif s == b:
if not a in route:
if not a in cost or c < cost[a]:
cost[a] = c
if cost:
s = sorted(list(cost.items()), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans)
else:
return ans
while True:
n, m = list(map(int, input().split()))
if n == m == 0: break
data = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
data[(a, b)] = c
else:
print(f(0, {0:0}, [], 0)) | def f(s, cost, route, ans):
route.append(s)
ans += cost[s]
del cost[s]
for k, c in list(data.items()):
if s in k:
a, b = k
b = b if s == a else a
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
if cost:
s = sorted(list(cost.items()), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans)
else:
return ans
while True:
n, m = list(map(int, input().split()))
if n == m == 0: break
data = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
data[(a, b)] = c
else:
print(f(0, {0:0}, [], 0)) | 29 | 26 | 793 | 696 | def f(s, cost, route, ans):
route.append(s)
ans += cost[s]
del cost[s]
for k, c in list(data.items()):
a, b = k
if s == a:
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
elif s == b:
if not a in route:
if not a in cost or c < cost[a]:
cost[a] = c
if cost:
s = sorted(list(cost.items()), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans)
else:
return ans
while True:
n, m = list(map(int, input().split()))
if n == m == 0:
break
data = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
data[(a, b)] = c
else:
print(f(0, {0: 0}, [], 0))
| def f(s, cost, route, ans):
route.append(s)
ans += cost[s]
del cost[s]
for k, c in list(data.items()):
if s in k:
a, b = k
b = b if s == a else a
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
if cost:
s = sorted(list(cost.items()), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans)
else:
return ans
while True:
n, m = list(map(int, input().split()))
if n == m == 0:
break
data = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
data[(a, b)] = c
else:
print(f(0, {0: 0}, [], 0))
| false | 10.344828 | [
"- a, b = k",
"- if s == a:",
"+ if s in k:",
"+ a, b = k",
"+ b = b if s == a else a",
"- elif s == b:",
"- if not a in route:",
"- if not a in cost or c < cost[a]:",
"- cost[a] = c"
] | false | 0.065721 | 0.065172 | 1.008426 | [
"s445988015",
"s127671285"
] |
u588341295 | p02743 | python | s230306508 | s307816651 | 37 | 18 | 5,032 | 3,064 | Accepted | Accepted | 51.35 | # -*- coding: utf-8 -*-
import sys
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
EPS = 10 ** -14
a, b, c = MAP()
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
Yes()
else:
No()
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
a, b, c = MAP()
if c-a-b >= 0 and 4*a*b < pow(c-a-b, 2):
Yes()
else:
No()
| 28 | 26 | 852 | 785 | # -*- coding: utf-8 -*-
import sys
from decimal import Decimal
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
EPS = 10**-14
a, b, c = MAP()
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
Yes()
else:
No()
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
a, b, c = MAP()
if c - a - b >= 0 and 4 * a * b < pow(c - a - b, 2):
Yes()
else:
No()
| false | 7.142857 | [
"-from decimal import Decimal",
"-EPS = 10**-14",
"-if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():",
"+if c - a - b >= 0 and 4 * a * b < pow(c - a - b, 2):"
] | false | 0.043459 | 0.049098 | 0.885159 | [
"s230306508",
"s307816651"
] |
u083960235 | p03738 | python | s098361660 | s596952051 | 47 | 38 | 5,528 | 5,144 | Accepted | Accepted | 19.15 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
a = INT()
b = INT()
if a > b:
print("GREATER")
elif a < b:
print("LESS")
else:
print("EQUAL") | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
A = INT()
B = INT()
if A > B :
print("GREATER")
elif A < B:
print("LESS")
else:
print("EQUAL") | 29 | 29 | 840 | 841 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
a = INT()
b = INT()
if a > b:
print("GREATER")
elif a < b:
print("LESS")
else:
print("EQUAL")
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
A = INT()
B = INT()
if A > B:
print("GREATER")
elif A < B:
print("LESS")
else:
print("EQUAL")
| false | 0 | [
"-a = INT()",
"-b = INT()",
"-if a > b:",
"+A = INT()",
"+B = INT()",
"+if A > B:",
"-elif a < b:",
"+elif A < B:"
] | false | 0.036979 | 0.042617 | 0.867702 | [
"s098361660",
"s596952051"
] |
u357751375 | p03296 | python | s037752678 | s613204844 | 33 | 28 | 9,176 | 9,100 | Accepted | Accepted | 15.15 | n = int(eval(input()))
a = list(map(int,input().split()))
p = 0
x = 0
y = 1
for i in range(n):
if a[i] != x:
if y == 1:
x = a[i]
else:
p += y // 2
x = a[i]
y = 1
else:
y += 1
if y == 1:
print(p)
else:
print((p + y // 2)) | n = int(eval(input()))
a = list(map(int,input().split()))
x = a[0]
y = 1
ans = 0
for i in range(1,n):
if a[i] == x:
y += 1
else:
ans += y // 2
x = a[i]
y = 1
print((ans + y // 2)) | 21 | 13 | 322 | 223 | n = int(eval(input()))
a = list(map(int, input().split()))
p = 0
x = 0
y = 1
for i in range(n):
if a[i] != x:
if y == 1:
x = a[i]
else:
p += y // 2
x = a[i]
y = 1
else:
y += 1
if y == 1:
print(p)
else:
print((p + y // 2))
| n = int(eval(input()))
a = list(map(int, input().split()))
x = a[0]
y = 1
ans = 0
for i in range(1, n):
if a[i] == x:
y += 1
else:
ans += y // 2
x = a[i]
y = 1
print((ans + y // 2))
| false | 38.095238 | [
"-p = 0",
"-x = 0",
"+x = a[0]",
"-for i in range(n):",
"- if a[i] != x:",
"- if y == 1:",
"- x = a[i]",
"- else:",
"- p += y // 2",
"- x = a[i]",
"- y = 1",
"+ans = 0",
"+for i in range(1, n):",
"+ if a[i] == x:",
"+ y += 1",
"- y += 1",
"-if y == 1:",
"- print(p)",
"-else:",
"- print((p + y // 2))",
"+ ans += y // 2",
"+ x = a[i]",
"+ y = 1",
"+print((ans + y // 2))"
] | false | 0.041949 | 0.042509 | 0.986834 | [
"s037752678",
"s613204844"
] |
u761320129 | p03682 | python | s882446657 | s822214517 | 1,111 | 731 | 53,524 | 53,224 | Accepted | Accepted | 34.2 | import sys
input = sys.stdin.readline
N = int(eval(input()))
XY = [tuple(map(int,input().split() + [i])) for i in range(N)]
class UnionFind:
def __init__(self,N):
self.parent = [i for i in range(N)]
self._size = [1] * N
self.count = 0
def root(self,a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self,a,b):
return self.root(a) == self.root(b)
def unite(self,a,b):
ra = self.root(a)
rb = self.root(b)
if ra == rb: return
if self._size[ra] < self._size[rb]: ra,rb = rb,ra
self._size[ra] += self._size[rb]
self.parent[rb] = ra
self.count += 1
def size(self,a):
return self._size[self.root(a)]
uf = UnionFind(N)
sx = sorted(XY, key=lambda x:x[0])
sy = sorted(XY, key=lambda x:x[1])
es = []
for (x1,_,i),(x2,_,j) in zip(sx,sx[1:]):
es.append((x2-x1, i, j))
for (_,y1,i),(_,y2,j) in zip(sy,sy[1:]):
es.append((y2-y1, i, j))
es.sort(key=lambda x:x[0])
ans = 0
for d,i,j in es:
if uf.is_same(i,j): continue
uf.unite(i,j)
ans += d
print(ans) | import sys
input = sys.stdin.readline
N = int(eval(input()))
XYI = [tuple(map(int,input().split() + [i])) for i in range(N)]
sx = sorted(XYI, key=lambda x:x[0])
sy = sorted(XYI, key=lambda x:x[1])
es = []
for (x0,_,i0),(x1,_,i1) in zip(sx,sx[1:]):
es.append((x1-x0, i0, i1))
for (_,y0,i0),(_,y1,i1) in zip(sy,sy[1:]):
es.append((y1-y0, i0, i1))
es.sort(key=lambda x:x[0])
class UnionFind:
def __init__(self,N):
self.parent = [i for i in range(N)]
self._size = [1] * N
self.count = 0
def root(self,a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self,a,b):
return self.root(a) == self.root(b)
def unite(self,a,b):
ra = self.root(a)
rb = self.root(b)
if ra == rb: return
if self._size[ra] < self._size[rb]: ra,rb = rb,ra
self._size[ra] += self._size[rb]
self.parent[rb] = ra
self.count += 1
def size(self,a):
return self._size[self.root(a)]
uf = UnionFind(N)
ans = 0
for d,a,b in es:
if uf.is_same(a,b): continue
uf.unite(a,b)
ans += d
print(ans) | 46 | 45 | 1,236 | 1,245 | import sys
input = sys.stdin.readline
N = int(eval(input()))
XY = [tuple(map(int, input().split() + [i])) for i in range(N)]
class UnionFind:
def __init__(self, N):
self.parent = [i for i in range(N)]
self._size = [1] * N
self.count = 0
def root(self, a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self, a, b):
return self.root(a) == self.root(b)
def unite(self, a, b):
ra = self.root(a)
rb = self.root(b)
if ra == rb:
return
if self._size[ra] < self._size[rb]:
ra, rb = rb, ra
self._size[ra] += self._size[rb]
self.parent[rb] = ra
self.count += 1
def size(self, a):
return self._size[self.root(a)]
uf = UnionFind(N)
sx = sorted(XY, key=lambda x: x[0])
sy = sorted(XY, key=lambda x: x[1])
es = []
for (x1, _, i), (x2, _, j) in zip(sx, sx[1:]):
es.append((x2 - x1, i, j))
for (_, y1, i), (_, y2, j) in zip(sy, sy[1:]):
es.append((y2 - y1, i, j))
es.sort(key=lambda x: x[0])
ans = 0
for d, i, j in es:
if uf.is_same(i, j):
continue
uf.unite(i, j)
ans += d
print(ans)
| import sys
input = sys.stdin.readline
N = int(eval(input()))
XYI = [tuple(map(int, input().split() + [i])) for i in range(N)]
sx = sorted(XYI, key=lambda x: x[0])
sy = sorted(XYI, key=lambda x: x[1])
es = []
for (x0, _, i0), (x1, _, i1) in zip(sx, sx[1:]):
es.append((x1 - x0, i0, i1))
for (_, y0, i0), (_, y1, i1) in zip(sy, sy[1:]):
es.append((y1 - y0, i0, i1))
es.sort(key=lambda x: x[0])
class UnionFind:
def __init__(self, N):
self.parent = [i for i in range(N)]
self._size = [1] * N
self.count = 0
def root(self, a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self, a, b):
return self.root(a) == self.root(b)
def unite(self, a, b):
ra = self.root(a)
rb = self.root(b)
if ra == rb:
return
if self._size[ra] < self._size[rb]:
ra, rb = rb, ra
self._size[ra] += self._size[rb]
self.parent[rb] = ra
self.count += 1
def size(self, a):
return self._size[self.root(a)]
uf = UnionFind(N)
ans = 0
for d, a, b in es:
if uf.is_same(a, b):
continue
uf.unite(a, b)
ans += d
print(ans)
| false | 2.173913 | [
"-XY = [tuple(map(int, input().split() + [i])) for i in range(N)]",
"+XYI = [tuple(map(int, input().split() + [i])) for i in range(N)]",
"+sx = sorted(XYI, key=lambda x: x[0])",
"+sy = sorted(XYI, key=lambda x: x[1])",
"+es = []",
"+for (x0, _, i0), (x1, _, i1) in zip(sx, sx[1:]):",
"+ es.append((x1 - x0, i0, i1))",
"+for (_, y0, i0), (_, y1, i1) in zip(sy, sy[1:]):",
"+ es.append((y1 - y0, i0, i1))",
"+es.sort(key=lambda x: x[0])",
"-sx = sorted(XY, key=lambda x: x[0])",
"-sy = sorted(XY, key=lambda x: x[1])",
"-es = []",
"-for (x1, _, i), (x2, _, j) in zip(sx, sx[1:]):",
"- es.append((x2 - x1, i, j))",
"-for (_, y1, i), (_, y2, j) in zip(sy, sy[1:]):",
"- es.append((y2 - y1, i, j))",
"-es.sort(key=lambda x: x[0])",
"-for d, i, j in es:",
"- if uf.is_same(i, j):",
"+for d, a, b in es:",
"+ if uf.is_same(a, b):",
"- uf.unite(i, j)",
"+ uf.unite(a, b)"
] | false | 0.045559 | 0.188726 | 0.241402 | [
"s882446657",
"s822214517"
] |
u063052907 | p03478 | python | s517977524 | s676291046 | 34 | 31 | 3,060 | 2,940 | Accepted | Accepted | 8.82 | # coding: utf-8
N, A, B = list(map(int, input().split()))
ans = 0
for x in range(1, N+1):
z = str(x)
sum_x = sum(int(y) for y in z)
if A <= sum_x <= B:
ans += x
print(ans) | # coding: utf-8
N, A, B = list(map(int, input().split()))
ans = 0
for x in range(1, N+1):
sum_x = sum(map(int, str(x)))
if A <= sum_x <= B:
ans += x
print(ans) | 9 | 8 | 193 | 176 | # coding: utf-8
N, A, B = list(map(int, input().split()))
ans = 0
for x in range(1, N + 1):
z = str(x)
sum_x = sum(int(y) for y in z)
if A <= sum_x <= B:
ans += x
print(ans)
| # coding: utf-8
N, A, B = list(map(int, input().split()))
ans = 0
for x in range(1, N + 1):
sum_x = sum(map(int, str(x)))
if A <= sum_x <= B:
ans += x
print(ans)
| false | 11.111111 | [
"- z = str(x)",
"- sum_x = sum(int(y) for y in z)",
"+ sum_x = sum(map(int, str(x)))"
] | false | 0.047194 | 0.044317 | 1.064904 | [
"s517977524",
"s676291046"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.