user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u578049848 | p03944 | python | s561358693 | s327151310 | 140 | 18 | 3,316 | 3,064 | Accepted | Accepted | 87.14 | W,H,N = list(map(int,input().split()))
CoordinateList = []
for i in range(N):
x,y,a = list(map(int, input().split()))
CoordinateList.append([x,y,a])
# raw White & Black
AllArea = []
for numline in range(H):
rawWhite = []
rawBlack = []
for numraw in range(W):
rawWhite.append("W")
rawBlack.append("B")
AllArea.append(rawWhite)
# coloring from white to Black
for n in range(N):
if CoordinateList[n][2] == 1:
if CoordinateList[n][0] == 0:
pass
else:
for i in range(H):
del AllArea[i][:(CoordinateList[n][0])]
for numX in range(CoordinateList[n][0]):
AllArea[i].insert(0,"B")
elif CoordinateList[n][2] == 2:
if CoordinateList[n][0] == 0:
print((0))
exit()
else:
for i in range(H):
del AllArea[i][(CoordinateList[n][0]):]
for numX in range(CoordinateList[n][0]):
AllArea[i].append("B")
elif CoordinateList[n][2] == 3:
changeY = H - int(CoordinateList[n][1])
if changeY == 0:
print((0))
exit()
else:
del AllArea[changeY:]
for changeRaw in range(int(CoordinateList[n][1])):
AllArea.append(rawBlack)
elif CoordinateList[n][2] == 4:
changeY = H - int(CoordinateList[n][1])
if changeY == 0:
pass
else:
del AllArea[:changeY]
for changeRaw in range(changeY):
AllArea.insert(0,rawBlack)
# counting
AreaWhite = 0
for i in range(H):
AreaWhite += AllArea[i].count("W")
print(AreaWhite) | W,H,N = list(map(int,input().split()))
CoordinateList1 = []
CoordinateList2 = []
CoordinateList3 = []
CoordinateList4 = []
for i in range(N):
x,y,a = list(map(int, input().split()))
if a == 1:
CoordinateList1.append(x)
elif a == 2:
CoordinateList2.append(x)
elif a == 3:
CoordinateList3.append(y)
elif a == 4:
CoordinateList4.append(y)
# X
a1 = 0
if sorted(CoordinateList1) != []:
a1 = sorted(CoordinateList1)[-1]
a2 = W
if sorted(CoordinateList2) != []:
a2 = sorted(CoordinateList2)[0]
# Y
a3 = 0
if sorted(CoordinateList3) != []:
a3 = sorted(CoordinateList3)[-1]
a4 = H
if sorted(CoordinateList4) != []:
a4 = sorted(CoordinateList4)[0]
if (int(a2)-int(a1)) > 0 and (int(a4)-int(a3)) > 0:
print(((int(a2)-int(a1))*(int(a4)-int(a3))))
else:
print((0)) | 65 | 36 | 1,786 | 849 | W, H, N = list(map(int, input().split()))
CoordinateList = []
for i in range(N):
x, y, a = list(map(int, input().split()))
CoordinateList.append([x, y, a])
# raw White & Black
AllArea = []
for numline in range(H):
rawWhite = []
rawBlack = []
for numraw in range(W):
rawWhite.append("W")
rawBlack.append("B")
AllArea.append(rawWhite)
# coloring from white to Black
for n in range(N):
if CoordinateList[n][2] == 1:
if CoordinateList[n][0] == 0:
pass
else:
for i in range(H):
del AllArea[i][: (CoordinateList[n][0])]
for numX in range(CoordinateList[n][0]):
AllArea[i].insert(0, "B")
elif CoordinateList[n][2] == 2:
if CoordinateList[n][0] == 0:
print((0))
exit()
else:
for i in range(H):
del AllArea[i][(CoordinateList[n][0]) :]
for numX in range(CoordinateList[n][0]):
AllArea[i].append("B")
elif CoordinateList[n][2] == 3:
changeY = H - int(CoordinateList[n][1])
if changeY == 0:
print((0))
exit()
else:
del AllArea[changeY:]
for changeRaw in range(int(CoordinateList[n][1])):
AllArea.append(rawBlack)
elif CoordinateList[n][2] == 4:
changeY = H - int(CoordinateList[n][1])
if changeY == 0:
pass
else:
del AllArea[:changeY]
for changeRaw in range(changeY):
AllArea.insert(0, rawBlack)
# counting
AreaWhite = 0
for i in range(H):
AreaWhite += AllArea[i].count("W")
print(AreaWhite)
| W, H, N = list(map(int, input().split()))
CoordinateList1 = []
CoordinateList2 = []
CoordinateList3 = []
CoordinateList4 = []
for i in range(N):
x, y, a = list(map(int, input().split()))
if a == 1:
CoordinateList1.append(x)
elif a == 2:
CoordinateList2.append(x)
elif a == 3:
CoordinateList3.append(y)
elif a == 4:
CoordinateList4.append(y)
# X
a1 = 0
if sorted(CoordinateList1) != []:
a1 = sorted(CoordinateList1)[-1]
a2 = W
if sorted(CoordinateList2) != []:
a2 = sorted(CoordinateList2)[0]
# Y
a3 = 0
if sorted(CoordinateList3) != []:
a3 = sorted(CoordinateList3)[-1]
a4 = H
if sorted(CoordinateList4) != []:
a4 = sorted(CoordinateList4)[0]
if (int(a2) - int(a1)) > 0 and (int(a4) - int(a3)) > 0:
print(((int(a2) - int(a1)) * (int(a4) - int(a3))))
else:
print((0))
| false | 44.615385 | [
"-CoordinateList = []",
"+CoordinateList1 = []",
"+CoordinateList2 = []",
"+CoordinateList3 = []",
"+CoordinateList4 = []",
"- CoordinateList.append([x, y, a])",
"-# raw White & Black",
"-AllArea = []",
"-for numline in range(H):",
"- rawWhite = []",
"- rawBlack = []",
"- for numraw in range(W):",
"- rawWhite.append(\"W\")",
"- rawBlack.append(\"B\")",
"- AllArea.append(rawWhite)",
"-# coloring from white to Black",
"-for n in range(N):",
"- if CoordinateList[n][2] == 1:",
"- if CoordinateList[n][0] == 0:",
"- pass",
"- else:",
"- for i in range(H):",
"- del AllArea[i][: (CoordinateList[n][0])]",
"- for numX in range(CoordinateList[n][0]):",
"- AllArea[i].insert(0, \"B\")",
"- elif CoordinateList[n][2] == 2:",
"- if CoordinateList[n][0] == 0:",
"- print((0))",
"- exit()",
"- else:",
"- for i in range(H):",
"- del AllArea[i][(CoordinateList[n][0]) :]",
"- for numX in range(CoordinateList[n][0]):",
"- AllArea[i].append(\"B\")",
"- elif CoordinateList[n][2] == 3:",
"- changeY = H - int(CoordinateList[n][1])",
"- if changeY == 0:",
"- print((0))",
"- exit()",
"- else:",
"- del AllArea[changeY:]",
"- for changeRaw in range(int(CoordinateList[n][1])):",
"- AllArea.append(rawBlack)",
"- elif CoordinateList[n][2] == 4:",
"- changeY = H - int(CoordinateList[n][1])",
"- if changeY == 0:",
"- pass",
"- else:",
"- del AllArea[:changeY]",
"- for changeRaw in range(changeY):",
"- AllArea.insert(0, rawBlack)",
"-# counting",
"-AreaWhite = 0",
"-for i in range(H):",
"- AreaWhite += AllArea[i].count(\"W\")",
"-print(AreaWhite)",
"+ if a == 1:",
"+ CoordinateList1.append(x)",
"+ elif a == 2:",
"+ CoordinateList2.append(x)",
"+ elif a == 3:",
"+ CoordinateList3.append(y)",
"+ elif a == 4:",
"+ CoordinateList4.append(y)",
"+# X",
"+a1 = 0",
"+if sorted(CoordinateList1) != []:",
"+ a1 = sorted(CoordinateList1)[-1]",
"+a2 = W",
"+if sorted(CoordinateList2) != []:",
"+ a2 = sorted(CoordinateList2)[0]",
"+# Y",
"+a3 = 0",
"+if sorted(CoordinateList3) != []:",
"+ a3 = sorted(CoordinateList3)[-1]",
"+a4 = H",
"+if sorted(CoordinateList4) != []:",
"+ a4 = sorted(CoordinateList4)[0]",
"+if (int(a2) - int(a1)) > 0 and (int(a4) - int(a3)) > 0:",
"+ print(((int(a2) - int(a1)) * (int(a4) - int(a3))))",
"+else:",
"+ print((0))"
]
| false | 0.03653 | 0.041786 | 0.874215 | [
"s561358693",
"s327151310"
]
|
u867408000 | p02761 | python | s679221711 | s438655497 | 70 | 63 | 61,992 | 62,420 | Accepted | Accepted | 10 | N, M = list(map(int,input().split()))
check_lis = [-1 for _ in range(N)]
for _ in range(M):
s,c = list(map(int,input().split()))
if check_lis[s-1] == -1:
check_lis[s-1] = c
else:
if check_lis[s-1] != c:
print('-1')
break
if check_lis[0] == 0 and N != 1:
print('-1')
break
else:
min_range = 10 ** (N-1)
max_range = 10 * min_range
if min_range == 1:
min_range = 0
for i in range(min_range, max_range):
for idx, check in enumerate(check_lis):
if check == -1:
continue
if (i // 10 ** (N - idx - 1)) % 10 != check:
break
else:
print(i)
break | N, M = list(map(int, input().split()))
if N == 1:
min_range = 0
max_range = 10
else:
min_range = 10 ** (N-1)
max_range = 10 ** N
digits_lis = ['not defined' for _ in range(N+1)]
for _ in range(M):
s, c = list(map(int, input().split()))
if digits_lis[s] == 'not defined':
digits_lis[s] = c
else:
if digits_lis[s] != c:
print('-1')
break
if digits_lis[1] == 0 and N != 1:
print('-1')
break
else:
for i in range(min_range, max_range):
for idx, check in enumerate(digits_lis):
if check == 'not defined':
continue
if (i // 10 ** (N - idx)) % 10 != check:
break
else:
print(i)
break
| 27 | 29 | 742 | 781 | N, M = list(map(int, input().split()))
check_lis = [-1 for _ in range(N)]
for _ in range(M):
s, c = list(map(int, input().split()))
if check_lis[s - 1] == -1:
check_lis[s - 1] = c
else:
if check_lis[s - 1] != c:
print("-1")
break
if check_lis[0] == 0 and N != 1:
print("-1")
break
else:
min_range = 10 ** (N - 1)
max_range = 10 * min_range
if min_range == 1:
min_range = 0
for i in range(min_range, max_range):
for idx, check in enumerate(check_lis):
if check == -1:
continue
if (i // 10 ** (N - idx - 1)) % 10 != check:
break
else:
print(i)
break
| N, M = list(map(int, input().split()))
if N == 1:
min_range = 0
max_range = 10
else:
min_range = 10 ** (N - 1)
max_range = 10**N
digits_lis = ["not defined" for _ in range(N + 1)]
for _ in range(M):
s, c = list(map(int, input().split()))
if digits_lis[s] == "not defined":
digits_lis[s] = c
else:
if digits_lis[s] != c:
print("-1")
break
if digits_lis[1] == 0 and N != 1:
print("-1")
break
else:
for i in range(min_range, max_range):
for idx, check in enumerate(digits_lis):
if check == "not defined":
continue
if (i // 10 ** (N - idx)) % 10 != check:
break
else:
print(i)
break
| false | 6.896552 | [
"-check_lis = [-1 for _ in range(N)]",
"+if N == 1:",
"+ min_range = 0",
"+ max_range = 10",
"+else:",
"+ min_range = 10 ** (N - 1)",
"+ max_range = 10**N",
"+digits_lis = [\"not defined\" for _ in range(N + 1)]",
"- if check_lis[s - 1] == -1:",
"- check_lis[s - 1] = c",
"+ if digits_lis[s] == \"not defined\":",
"+ digits_lis[s] = c",
"- if check_lis[s - 1] != c:",
"+ if digits_lis[s] != c:",
"- if check_lis[0] == 0 and N != 1:",
"+ if digits_lis[1] == 0 and N != 1:",
"- min_range = 10 ** (N - 1)",
"- max_range = 10 * min_range",
"- if min_range == 1:",
"- min_range = 0",
"- for idx, check in enumerate(check_lis):",
"- if check == -1:",
"+ for idx, check in enumerate(digits_lis):",
"+ if check == \"not defined\":",
"- if (i // 10 ** (N - idx - 1)) % 10 != check:",
"+ if (i // 10 ** (N - idx)) % 10 != check:"
]
| false | 0.036199 | 0.033864 | 1.06897 | [
"s679221711",
"s438655497"
]
|
u607884285 | p03557 | python | s615193737 | s810549172 | 1,159 | 1,068 | 23,092 | 24,180 | Accepted | Accepted | 7.85 | n=int(eval(input()))
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
c=list(map(int,input().split(' ')))
a=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]
def bin_search_a(a,b):
low=0
high=len(a)-1
while low<=high:
mid=(low+high)//2
if a[mid] < b <= a[mid+1]:
return mid
if a[mid] >= b:
high=mid-1
else:
low=mid+1
def bin_search_c(c,b):
low=0
high=len(c)-1
while low<=high:
mid=(low+high)//2
if c[mid] <= b < c[mid+1]:
return mid
if c[mid] > b:
high=mid-1
else:
low=mid+1
altar=0
for bi in b:
s=bin_search_a(a,bi)*(n-bin_search_c(c,bi))
altar+=s
print(altar) | n=int(eval(input()))
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
c=list(map(int,input().split(' ')))
a=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]
def meguru_a(bi):
ng=n+1 ; ok=0
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if a[mid] < bi :
ok = mid
else:
ng = mid
return ok
def meguru_c(bi):
ng=-1 ; ok=n
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if bi < c[mid+1]:
ok = mid
else:
ng = mid
return ok
altar=0
for bi in b:
s=meguru_a(bi)*(n - meguru_c(bi))
altar+=s
print(altar) | 38 | 34 | 802 | 688 | n = int(eval(input()))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
c = list(map(int, input().split(" ")))
a = [0] + sorted(a) + [float("inf")]
c = [0] + sorted(c) + [float("inf")]
def bin_search_a(a, b):
low = 0
high = len(a) - 1
while low <= high:
mid = (low + high) // 2
if a[mid] < b <= a[mid + 1]:
return mid
if a[mid] >= b:
high = mid - 1
else:
low = mid + 1
def bin_search_c(c, b):
low = 0
high = len(c) - 1
while low <= high:
mid = (low + high) // 2
if c[mid] <= b < c[mid + 1]:
return mid
if c[mid] > b:
high = mid - 1
else:
low = mid + 1
altar = 0
for bi in b:
s = bin_search_a(a, bi) * (n - bin_search_c(c, bi))
altar += s
print(altar)
| n = int(eval(input()))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
c = list(map(int, input().split(" ")))
a = [0] + sorted(a) + [float("inf")]
c = [0] + sorted(c) + [float("inf")]
def meguru_a(bi):
ng = n + 1
ok = 0
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if a[mid] < bi:
ok = mid
else:
ng = mid
return ok
def meguru_c(bi):
ng = -1
ok = n
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if bi < c[mid + 1]:
ok = mid
else:
ng = mid
return ok
altar = 0
for bi in b:
s = meguru_a(bi) * (n - meguru_c(bi))
altar += s
print(altar)
| false | 10.526316 | [
"-def bin_search_a(a, b):",
"- low = 0",
"- high = len(a) - 1",
"- while low <= high:",
"- mid = (low + high) // 2",
"- if a[mid] < b <= a[mid + 1]:",
"- return mid",
"- if a[mid] >= b:",
"- high = mid - 1",
"+def meguru_a(bi):",
"+ ng = n + 1",
"+ ok = 0",
"+ while abs(ok - ng) > 1:",
"+ mid = (ok + ng) // 2",
"+ if a[mid] < bi:",
"+ ok = mid",
"- low = mid + 1",
"+ ng = mid",
"+ return ok",
"-def bin_search_c(c, b):",
"- low = 0",
"- high = len(c) - 1",
"- while low <= high:",
"- mid = (low + high) // 2",
"- if c[mid] <= b < c[mid + 1]:",
"- return mid",
"- if c[mid] > b:",
"- high = mid - 1",
"+def meguru_c(bi):",
"+ ng = -1",
"+ ok = n",
"+ while abs(ok - ng) > 1:",
"+ mid = (ok + ng) // 2",
"+ if bi < c[mid + 1]:",
"+ ok = mid",
"- low = mid + 1",
"+ ng = mid",
"+ return ok",
"- s = bin_search_a(a, bi) * (n - bin_search_c(c, bi))",
"+ s = meguru_a(bi) * (n - meguru_c(bi))"
]
| false | 0.047624 | 0.047721 | 0.99796 | [
"s615193737",
"s810549172"
]
|
u102461423 | p03003 | python | s166335576 | s314477350 | 292 | 266 | 43,684 | 14,424 | Accepted | Accepted | 8.9 | import numpy as np
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
N,M = list(map(int,input().split()))
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)
# (n,m) 以前で作れている列
dp = np.zeros((N+1, M+1), dtype = np.int64)
dp[0] = 1
for n in range(1, N+1):
same = (T == S[n-1])
dp[n,1:][same] = dp[n-1,:-1][same] # ちょうど(n,m)で終わる
dp[n] = (dp[n].cumsum() + dp[n-1]) % MOD # cumsumに直す
answer = dp[N,M]
print(answer)
| import numpy as np
MOD = 10**9 + 7
N,M = list(map(int,input().split()))
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)
# (n,m) 以前で作れている列
dp = np.ones(M+1, dtype = np.int64)
for n in range(N):
dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD # cumsumに直す
answer = dp[M]
print(answer) | 20 | 14 | 477 | 348 | import numpy as np
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)
# (n,m) 以前で作れている列
dp = np.zeros((N + 1, M + 1), dtype=np.int64)
dp[0] = 1
for n in range(1, N + 1):
same = T == S[n - 1]
dp[n, 1:][same] = dp[n - 1, :-1][same] # ちょうど(n,m)で終わる
dp[n] = (dp[n].cumsum() + dp[n - 1]) % MOD # cumsumに直す
answer = dp[N, M]
print(answer)
| import numpy as np
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)
# (n,m) 以前で作れている列
dp = np.ones(M + 1, dtype=np.int64)
for n in range(N):
dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD # cumsumに直す
answer = dp[M]
print(answer)
| false | 30 | [
"-import sys",
"-input = sys.stdin.readline",
"-dp = np.zeros((N + 1, M + 1), dtype=np.int64)",
"-dp[0] = 1",
"-for n in range(1, N + 1):",
"- same = T == S[n - 1]",
"- dp[n, 1:][same] = dp[n - 1, :-1][same] # ちょうど(n,m)で終わる",
"- dp[n] = (dp[n].cumsum() + dp[n - 1]) % MOD # cumsumに直す",
"-answer = dp[N, M]",
"+dp = np.ones(M + 1, dtype=np.int64)",
"+for n in range(N):",
"+ dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD # cumsumに直す",
"+answer = dp[M]"
]
| false | 0.212522 | 0.205323 | 1.035061 | [
"s166335576",
"s314477350"
]
|
u426534722 | p02271 | python | s824625525 | s655155562 | 460 | 20 | 5,724 | 5,660 | Accepted | Accepted | 95.65 | from itertools import combinations
n = int(eval(input()))
A = tuple(map(int, input().split()))
B = set(A)
for i in range(2, n + 1):
for C in combinations(A, i):
B.add(sum(C))
q = int(eval(input()))
for m in map(int, input().split()):
print(("yes" if m in B else "no"))
| n = int(eval(input()))
SET1 = {0}
for a in map(int, input().split()):
for b in tuple(SET1):
SET1.add(a + b)
eval(input())
for m in map(int, input().split()):
print(('yes' if m in SET1 else 'no'))
| 11 | 8 | 282 | 205 | from itertools import combinations
n = int(eval(input()))
A = tuple(map(int, input().split()))
B = set(A)
for i in range(2, n + 1):
for C in combinations(A, i):
B.add(sum(C))
q = int(eval(input()))
for m in map(int, input().split()):
print(("yes" if m in B else "no"))
| n = int(eval(input()))
SET1 = {0}
for a in map(int, input().split()):
for b in tuple(SET1):
SET1.add(a + b)
eval(input())
for m in map(int, input().split()):
print(("yes" if m in SET1 else "no"))
| false | 27.272727 | [
"-from itertools import combinations",
"-",
"-A = tuple(map(int, input().split()))",
"-B = set(A)",
"-for i in range(2, n + 1):",
"- for C in combinations(A, i):",
"- B.add(sum(C))",
"-q = int(eval(input()))",
"+SET1 = {0}",
"+for a in map(int, input().split()):",
"+ for b in tuple(SET1):",
"+ SET1.add(a + b)",
"+eval(input())",
"- print((\"yes\" if m in B else \"no\"))",
"+ print((\"yes\" if m in SET1 else \"no\"))"
]
| false | 0.08429 | 0.037965 | 2.220185 | [
"s824625525",
"s655155562"
]
|
u977389981 | p03244 | python | s419838699 | s276885089 | 106 | 90 | 21,084 | 20,692 | Accepted | Accepted | 15.09 | from collections import Counter
n = int(eval(input()))
A = [int(i) for i in input().split()]
A0 = []
A1 = []
for i in range(0, n, 2):
A0.append(A[i])
A1.append(A[i + 1])
C0 = Counter(A0).most_common()
C1 = Counter(A1).most_common()
if C0[0][0] != C1[0][0]:
ans = n - C0[0][1] - C1[0][1]
else:
if len(C0) == 1 and len(C1) == 1:
ans = n // 2
elif len(C0) != 1 and len(C1) != 1:
ans = min(n - C0[0][1] - C1[1][1], n - C0[1][1] - C1[0][1])
elif len(C0) != 1 and len(C1) == 1:
ans = n // 2 - C0[0][1]
else:
ans = n // 2 - C1[0][1]
print(ans) | from collections import Counter
n = int(eval(input()))
A = [int(i) for i in input().split()]
S = Counter(A[0::2]).most_common()
T = Counter(A[1::2]).most_common()
if S[0][0] != T[0][0]:
ans = n - S[0][1] - T[0][1]
elif S[0][0] == T[0][0]:
if len(S) == 1 and len(T) > 1:
ans = n // 2 - T[0][1]
elif len(S) > 1 and len(T) == 1:
ans = n // 2 - S[0][1]
elif len(S) > 1 and len(T) > 1:
ans = min(n - S[0][1] - T[1][1], n - S[1][1] - T[0][1])
else:
ans = n // 2
print(ans) | 26 | 20 | 631 | 542 | from collections import Counter
n = int(eval(input()))
A = [int(i) for i in input().split()]
A0 = []
A1 = []
for i in range(0, n, 2):
A0.append(A[i])
A1.append(A[i + 1])
C0 = Counter(A0).most_common()
C1 = Counter(A1).most_common()
if C0[0][0] != C1[0][0]:
ans = n - C0[0][1] - C1[0][1]
else:
if len(C0) == 1 and len(C1) == 1:
ans = n // 2
elif len(C0) != 1 and len(C1) != 1:
ans = min(n - C0[0][1] - C1[1][1], n - C0[1][1] - C1[0][1])
elif len(C0) != 1 and len(C1) == 1:
ans = n // 2 - C0[0][1]
else:
ans = n // 2 - C1[0][1]
print(ans)
| from collections import Counter
n = int(eval(input()))
A = [int(i) for i in input().split()]
S = Counter(A[0::2]).most_common()
T = Counter(A[1::2]).most_common()
if S[0][0] != T[0][0]:
ans = n - S[0][1] - T[0][1]
elif S[0][0] == T[0][0]:
if len(S) == 1 and len(T) > 1:
ans = n // 2 - T[0][1]
elif len(S) > 1 and len(T) == 1:
ans = n // 2 - S[0][1]
elif len(S) > 1 and len(T) > 1:
ans = min(n - S[0][1] - T[1][1], n - S[1][1] - T[0][1])
else:
ans = n // 2
print(ans)
| false | 23.076923 | [
"-A0 = []",
"-A1 = []",
"-for i in range(0, n, 2):",
"- A0.append(A[i])",
"- A1.append(A[i + 1])",
"-C0 = Counter(A0).most_common()",
"-C1 = Counter(A1).most_common()",
"-if C0[0][0] != C1[0][0]:",
"- ans = n - C0[0][1] - C1[0][1]",
"-else:",
"- if len(C0) == 1 and len(C1) == 1:",
"+S = Counter(A[0::2]).most_common()",
"+T = Counter(A[1::2]).most_common()",
"+if S[0][0] != T[0][0]:",
"+ ans = n - S[0][1] - T[0][1]",
"+elif S[0][0] == T[0][0]:",
"+ if len(S) == 1 and len(T) > 1:",
"+ ans = n // 2 - T[0][1]",
"+ elif len(S) > 1 and len(T) == 1:",
"+ ans = n // 2 - S[0][1]",
"+ elif len(S) > 1 and len(T) > 1:",
"+ ans = min(n - S[0][1] - T[1][1], n - S[1][1] - T[0][1])",
"+ else:",
"- elif len(C0) != 1 and len(C1) != 1:",
"- ans = min(n - C0[0][1] - C1[1][1], n - C0[1][1] - C1[0][1])",
"- elif len(C0) != 1 and len(C1) == 1:",
"- ans = n // 2 - C0[0][1]",
"- else:",
"- ans = n // 2 - C1[0][1]"
]
| false | 0.046454 | 0.042565 | 1.091363 | [
"s419838699",
"s276885089"
]
|
u724687935 | p03087 | python | s922054176 | s815334737 | 651 | 438 | 55,128 | 60,020 | Accepted | Accepted | 32.72 | N, Q = list(map(int, input().split()))
S = eval(input())
AC = [0] * N
flag = 0
for i, s in enumerate(S):
if s == 'C':
if flag == 1:
AC[i] = AC[i - 1] + 1
flag = 0
else:
AC[i] = AC[i - 1]
flag = 0
elif s == 'A':
AC[i] = AC[i - 1]
flag = 1
else:
AC[i] = AC[i - 1]
flag = 0
ans = [0] * Q
for q in range(Q):
l, r = [int(x) - 1 for x in input().split()]
ans[q] = AC[r] - AC[l]
for q in range(Q):
print((ans[q]))
| import sys
N, Q = list(map(int, input().split()))
S = eval(input())
AC = [0] * N
for i in range(1, N):
a = 0
if S[i - 1] == 'A' and S[i] == 'C':
a = 1
AC[i] = AC[i - 1] + a
LR = [list(map(int, x.split())) for x in sys.stdin.readlines()]
for l, r in LR:
print((AC[r - 1] - AC[l - 1]))
| 29 | 18 | 551 | 311 | N, Q = list(map(int, input().split()))
S = eval(input())
AC = [0] * N
flag = 0
for i, s in enumerate(S):
if s == "C":
if flag == 1:
AC[i] = AC[i - 1] + 1
flag = 0
else:
AC[i] = AC[i - 1]
flag = 0
elif s == "A":
AC[i] = AC[i - 1]
flag = 1
else:
AC[i] = AC[i - 1]
flag = 0
ans = [0] * Q
for q in range(Q):
l, r = [int(x) - 1 for x in input().split()]
ans[q] = AC[r] - AC[l]
for q in range(Q):
print((ans[q]))
| import sys
N, Q = list(map(int, input().split()))
S = eval(input())
AC = [0] * N
for i in range(1, N):
a = 0
if S[i - 1] == "A" and S[i] == "C":
a = 1
AC[i] = AC[i - 1] + a
LR = [list(map(int, x.split())) for x in sys.stdin.readlines()]
for l, r in LR:
print((AC[r - 1] - AC[l - 1]))
| false | 37.931034 | [
"+import sys",
"+",
"-flag = 0",
"-for i, s in enumerate(S):",
"- if s == \"C\":",
"- if flag == 1:",
"- AC[i] = AC[i - 1] + 1",
"- flag = 0",
"- else:",
"- AC[i] = AC[i - 1]",
"- flag = 0",
"- elif s == \"A\":",
"- AC[i] = AC[i - 1]",
"- flag = 1",
"- else:",
"- AC[i] = AC[i - 1]",
"- flag = 0",
"-ans = [0] * Q",
"-for q in range(Q):",
"- l, r = [int(x) - 1 for x in input().split()]",
"- ans[q] = AC[r] - AC[l]",
"-for q in range(Q):",
"- print((ans[q]))",
"+for i in range(1, N):",
"+ a = 0",
"+ if S[i - 1] == \"A\" and S[i] == \"C\":",
"+ a = 1",
"+ AC[i] = AC[i - 1] + a",
"+LR = [list(map(int, x.split())) for x in sys.stdin.readlines()]",
"+for l, r in LR:",
"+ print((AC[r - 1] - AC[l - 1]))"
]
| false | 0.083233 | 0.037187 | 2.238221 | [
"s922054176",
"s815334737"
]
|
u997641430 | p02787 | python | s899988488 | s452697432 | 380 | 345 | 41,452 | 41,068 | Accepted | Accepted | 9.21 | inf = 10**9
H, N = list(map(int, input().split()))
AB = []
for n in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort(reverse=True, key=lambda x: x[0])
dp = [inf] * (H + 10 ** 4)
dp[0] = 0
for a, b in AB:
for h in range(H):
if dp[h] != inf:
tmp = dp[h] + b
if tmp < dp[h + a]:
dp[h + a] = tmp
print((min(dp[H:])))
| import sys
input = sys.stdin.readline
inf = 10**9
H, N = list(map(int, input().split()))
AB = []
for n in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort(reverse=True, key=lambda x: x[0])
dp = [inf] * (H + 10 ** 4)
dp[0] = 0
for a, b in AB:
for h in range(H):
if dp[h] != inf:
tmp = dp[h] + b
if tmp < dp[h + a]:
dp[h + a] = tmp
print((min(dp[H:])))
| 16 | 18 | 400 | 440 | inf = 10**9
H, N = list(map(int, input().split()))
AB = []
for n in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort(reverse=True, key=lambda x: x[0])
dp = [inf] * (H + 10**4)
dp[0] = 0
for a, b in AB:
for h in range(H):
if dp[h] != inf:
tmp = dp[h] + b
if tmp < dp[h + a]:
dp[h + a] = tmp
print((min(dp[H:])))
| import sys
input = sys.stdin.readline
inf = 10**9
H, N = list(map(int, input().split()))
AB = []
for n in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort(reverse=True, key=lambda x: x[0])
dp = [inf] * (H + 10**4)
dp[0] = 0
for a, b in AB:
for h in range(H):
if dp[h] != inf:
tmp = dp[h] + b
if tmp < dp[h + a]:
dp[h + a] = tmp
print((min(dp[H:])))
| false | 11.111111 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
]
| false | 0.049812 | 0.055361 | 0.899762 | [
"s899988488",
"s452697432"
]
|
u460386402 | p02802 | python | s577503324 | s510392681 | 364 | 288 | 4,596 | 4,596 | Accepted | Accepted | 20.88 | n,m=list(map(int,input().split()))
acount=0
wcount=0
a=[0]*n
w=[0]*n
for i in range(m):
p,m=list(map(str,input().split()))
p=int(p)
if m=="AC":
if a[p-1]==0:
acount+=1
a[p-1]+=1
else:
if a[p-1]==0:
w[p-1]+=1
for i in range(n):
if a[i-1]==1:
wcount+=w[i-1]
print((acount,wcount)) | n,m=list(map(int,input().split()))
acount=0
wcount=0
a=[False]*n
w=[0]*n
for i in range(m):
p,m=input().split()
p=int(p)
if m=="AC":
if a[p-1]==False:
acount+=1
a[p-1]=True
else:
if a[p-1]==False:
w[p-1]+=1
for i in range(n):
if a[i-1]==1:
wcount+=w[i-1]
print((acount,wcount)) | 21 | 21 | 336 | 341 | n, m = list(map(int, input().split()))
acount = 0
wcount = 0
a = [0] * n
w = [0] * n
for i in range(m):
p, m = list(map(str, input().split()))
p = int(p)
if m == "AC":
if a[p - 1] == 0:
acount += 1
a[p - 1] += 1
else:
if a[p - 1] == 0:
w[p - 1] += 1
for i in range(n):
if a[i - 1] == 1:
wcount += w[i - 1]
print((acount, wcount))
| n, m = list(map(int, input().split()))
acount = 0
wcount = 0
a = [False] * n
w = [0] * n
for i in range(m):
p, m = input().split()
p = int(p)
if m == "AC":
if a[p - 1] == False:
acount += 1
a[p - 1] = True
else:
if a[p - 1] == False:
w[p - 1] += 1
for i in range(n):
if a[i - 1] == 1:
wcount += w[i - 1]
print((acount, wcount))
| false | 0 | [
"-a = [0] * n",
"+a = [False] * n",
"- p, m = list(map(str, input().split()))",
"+ p, m = input().split()",
"- if a[p - 1] == 0:",
"+ if a[p - 1] == False:",
"- a[p - 1] += 1",
"+ a[p - 1] = True",
"- if a[p - 1] == 0:",
"+ if a[p - 1] == False:"
]
| false | 0.037157 | 0.061446 | 0.604711 | [
"s577503324",
"s510392681"
]
|
u729133443 | p03792 | python | s543756421 | s872434897 | 55 | 33 | 3,316 | 5,236 | Accepted | Accepted | 40 | s='#';n,*a=open(0).readlines();n=int(n);f=sum(n==t.count(s)for t in zip(*a));r=list(range(n));print((-all(not s in t for t in a)or min(n*2-f-a[i].count(s)+all(s<a[j][i]for j in r)for i in r))) | n,*a=open(0).readlines();n=int(n);*b,=list(zip(*a));f,e=[sum(n==t.count(c)for t in b)for c in'#.'];print((-(e==n)or min(n*2-f-a[i].count('#')+(not'#'in b[i])for i in range(n)))) | 1 | 1 | 184 | 169 | s = "#"
n, *a = open(0).readlines()
n = int(n)
f = sum(n == t.count(s) for t in zip(*a))
r = list(range(n))
print(
(
-all(not s in t for t in a)
or min(n * 2 - f - a[i].count(s) + all(s < a[j][i] for j in r) for i in r)
)
)
| n, *a = open(0).readlines()
n = int(n)
(*b,) = list(zip(*a))
f, e = [sum(n == t.count(c) for t in b) for c in "#."]
print(
(
-(e == n)
or min(n * 2 - f - a[i].count("#") + (not "#" in b[i]) for i in range(n))
)
)
| false | 0 | [
"-s = \"#\"",
"-f = sum(n == t.count(s) for t in zip(*a))",
"-r = list(range(n))",
"+(*b,) = list(zip(*a))",
"+f, e = [sum(n == t.count(c) for t in b) for c in \"#.\"]",
"- -all(not s in t for t in a)",
"- or min(n * 2 - f - a[i].count(s) + all(s < a[j][i] for j in r) for i in r)",
"+ -(e == n)",
"+ or min(n * 2 - f - a[i].count(\"#\") + (not \"#\" in b[i]) for i in range(n))"
]
| false | 0.044096 | 0.042049 | 1.048675 | [
"s543756421",
"s872434897"
]
|
u864197622 | p03395 | python | s609292803 | s024836497 | 152 | 67 | 3,572 | 3,564 | Accepted | Accepted | 55.92 | from heapq import heapify, heappush as hpush, heappop as hpop
def dijkstra(n, E, i0=0):
h = [[0, i0]]
D = [-1] * n
done = [0] * n
D[i0] = 0
while h:
d, i = hpop(h)
done[i] = 1
for j, w in E[i]:
nd = d + w
if D[j] < 0 or D[j] >= nd:
if done[j] == 0:
hpush(h, [nd, j])
D[j] = nd
return D
N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
M = 51
X = [[] for _ in range(M)]
for i in range(1, M):
for j in range(1, i+1):
X[i].append([i%j, 2**j])
def chk(S):
M = 51
X = [[] for _ in range(M)]
for j in S:
for i in range(j, M):
X[i].append([i%j, 2**j])
DI = []
for i in range(M):
DI.append(dijkstra(M, X, i))
for i in range(N):
if DI[A[i]][B[i]] < 0:
return 0
return 1
L1 = [i for i in range(1, 51)]
L2 = []
if chk(L1) == 0:
print((-1))
else:
while L1:
while True:
if chk(L1 + L2):
if len(L1) == 0:
break
L1.pop()
else:
L2.append(L1[-1]+1 if L1 else 1)
L1 = [i for i in range(1, L2[-1])]
break
if len(L1) == 0:
break
print((sum([1<<l for l in L2])))
| from collections import deque
def BFS_dist(n, E, i0=0):
Q = deque([i0])
D = [-1] * n
D[i0] = 0
while Q:
x = Q.popleft()
for c in E[x]:
if D[c] == -1:
D[c] = D[x] + 1
Q.append(c)
return D
N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
M = 51
X = [[] for _ in range(M)]
for i in range(1, M):
for j in range(1, i+1):
X[i].append([i%j, 2**j])
def chk(S):
M = 51
X = [[] for _ in range(M)]
for j in S:
for i in range(j, M):
X[i].append(i%j)
DI = []
for i in range(M):
DI.append(BFS_dist(M, X, i))
for i in range(N):
if DI[A[i]][B[i]] < 0:
return 0
return 1
L1 = [i for i in range(1, 51)]
L2 = []
if chk(L1) == 0:
print((-1))
else:
while L1:
while True:
if chk(L1 + L2):
if len(L1) == 0:
break
L1.pop()
else:
L2.append(L1[-1]+1 if L1 else 1)
L1 = [i for i in range(1, L2[-1])]
break
if len(L1) == 0:
break
print((sum([1<<l for l in L2])))
| 61 | 56 | 1,432 | 1,267 | from heapq import heapify, heappush as hpush, heappop as hpop
def dijkstra(n, E, i0=0):
h = [[0, i0]]
D = [-1] * n
done = [0] * n
D[i0] = 0
while h:
d, i = hpop(h)
done[i] = 1
for j, w in E[i]:
nd = d + w
if D[j] < 0 or D[j] >= nd:
if done[j] == 0:
hpush(h, [nd, j])
D[j] = nd
return D
N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
M = 51
X = [[] for _ in range(M)]
for i in range(1, M):
for j in range(1, i + 1):
X[i].append([i % j, 2**j])
def chk(S):
M = 51
X = [[] for _ in range(M)]
for j in S:
for i in range(j, M):
X[i].append([i % j, 2**j])
DI = []
for i in range(M):
DI.append(dijkstra(M, X, i))
for i in range(N):
if DI[A[i]][B[i]] < 0:
return 0
return 1
L1 = [i for i in range(1, 51)]
L2 = []
if chk(L1) == 0:
print((-1))
else:
while L1:
while True:
if chk(L1 + L2):
if len(L1) == 0:
break
L1.pop()
else:
L2.append(L1[-1] + 1 if L1 else 1)
L1 = [i for i in range(1, L2[-1])]
break
if len(L1) == 0:
break
print((sum([1 << l for l in L2])))
| from collections import deque
def BFS_dist(n, E, i0=0):
Q = deque([i0])
D = [-1] * n
D[i0] = 0
while Q:
x = Q.popleft()
for c in E[x]:
if D[c] == -1:
D[c] = D[x] + 1
Q.append(c)
return D
N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
M = 51
X = [[] for _ in range(M)]
for i in range(1, M):
for j in range(1, i + 1):
X[i].append([i % j, 2**j])
def chk(S):
M = 51
X = [[] for _ in range(M)]
for j in S:
for i in range(j, M):
X[i].append(i % j)
DI = []
for i in range(M):
DI.append(BFS_dist(M, X, i))
for i in range(N):
if DI[A[i]][B[i]] < 0:
return 0
return 1
L1 = [i for i in range(1, 51)]
L2 = []
if chk(L1) == 0:
print((-1))
else:
while L1:
while True:
if chk(L1 + L2):
if len(L1) == 0:
break
L1.pop()
else:
L2.append(L1[-1] + 1 if L1 else 1)
L1 = [i for i in range(1, L2[-1])]
break
if len(L1) == 0:
break
print((sum([1 << l for l in L2])))
| false | 8.196721 | [
"-from heapq import heapify, heappush as hpush, heappop as hpop",
"+from collections import deque",
"-def dijkstra(n, E, i0=0):",
"- h = [[0, i0]]",
"+def BFS_dist(n, E, i0=0):",
"+ Q = deque([i0])",
"- done = [0] * n",
"- while h:",
"- d, i = hpop(h)",
"- done[i] = 1",
"- for j, w in E[i]:",
"- nd = d + w",
"- if D[j] < 0 or D[j] >= nd:",
"- if done[j] == 0:",
"- hpush(h, [nd, j])",
"- D[j] = nd",
"+ while Q:",
"+ x = Q.popleft()",
"+ for c in E[x]:",
"+ if D[c] == -1:",
"+ D[c] = D[x] + 1",
"+ Q.append(c)",
"- X[i].append([i % j, 2**j])",
"+ X[i].append(i % j)",
"- DI.append(dijkstra(M, X, i))",
"+ DI.append(BFS_dist(M, X, i))"
]
| false | 0.121389 | 0.139509 | 0.870118 | [
"s609292803",
"s024836497"
]
|
u980503157 | p03852 | python | s302951454 | s311091412 | 29 | 26 | 8,996 | 9,028 | Accepted | Accepted | 10.34 | letter = eval(input())
if letter in "aeiou":
print("vowel")
else:
print("consonant") | s = eval(input())
if s in "aeiou":
print("vowel")
else:
print("consonant") | 6 | 6 | 88 | 78 | letter = eval(input())
if letter in "aeiou":
print("vowel")
else:
print("consonant")
| s = eval(input())
if s in "aeiou":
print("vowel")
else:
print("consonant")
| false | 0 | [
"-letter = eval(input())",
"-if letter in \"aeiou\":",
"+s = eval(input())",
"+if s in \"aeiou\":"
]
| false | 0.03877 | 0.038965 | 0.994976 | [
"s302951454",
"s311091412"
]
|
u057964173 | p03073 | python | s184819997 | s735179744 | 76 | 47 | 5,476 | 3,316 | Accepted | Accepted | 38.16 | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
s=eval(input())
x=len(s)//2
l1=[1,0]*x+[1]
l2=[0,1]*x+[0]
cnt1=0
cnt2=0
for i in range(len(s)):
if s[i]!=str(l1[i]):
cnt1+=1
if s[i]!=str(l2[i]):
cnt2+=1
print((min(cnt1,cnt2)))
resolve() | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
s=eval(input())
x=len(s)//2
l1='10'*x+'1'
l2='01'*x+'0'
cnt1=0
cnt2=0
for i in range(len(s)):
if s[i]!=l1[i]:
cnt1+=1
if s[i]!=l2[i]:
cnt2+=1
print((min(cnt1,cnt2)))
resolve() | 17 | 17 | 343 | 331 | import sys
def input():
return sys.stdin.readline().strip()
def resolve():
s = eval(input())
x = len(s) // 2
l1 = [1, 0] * x + [1]
l2 = [0, 1] * x + [0]
cnt1 = 0
cnt2 = 0
for i in range(len(s)):
if s[i] != str(l1[i]):
cnt1 += 1
if s[i] != str(l2[i]):
cnt2 += 1
print((min(cnt1, cnt2)))
resolve()
| import sys
def input():
return sys.stdin.readline().strip()
def resolve():
s = eval(input())
x = len(s) // 2
l1 = "10" * x + "1"
l2 = "01" * x + "0"
cnt1 = 0
cnt2 = 0
for i in range(len(s)):
if s[i] != l1[i]:
cnt1 += 1
if s[i] != l2[i]:
cnt2 += 1
print((min(cnt1, cnt2)))
resolve()
| false | 0 | [
"- l1 = [1, 0] * x + [1]",
"- l2 = [0, 1] * x + [0]",
"+ l1 = \"10\" * x + \"1\"",
"+ l2 = \"01\" * x + \"0\"",
"- if s[i] != str(l1[i]):",
"+ if s[i] != l1[i]:",
"- if s[i] != str(l2[i]):",
"+ if s[i] != l2[i]:"
]
| false | 0.041299 | 0.041491 | 0.995359 | [
"s184819997",
"s735179744"
]
|
u754022296 | p03603 | python | s291733712 | s938123317 | 1,546 | 210 | 25,096 | 34,156 | Accepted | Accepted | 86.42 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 2**30
n = int(eval(input()))
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
T[p-1].append(i)
X = tuple(map(int, input().split()))
D = [-1]*n
def dfs(v):
if D[v] != -1:
return D[v]
l = len(T[v])
x = X[v]
dp = [INF]*(x+1)
dp[0] = 0
for nv in T[v]:
k = [INF]*(x+1)
d = dfs(nv)
for j in range(x+1):
if j >= X[nv]:
k[j] = min(k[j], dp[j-X[nv]]+d)
if j >= d:
k[j] = min(k[j], dp[j-d]+X[nv])
dp = tuple(k)
res = min(dp)
D[v] = res
return res
ans = dfs(0)
if ans == INF:
print("IMPOSSIBLE")
else:
print("POSSIBLE") | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import numpy as np
INF = 2**30
n = int(eval(input()))
P = tuple(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
T[p-1].append(i)
X = tuple(map(int, input().split()))
D = [-1]*n
def dfs(v):
if D[v] != -1:
return D[v]
l = len(T[v])
x = X[v]
dp = np.full(x+1, INF, dtype=np.int64)
dp[0] = 0
for i, nv in enumerate(T[v]):
k = np.full(x+1, INF, dtype=np.int64)
d = dfs(nv)
if x+1 >= X[nv]:
np.minimum(k[X[nv]:], dp[:x+1-X[nv]]+d, out=k[X[nv]:])
if x+1 >= d:
np.minimum(k[d:], dp[:x+1-d]+X[nv], out=k[d:])
dp = k.copy()
res = dp.min()
D[v] = res
return res
ans = dfs(0)
if ans == INF:
print("IMPOSSIBLE")
else:
print("POSSIBLE") | 36 | 36 | 726 | 814 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 2**30
n = int(eval(input()))
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
T[p - 1].append(i)
X = tuple(map(int, input().split()))
D = [-1] * n
def dfs(v):
if D[v] != -1:
return D[v]
l = len(T[v])
x = X[v]
dp = [INF] * (x + 1)
dp[0] = 0
for nv in T[v]:
k = [INF] * (x + 1)
d = dfs(nv)
for j in range(x + 1):
if j >= X[nv]:
k[j] = min(k[j], dp[j - X[nv]] + d)
if j >= d:
k[j] = min(k[j], dp[j - d] + X[nv])
dp = tuple(k)
res = min(dp)
D[v] = res
return res
ans = dfs(0)
if ans == INF:
print("IMPOSSIBLE")
else:
print("POSSIBLE")
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import numpy as np
INF = 2**30
n = int(eval(input()))
P = tuple(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
T[p - 1].append(i)
X = tuple(map(int, input().split()))
D = [-1] * n
def dfs(v):
if D[v] != -1:
return D[v]
l = len(T[v])
x = X[v]
dp = np.full(x + 1, INF, dtype=np.int64)
dp[0] = 0
for i, nv in enumerate(T[v]):
k = np.full(x + 1, INF, dtype=np.int64)
d = dfs(nv)
if x + 1 >= X[nv]:
np.minimum(k[X[nv] :], dp[: x + 1 - X[nv]] + d, out=k[X[nv] :])
if x + 1 >= d:
np.minimum(k[d:], dp[: x + 1 - d] + X[nv], out=k[d:])
dp = k.copy()
res = dp.min()
D[v] = res
return res
ans = dfs(0)
if ans == INF:
print("IMPOSSIBLE")
else:
print("POSSIBLE")
| false | 0 | [
"+import numpy as np",
"+",
"-P = list(map(int, input().split()))",
"+P = tuple(map(int, input().split()))",
"- dp = [INF] * (x + 1)",
"+ dp = np.full(x + 1, INF, dtype=np.int64)",
"- for nv in T[v]:",
"- k = [INF] * (x + 1)",
"+ for i, nv in enumerate(T[v]):",
"+ k = np.full(x + 1, INF, dtype=np.int64)",
"- for j in range(x + 1):",
"- if j >= X[nv]:",
"- k[j] = min(k[j], dp[j - X[nv]] + d)",
"- if j >= d:",
"- k[j] = min(k[j], dp[j - d] + X[nv])",
"- dp = tuple(k)",
"- res = min(dp)",
"+ if x + 1 >= X[nv]:",
"+ np.minimum(k[X[nv] :], dp[: x + 1 - X[nv]] + d, out=k[X[nv] :])",
"+ if x + 1 >= d:",
"+ np.minimum(k[d:], dp[: x + 1 - d] + X[nv], out=k[d:])",
"+ dp = k.copy()",
"+ res = dp.min()"
]
| false | 0.04644 | 0.209553 | 0.221614 | [
"s291733712",
"s938123317"
]
|
u451017206 | p03229 | python | s387010472 | s552176536 | 302 | 223 | 12,600 | 10,504 | Accepted | Accepted | 26.16 | N = int(eval(input()))
A = sorted([int(eval(input())) for i in range(N)])
a = [0] * N
b = [0] * N
j = 1
for i in range(N-1):
a[i] += -j
a[i+1] += j
b[i] += j
b[i+1] += -j
j = -j
a.sort()
b.sort()
s1 = sum([i*j for i,j in zip(a, A)])
s2 = sum([i*j for i,j in zip(b, A)])
print((max(s1,s2))) | from sys import stdin
from collections import deque
N = int(stdin.readline())
A = sorted([int(stdin.readline()) for i in range(N)])
ans1 = deque([A[N-1]])
ans2 = deque([A[0]])
f = 0
f2 = 1
b = N - 2
b2 = N - 1
s = True
while f <= b:
if s:
ans1.append(A[f])
f += 1
if f <= b:
ans1.appendleft(A[f])
f += 1
ans2.append(A[b2])
b2 -= 1
if f2 <= b2:
ans2.appendleft(A[b2])
b2 -= 1
else:
ans1.append(A[b])
b -= 1
if f <= b:
ans1.appendleft(A[b])
b -= 1
ans2.append(A[f2])
f2 += 1
if f2 <= b2:
ans2.appendleft(A[f2])
f2 += 1
s = not s
a1 = a2 = 0
ans1 = list(ans1)
ans2 = list(ans2)
for i in range(N-1):
a1 += abs(ans1[i] - ans1[i+1])
a2 += abs(ans2[i] - ans2[i+1])
print((max(a1, a2))) | 19 | 46 | 324 | 937 | N = int(eval(input()))
A = sorted([int(eval(input())) for i in range(N)])
a = [0] * N
b = [0] * N
j = 1
for i in range(N - 1):
a[i] += -j
a[i + 1] += j
b[i] += j
b[i + 1] += -j
j = -j
a.sort()
b.sort()
s1 = sum([i * j for i, j in zip(a, A)])
s2 = sum([i * j for i, j in zip(b, A)])
print((max(s1, s2)))
| from sys import stdin
from collections import deque
N = int(stdin.readline())
A = sorted([int(stdin.readline()) for i in range(N)])
ans1 = deque([A[N - 1]])
ans2 = deque([A[0]])
f = 0
f2 = 1
b = N - 2
b2 = N - 1
s = True
while f <= b:
if s:
ans1.append(A[f])
f += 1
if f <= b:
ans1.appendleft(A[f])
f += 1
ans2.append(A[b2])
b2 -= 1
if f2 <= b2:
ans2.appendleft(A[b2])
b2 -= 1
else:
ans1.append(A[b])
b -= 1
if f <= b:
ans1.appendleft(A[b])
b -= 1
ans2.append(A[f2])
f2 += 1
if f2 <= b2:
ans2.appendleft(A[f2])
f2 += 1
s = not s
a1 = a2 = 0
ans1 = list(ans1)
ans2 = list(ans2)
for i in range(N - 1):
a1 += abs(ans1[i] - ans1[i + 1])
a2 += abs(ans2[i] - ans2[i + 1])
print((max(a1, a2)))
| false | 58.695652 | [
"-N = int(eval(input()))",
"-A = sorted([int(eval(input())) for i in range(N)])",
"-a = [0] * N",
"-b = [0] * N",
"-j = 1",
"+from sys import stdin",
"+from collections import deque",
"+",
"+N = int(stdin.readline())",
"+A = sorted([int(stdin.readline()) for i in range(N)])",
"+ans1 = deque([A[N - 1]])",
"+ans2 = deque([A[0]])",
"+f = 0",
"+f2 = 1",
"+b = N - 2",
"+b2 = N - 1",
"+s = True",
"+while f <= b:",
"+ if s:",
"+ ans1.append(A[f])",
"+ f += 1",
"+ if f <= b:",
"+ ans1.appendleft(A[f])",
"+ f += 1",
"+ ans2.append(A[b2])",
"+ b2 -= 1",
"+ if f2 <= b2:",
"+ ans2.appendleft(A[b2])",
"+ b2 -= 1",
"+ else:",
"+ ans1.append(A[b])",
"+ b -= 1",
"+ if f <= b:",
"+ ans1.appendleft(A[b])",
"+ b -= 1",
"+ ans2.append(A[f2])",
"+ f2 += 1",
"+ if f2 <= b2:",
"+ ans2.appendleft(A[f2])",
"+ f2 += 1",
"+ s = not s",
"+a1 = a2 = 0",
"+ans1 = list(ans1)",
"+ans2 = list(ans2)",
"- a[i] += -j",
"- a[i + 1] += j",
"- b[i] += j",
"- b[i + 1] += -j",
"- j = -j",
"-a.sort()",
"-b.sort()",
"-s1 = sum([i * j for i, j in zip(a, A)])",
"-s2 = sum([i * j for i, j in zip(b, A)])",
"-print((max(s1, s2)))",
"+ a1 += abs(ans1[i] - ans1[i + 1])",
"+ a2 += abs(ans2[i] - ans2[i + 1])",
"+print((max(a1, a2)))"
]
| false | 0.084782 | 0.076657 | 1.106001 | [
"s387010472",
"s552176536"
]
|
u729133443 | p03700 | python | s058010248 | s363707475 | 628 | 230 | 26,668 | 24,568 | Accepted | Accepted | 63.38 | from numpy import*
t,*h=open(0)
_,a,b=int32(t.split())
i,j=0,2**30
while~i+j:
k=(j+i)//2;t=(b*k-int32(h))//(a-b)
if-k>sum(t[t<0]):i=k
else:j=k
print(j) | from numpy import*
t,*h=open(0)
_,a,b=int32(t.split())
h=int32(h)
i,j=0,2**30
while~i+j:
k=(j+i)//2
t=(b*k-h)//(a-b)
if-k>sum(t[t<0]):i=k
else:j=k
print(j) | 9 | 11 | 162 | 173 | from numpy import *
t, *h = open(0)
_, a, b = int32(t.split())
i, j = 0, 2**30
while ~i + j:
k = (j + i) // 2
t = (b * k - int32(h)) // (a - b)
if -k > sum(t[t < 0]):
i = k
else:
j = k
print(j)
| from numpy import *
t, *h = open(0)
_, a, b = int32(t.split())
h = int32(h)
i, j = 0, 2**30
while ~i + j:
k = (j + i) // 2
t = (b * k - h) // (a - b)
if -k > sum(t[t < 0]):
i = k
else:
j = k
print(j)
| false | 18.181818 | [
"+h = int32(h)",
"- t = (b * k - int32(h)) // (a - b)",
"+ t = (b * k - h) // (a - b)"
]
| false | 0.200057 | 0.174724 | 1.144986 | [
"s058010248",
"s363707475"
]
|
u219197917 | p03043 | python | s770092766 | s247330346 | 85 | 59 | 2,940 | 9,132 | Accepted | Accepted | 30.59 | n, k = [int(i) for i in input().split()]
win = 0
for i in range(1, n + 1):
for j in range(k):
if i * 2 ** j >= k:
win += 0.5 ** j / n
break
print(win) | from math import ceil, log2
n, k = list(map(int, input().split()))
print((sum(0.5 ** max(ceil(log2(k / i)), 0) for i in range(1, n + 1)) / n))
| 8 | 4 | 175 | 139 | n, k = [int(i) for i in input().split()]
win = 0
for i in range(1, n + 1):
for j in range(k):
if i * 2**j >= k:
win += 0.5**j / n
break
print(win)
| from math import ceil, log2
n, k = list(map(int, input().split()))
print((sum(0.5 ** max(ceil(log2(k / i)), 0) for i in range(1, n + 1)) / n))
| false | 50 | [
"-n, k = [int(i) for i in input().split()]",
"-win = 0",
"-for i in range(1, n + 1):",
"- for j in range(k):",
"- if i * 2**j >= k:",
"- win += 0.5**j / n",
"- break",
"-print(win)",
"+from math import ceil, log2",
"+",
"+n, k = list(map(int, input().split()))",
"+print((sum(0.5 ** max(ceil(log2(k / i)), 0) for i in range(1, n + 1)) / n))"
]
| false | 0.102634 | 0.077389 | 1.326211 | [
"s770092766",
"s247330346"
]
|
u225388820 | p03166 | python | s651400245 | s077462284 | 393 | 289 | 194,100 | 118,100 | Accepted | Accepted | 26.46 | # 根付き木に対して根から最大でどれだけかかるかを使う方法
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(m):
a, b = list(map(int, input().split()))
co[b - 1].append(a - 1)
dp = [-1] * n
def memo(v):
if dp[v] != -1: #更新済
return dp[v]
for i in co[v]:
x = memo(i) + 1
if x > dp[v]:
parent[v] = i + 1
dp[v] = x
return max(dp[v], 0)
# 経路復元
parent = [0] * n
ans = 0
for i in range(n):
ans = max(ans, memo(i))
print(ans) | #解説AC
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n,m=list(map(int,input().split()))
es=[[] for i in range(n)]
for i in range(m):
x,y=list(map(int,input().split()))
es[x-1].append(y-1)
dp=[-1]*n
def memo(v):
if dp[v]+1: #更新済 dp[v]!=-1
return dp[v]
a=0
for i in es[v]:
a=max(a,memo(i)+1)
dp[v]=a
return a
ans=0
for i in range(n):
ans=max(ans,memo(i))
print(ans)
| 33 | 28 | 610 | 458 | # 根付き木に対して根から最大でどれだけかかるかを使う方法
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(m):
a, b = list(map(int, input().split()))
co[b - 1].append(a - 1)
dp = [-1] * n
def memo(v):
if dp[v] != -1: # 更新済
return dp[v]
for i in co[v]:
x = memo(i) + 1
if x > dp[v]:
parent[v] = i + 1
dp[v] = x
return max(dp[v], 0)
# 経路復元
parent = [0] * n
ans = 0
for i in range(n):
ans = max(ans, memo(i))
print(ans)
| # 解説AC
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
es = [[] for i in range(n)]
for i in range(m):
x, y = list(map(int, input().split()))
es[x - 1].append(y - 1)
dp = [-1] * n
def memo(v):
if dp[v] + 1: # 更新済 dp[v]!=-1
return dp[v]
a = 0
for i in es[v]:
a = max(a, memo(i) + 1)
dp[v] = a
return a
ans = 0
for i in range(n):
ans = max(ans, memo(i))
print(ans)
| false | 15.151515 | [
"-# 根付き木に対して根から最大でどれだけかかるかを使う方法",
"+# 解説AC",
"-co = [[] for i in range(n)] # 有効辺の向きを逆にした",
"+es = [[] for i in range(n)]",
"- a, b = list(map(int, input().split()))",
"- co[b - 1].append(a - 1)",
"+ x, y = list(map(int, input().split()))",
"+ es[x - 1].append(y - 1)",
"- if dp[v] != -1: # 更新済",
"+ if dp[v] + 1: # 更新済 dp[v]!=-1",
"- for i in co[v]:",
"- x = memo(i) + 1",
"- if x > dp[v]:",
"- parent[v] = i + 1",
"- dp[v] = x",
"- return max(dp[v], 0)",
"+ a = 0",
"+ for i in es[v]:",
"+ a = max(a, memo(i) + 1)",
"+ dp[v] = a",
"+ return a",
"-# 経路復元",
"-parent = [0] * n"
]
| false | 0.082443 | 0.063534 | 1.297634 | [
"s651400245",
"s077462284"
]
|
u446774692 | p03722 | python | s445742115 | s301301561 | 1,762 | 1,302 | 5,612 | 3,572 | Accepted | Accepted | 26.11 | N,M = list(map(int,input().split()))
from collections import deque
ls = [deque([]) for _ in range(N)]
for i in range(M):
a,b,c = list(map(int,input().split()))
a,b = a-1,b-1
ls[a].append([b,c])
cost = [-(10**10)*N]*N
cost[0] = 0
for i in range(N):
update = False
q = [deque(m for m in l) for l in ls]
for j in range(N):
if cost[j] != -(10**10)*N:
while q[j]:
b,c = q[j].pop()
if cost[b] < cost[j] + c:
cost[b] = cost[j] + c
update = True
if i == 0:
Max = cost[N-1]
elif i < N-1:
Max = max(Max,cost[N-1])
if update == True and Max < cost[N-1]:
print('inf')
else:
print(Max)
| N,M = list(map(int,input().split()))
abc = []
for _ in range(M):
abc.append(list(map(int,input().split())))
cost = [-(10**10)*N]*N
cost[0] = 0
for i in range(N):
update = False
for a,b,c in abc:
a,b = a-1,b-1
if cost[a] != -(10**10)*N:
if cost[b] < cost[a] + c:
cost[b] = cost[a] + c
update = True
if i == 0:
Max = cost[N-1]
elif i < N-1:
Max = max(Max,cost[N-1])
if update == True and Max < cost[N-1]:
print('inf')
else:
print(Max)
| 31 | 26 | 743 | 560 | N, M = list(map(int, input().split()))
from collections import deque
ls = [deque([]) for _ in range(N)]
for i in range(M):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
ls[a].append([b, c])
cost = [-(10**10) * N] * N
cost[0] = 0
for i in range(N):
update = False
q = [deque(m for m in l) for l in ls]
for j in range(N):
if cost[j] != -(10**10) * N:
while q[j]:
b, c = q[j].pop()
if cost[b] < cost[j] + c:
cost[b] = cost[j] + c
update = True
if i == 0:
Max = cost[N - 1]
elif i < N - 1:
Max = max(Max, cost[N - 1])
if update == True and Max < cost[N - 1]:
print("inf")
else:
print(Max)
| N, M = list(map(int, input().split()))
abc = []
for _ in range(M):
abc.append(list(map(int, input().split())))
cost = [-(10**10) * N] * N
cost[0] = 0
for i in range(N):
update = False
for a, b, c in abc:
a, b = a - 1, b - 1
if cost[a] != -(10**10) * N:
if cost[b] < cost[a] + c:
cost[b] = cost[a] + c
update = True
if i == 0:
Max = cost[N - 1]
elif i < N - 1:
Max = max(Max, cost[N - 1])
if update == True and Max < cost[N - 1]:
print("inf")
else:
print(Max)
| false | 16.129032 | [
"-from collections import deque",
"-",
"-ls = [deque([]) for _ in range(N)]",
"-for i in range(M):",
"- a, b, c = list(map(int, input().split()))",
"- a, b = a - 1, b - 1",
"- ls[a].append([b, c])",
"+abc = []",
"+for _ in range(M):",
"+ abc.append(list(map(int, input().split())))",
"- q = [deque(m for m in l) for l in ls]",
"- for j in range(N):",
"- if cost[j] != -(10**10) * N:",
"- while q[j]:",
"- b, c = q[j].pop()",
"- if cost[b] < cost[j] + c:",
"- cost[b] = cost[j] + c",
"- update = True",
"+ for a, b, c in abc:",
"+ a, b = a - 1, b - 1",
"+ if cost[a] != -(10**10) * N:",
"+ if cost[b] < cost[a] + c:",
"+ cost[b] = cost[a] + c",
"+ update = True"
]
| false | 0.038507 | 0.179035 | 0.215082 | [
"s445742115",
"s301301561"
]
|
u874395007 | p02419 | python | s747764399 | s504655328 | 40 | 20 | 6,484 | 5,556 | Accepted | Accepted | 50 | import re
pattern = str(eval(input()))
words = []
while True:
line = str(eval(input()))
if line == 'END_OF_TEXT':
break
words += line.lower().split()
cnt = 0
for word in words:
if re.fullmatch(pattern, word):
cnt += 1
print(cnt)
| W = str(eval(input()))
words = []
while True:
line = str(eval(input()))
if line == 'END_OF_TEXT':
break
words += line.lower().split()
cnt = 0
for word in words:
if W == word:
cnt += 1
print(cnt)
| 15 | 14 | 265 | 230 | import re
pattern = str(eval(input()))
words = []
while True:
line = str(eval(input()))
if line == "END_OF_TEXT":
break
words += line.lower().split()
cnt = 0
for word in words:
if re.fullmatch(pattern, word):
cnt += 1
print(cnt)
| W = str(eval(input()))
words = []
while True:
line = str(eval(input()))
if line == "END_OF_TEXT":
break
words += line.lower().split()
cnt = 0
for word in words:
if W == word:
cnt += 1
print(cnt)
| false | 6.666667 | [
"-import re",
"-",
"-pattern = str(eval(input()))",
"+W = str(eval(input()))",
"- if re.fullmatch(pattern, word):",
"+ if W == word:"
]
| false | 0.042349 | 0.037045 | 1.143167 | [
"s747764399",
"s504655328"
]
|
u645250356 | p03163 | python | s703961847 | s765104166 | 669 | 567 | 171,888 | 128,260 | Accepted | Accepted | 15.25 | from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
n,w = inpl()
ww = [0] * n
vv = [0] * n
for i in range(n):
ww[i],vv[i] = inpl()
dp = [[0 for i in range(w+1)] for j in range(n+1)]
for i in range(n):
for j in range(w+1):
if j >= ww[i]:
dp[i+1][j] = max(dp[i][j], dp[i][j-ww[i]]+vv[i])
else:
dp[i+1][j] = dp[i][j]
print((dp[n][w]))
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n,w = inpl()
wei = [0] * n
val = [0] * n
for i in range(n):
wei[i],val[i] = inpl()
dp = [[0]*(w+5) for i in range(n+5)]
for i in range(n):
for j in range(w+1):
if wei[i] > j:
dp[i+1][j] = dp[i][j]
continue
dp[i+1][j] = max(dp[i+1][j], dp[i][j-wei[i]]+val[i], dp[i][j])
print((dp[n][w])) | 24 | 25 | 636 | 759 | from collections import Counter, defaultdict
import sys, bisect, math, itertools, string, queue
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
n, w = inpl()
ww = [0] * n
vv = [0] * n
for i in range(n):
ww[i], vv[i] = inpl()
dp = [[0 for i in range(w + 1)] for j in range(n + 1)]
for i in range(n):
for j in range(w + 1):
if j >= ww[i]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - ww[i]] + vv[i])
else:
dp[i + 1][j] = dp[i][j]
print((dp[n][w]))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
mod2 = 998244353
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n, w = inpl()
wei = [0] * n
val = [0] * n
for i in range(n):
wei[i], val[i] = inpl()
dp = [[0] * (w + 5) for i in range(n + 5)]
for i in range(n):
for j in range(w + 1):
if wei[i] > j:
dp[i + 1][j] = dp[i][j]
continue
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - wei[i]] + val[i], dp[i][j])
print((dp[n][w]))
| false | 4 | [
"-from collections import Counter, defaultdict",
"-import sys, bisect, math, itertools, string, queue",
"+from collections import Counter, defaultdict, deque",
"+from heapq import heappop, heappush, heapify",
"+import sys, bisect, math, itertools, fractions, pprint",
"+sys.setrecursionlimit(10**8)",
"+mod2 = 998244353",
"+INF = float(\"inf\")",
"-def inpl_str():",
"- return list(sys.stdin.readline().split())",
"+def inpln(n):",
"+ return list(int(sys.stdin.readline()) for i in range(n))",
"-ww = [0] * n",
"-vv = [0] * n",
"+wei = [0] * n",
"+val = [0] * n",
"- ww[i], vv[i] = inpl()",
"-dp = [[0 for i in range(w + 1)] for j in range(n + 1)]",
"+ wei[i], val[i] = inpl()",
"+dp = [[0] * (w + 5) for i in range(n + 5)]",
"- if j >= ww[i]:",
"- dp[i + 1][j] = max(dp[i][j], dp[i][j - ww[i]] + vv[i])",
"- else:",
"+ if wei[i] > j:",
"+ continue",
"+ dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - wei[i]] + val[i], dp[i][j])"
]
| false | 0.048408 | 0.033375 | 1.450418 | [
"s703961847",
"s765104166"
]
|
u840988663 | p02830 | python | s233409453 | s782107543 | 20 | 17 | 3,316 | 2,940 | Accepted | Accepted | 15 | N=int(eval(input()))
S,T = list(map(str, input().split()))
li=[]
for i in range(N):
li.append(S[i])
li.append(T[i])
print((''.join(li))) | n=int(eval(input()))
s,t=input().split()
li=[]
for i in range(n):
li.append(s[i])
li.append(t[i])
li="".join(li)
print(li)
| 7 | 9 | 136 | 130 | N = int(eval(input()))
S, T = list(map(str, input().split()))
li = []
for i in range(N):
li.append(S[i])
li.append(T[i])
print(("".join(li)))
| n = int(eval(input()))
s, t = input().split()
li = []
for i in range(n):
li.append(s[i])
li.append(t[i])
li = "".join(li)
print(li)
| false | 22.222222 | [
"-N = int(eval(input()))",
"-S, T = list(map(str, input().split()))",
"+n = int(eval(input()))",
"+s, t = input().split()",
"-for i in range(N):",
"- li.append(S[i])",
"- li.append(T[i])",
"-print((\"\".join(li)))",
"+for i in range(n):",
"+ li.append(s[i])",
"+ li.append(t[i])",
"+li = \"\".join(li)",
"+print(li)"
]
| false | 0.045312 | 0.044806 | 1.011305 | [
"s233409453",
"s782107543"
]
|
u334712262 | p02925 | python | s238834609 | s315604047 | 1,818 | 1,072 | 386,444 | 224,560 | Accepted | Accepted | 41.03 | # -*- coding: utf-8 -*-
from collections import Counter, defaultdict
import sys
# sys.setrecursionlimit(10**6)
readline = sys.stdin.buffer.readline
# readline = sys.stdin.readline
INF = 1 << 60
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, A):
g = defaultdict(list)
rg = defaultdict(set)
V = set()
def ij2v(i, j):
if i > j:
i, j = j, i
return i * 10**6 + j
for i, a in enumerate(A, start=1):
for j in range(len(a)-1):
u = ij2v(i, a[j])
v = ij2v(i, a[j+1])
g[u].append(v)
rg[v].add(u)
V.add(u)
V.add(v)
s = []
for v in V:
if not rg[v]:
s.append(v)
done = len(s)
ans = 0
while s:
ans += 1
ns = []
for u in s:
for v in g[u]:
# if v in done:
# continue
rg[v].remove(u)
if len(rg[v]) == 0:
ns.append(v)
done += 1
s = ns
if done != N * (N-1) // 2:
return -1
return ans
def main():
N = read_int()
A = [read_int_n() for _ in range(N)]
print(slv(N, A))
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
MAXN = 1005
MAXV = MAXN*(MAXN-1)//2
to = [[] for _ in range(MAXV)] # 頂点間の辺の情報
id = [[[] for _ in range(MAXN)] for _ in range(MAXN)] # 試合のid=DAGの頂点番号
def toId(i,j): # 選手idから試合idを返す関数
if i > j: # i,jが逆になっても試合idは同じ
i,j = j,i
return id[i][j]
visited = [False]*MAXV
calculated = [False]*MAXV
dp = [1]*MAXV # Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1
def dfs(v):
if visited[v]:
if not calculated[v]:
return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ
return dp[v]
visited[v] = True
for u in to[v]: # 全ての辺をなめる
res = dfs(u)
if res == -1: return -1 # ループがあれば-1を返す
dp[v] = max(dp[v], res+1)
calculated[v] = True
return dp[v]
def main():
n = int(eval(input()))
a = [[int(i) for i in readline().split()] for _ in range(n)]
for i in range(n):
for j in range(n-1):
a[i][j] -= 1 # 選手idを0始まりに変換
V = 0
for i in range(n):
for j in range(n):
if i < j:
id[i][j] = V
V += 1 # 0から順に各試合にidを割り振る
for i in range(n):
for j in range(n-1):
a[i][j] = toId(i,a[i][j]) # 選手idを試合id(頂点番号)に置き換える
for j in range(n-2): # 頂点間の依存関係はn-2個
to[a[i][j+1]].append(a[i][j])
ans = 0
for i in range(V):
res = dfs(i)
if res == -1:
print('-1') # ループがあれば-1を返す(問題文の指示)
return
ans = max(ans, res)
print(ans)
return
if __name__ == '__main__':
main() | 109 | 59 | 1,930 | 1,610 | # -*- coding: utf-8 -*-
from collections import Counter, defaultdict
import sys
# sys.setrecursionlimit(10**6)
readline = sys.stdin.buffer.readline
# readline = sys.stdin.readline
INF = 1 << 60
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, "sec")
return ret
return wrap
@mt
def slv(N, A):
g = defaultdict(list)
rg = defaultdict(set)
V = set()
def ij2v(i, j):
if i > j:
i, j = j, i
return i * 10**6 + j
for i, a in enumerate(A, start=1):
for j in range(len(a) - 1):
u = ij2v(i, a[j])
v = ij2v(i, a[j + 1])
g[u].append(v)
rg[v].add(u)
V.add(u)
V.add(v)
s = []
for v in V:
if not rg[v]:
s.append(v)
done = len(s)
ans = 0
while s:
ans += 1
ns = []
for u in s:
for v in g[u]:
# if v in done:
# continue
rg[v].remove(u)
if len(rg[v]) == 0:
ns.append(v)
done += 1
s = ns
if done != N * (N - 1) // 2:
return -1
return ans
def main():
N = read_int()
A = [read_int_n() for _ in range(N)]
print(slv(N, A))
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
MAXN = 1005
MAXV = MAXN * (MAXN - 1) // 2
to = [[] for _ in range(MAXV)] # 頂点間の辺の情報
id = [[[] for _ in range(MAXN)] for _ in range(MAXN)] # 試合のid=DAGの頂点番号
def toId(i, j): # 選手idから試合idを返す関数
if i > j: # i,jが逆になっても試合idは同じ
i, j = j, i
return id[i][j]
visited = [False] * MAXV
calculated = [False] * MAXV
dp = [1] * MAXV # Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1
def dfs(v):
if visited[v]:
if not calculated[v]:
return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ
return dp[v]
visited[v] = True
for u in to[v]: # 全ての辺をなめる
res = dfs(u)
if res == -1:
return -1 # ループがあれば-1を返す
dp[v] = max(dp[v], res + 1)
calculated[v] = True
return dp[v]
def main():
n = int(eval(input()))
a = [[int(i) for i in readline().split()] for _ in range(n)]
for i in range(n):
for j in range(n - 1):
a[i][j] -= 1 # 選手idを0始まりに変換
V = 0
for i in range(n):
for j in range(n):
if i < j:
id[i][j] = V
V += 1 # 0から順に各試合にidを割り振る
for i in range(n):
for j in range(n - 1):
a[i][j] = toId(i, a[i][j]) # 選手idを試合id(頂点番号)に置き換える
for j in range(n - 2): # 頂点間の依存関係はn-2個
to[a[i][j + 1]].append(a[i][j])
ans = 0
for i in range(V):
res = dfs(i)
if res == -1:
print("-1") # ループがあれば-1を返す(問題文の指示)
return
ans = max(ans, res)
print(ans)
return
if __name__ == "__main__":
main()
| false | 45.87156 | [
"-# -*- coding: utf-8 -*-",
"-from collections import Counter, defaultdict",
"-# sys.setrecursionlimit(10**6)",
"-readline = sys.stdin.buffer.readline",
"-# readline = sys.stdin.readline",
"-INF = 1 << 60",
"+sys.setrecursionlimit(10**6)",
"+readline = sys.stdin.readline",
"+MAXN = 1005",
"+MAXV = MAXN * (MAXN - 1) // 2",
"+to = [[] for _ in range(MAXV)] # 頂点間の辺の情報",
"+id = [[[] for _ in range(MAXN)] for _ in range(MAXN)] # 試合のid=DAGの頂点番号",
"-def read_int():",
"- return int(readline())",
"+def toId(i, j): # 選手idから試合idを返す関数",
"+ if i > j: # i,jが逆になっても試合idは同じ",
"+ i, j = j, i",
"+ return id[i][j]",
"-def read_int_n():",
"- return list(map(int, readline().split()))",
"+visited = [False] * MAXV",
"+calculated = [False] * MAXV",
"+dp = [1] * MAXV # Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1",
"-def read_float():",
"- return float(readline())",
"-",
"-",
"-def read_float_n():",
"- return list(map(float, readline().split()))",
"-",
"-",
"-def read_str():",
"- return readline().strip()",
"-",
"-",
"-def read_str_n():",
"- return readline().strip().split()",
"-",
"-",
"-def ep(*args):",
"- print(*args, file=sys.stderr)",
"-",
"-",
"-def mt(f):",
"- import time",
"-",
"- def wrap(*args, **kwargs):",
"- s = time.perf_counter()",
"- ret = f(*args, **kwargs)",
"- e = time.perf_counter()",
"- ep(e - s, \"sec\")",
"- return ret",
"-",
"- return wrap",
"-",
"-",
"-@mt",
"-def slv(N, A):",
"- g = defaultdict(list)",
"- rg = defaultdict(set)",
"- V = set()",
"-",
"- def ij2v(i, j):",
"- if i > j:",
"- i, j = j, i",
"- return i * 10**6 + j",
"-",
"- for i, a in enumerate(A, start=1):",
"- for j in range(len(a) - 1):",
"- u = ij2v(i, a[j])",
"- v = ij2v(i, a[j + 1])",
"- g[u].append(v)",
"- rg[v].add(u)",
"- V.add(u)",
"- V.add(v)",
"- s = []",
"- for v in V:",
"- if not rg[v]:",
"- s.append(v)",
"- done = len(s)",
"- ans = 0",
"- while s:",
"- ans += 1",
"- ns = []",
"- for u in s:",
"- for v in g[u]:",
"- # if v in done:",
"- # continue",
"- rg[v].remove(u)",
"- if len(rg[v]) == 0:",
"- ns.append(v)",
"- done += 1",
"- s = ns",
"- if done != N * (N - 1) // 2:",
"- return -1",
"- return ans",
"+def dfs(v):",
"+ if visited[v]:",
"+ if not calculated[v]:",
"+ return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ",
"+ return dp[v]",
"+ visited[v] = True",
"+ for u in to[v]: # 全ての辺をなめる",
"+ res = dfs(u)",
"+ if res == -1:",
"+ return -1 # ループがあれば-1を返す",
"+ dp[v] = max(dp[v], res + 1)",
"+ calculated[v] = True",
"+ return dp[v]",
"- N = read_int()",
"- A = [read_int_n() for _ in range(N)]",
"- print(slv(N, A))",
"+ n = int(eval(input()))",
"+ a = [[int(i) for i in readline().split()] for _ in range(n)]",
"+ for i in range(n):",
"+ for j in range(n - 1):",
"+ a[i][j] -= 1 # 選手idを0始まりに変換",
"+ V = 0",
"+ for i in range(n):",
"+ for j in range(n):",
"+ if i < j:",
"+ id[i][j] = V",
"+ V += 1 # 0から順に各試合にidを割り振る",
"+ for i in range(n):",
"+ for j in range(n - 1):",
"+ a[i][j] = toId(i, a[i][j]) # 選手idを試合id(頂点番号)に置き換える",
"+ for j in range(n - 2): # 頂点間の依存関係はn-2個",
"+ to[a[i][j + 1]].append(a[i][j])",
"+ ans = 0",
"+ for i in range(V):",
"+ res = dfs(i)",
"+ if res == -1:",
"+ print(\"-1\") # ループがあれば-1を返す(問題文の指示)",
"+ return",
"+ ans = max(ans, res)",
"+ print(ans)",
"+ return"
]
| false | 0.044138 | 1.582727 | 0.027887 | [
"s238834609",
"s315604047"
]
|
u616217092 | p03353 | python | s696362007 | s729835607 | 58 | 40 | 16,500 | 16,248 | Accepted | Accepted | 31.03 | from sys import stdin
from string import ascii_lowercase
def myfind(s, c):
result = []
for i, x in enumerate(s):
if x == c:
result.append(i)
return result
def main():
s = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
result = []
for x in ascii_lowercase:
idxs = myfind(s, x)
if not idxs:
continue
result.append(x)
if len(result) >= K:
break
temp = sorted(list(set([s[x:] for x in idxs])))
for y in temp:
for z in range(len(y)):
foo = y[: z + 1]
if not foo in result:
result.append(foo)
if len(result) >= K:
break
if len(result) >= K:
break
if len(result) >= K:
break
print((result[-1]))
if __name__ == '__main__':
main()
| from sys import stdin
from string import ascii_lowercase
def main():
s = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
result = []
for c in ascii_lowercase:
for text in sorted([s[i:] for i, x in enumerate(s) if x == c]):
for i in range(len(text)):
if not text[:i + 1] in result:
result.append(text[:i + 1])
if len(result) == K:
print((result[-1]))
return
if __name__ == '__main__':
main()
| 41 | 20 | 965 | 569 | from sys import stdin
from string import ascii_lowercase
def myfind(s, c):
result = []
for i, x in enumerate(s):
if x == c:
result.append(i)
return result
def main():
s = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
result = []
for x in ascii_lowercase:
idxs = myfind(s, x)
if not idxs:
continue
result.append(x)
if len(result) >= K:
break
temp = sorted(list(set([s[x:] for x in idxs])))
for y in temp:
for z in range(len(y)):
foo = y[: z + 1]
if not foo in result:
result.append(foo)
if len(result) >= K:
break
if len(result) >= K:
break
if len(result) >= K:
break
print((result[-1]))
if __name__ == "__main__":
main()
| from sys import stdin
from string import ascii_lowercase
def main():
s = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
result = []
for c in ascii_lowercase:
for text in sorted([s[i:] for i, x in enumerate(s) if x == c]):
for i in range(len(text)):
if not text[: i + 1] in result:
result.append(text[: i + 1])
if len(result) == K:
print((result[-1]))
return
if __name__ == "__main__":
main()
| false | 51.219512 | [
"-",
"-",
"-def myfind(s, c):",
"- result = []",
"- for i, x in enumerate(s):",
"- if x == c:",
"- result.append(i)",
"- return result",
"- for x in ascii_lowercase:",
"- idxs = myfind(s, x)",
"- if not idxs:",
"- continue",
"- result.append(x)",
"- if len(result) >= K:",
"- break",
"- temp = sorted(list(set([s[x:] for x in idxs])))",
"- for y in temp:",
"- for z in range(len(y)):",
"- foo = y[: z + 1]",
"- if not foo in result:",
"- result.append(foo)",
"- if len(result) >= K:",
"- break",
"- if len(result) >= K:",
"- break",
"- if len(result) >= K:",
"- break",
"- print((result[-1]))",
"+ for c in ascii_lowercase:",
"+ for text in sorted([s[i:] for i, x in enumerate(s) if x == c]):",
"+ for i in range(len(text)):",
"+ if not text[: i + 1] in result:",
"+ result.append(text[: i + 1])",
"+ if len(result) == K:",
"+ print((result[-1]))",
"+ return"
]
| false | 0.049658 | 0.101003 | 0.49165 | [
"s696362007",
"s729835607"
]
|
u781262926 | p03361 | python | s185719154 | s252019264 | 281 | 178 | 18,300 | 12,352 | Accepted | Accepted | 36.65 | from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()
class Grid():
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return '\n'.join([' '.join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:], function=lambda x: int(x == '#'))
from collections import deque
def bfs(root):
count = 1
x, y = root
grid[y, x] = 0
queue = deque([root])
while queue:
x, y = queue.popleft()
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]:
queue.append((x+dx, y+dy))
grid[y+dy, x+dx] = 0
count += 1
return count
ans = 'Yes'
for i, j in product(list(range(h)), list(range(w))):
if grid[i, j]:
if bfs((j, i)) == 1:
ans = 'No'
break
print(ans) | from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()
class Grid():
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return '\n'.join([' '.join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:], function=lambda x: int(x == '#'))
def dfs(root):
count = 1
x, y = root
grid[y, x] = 0
stack = [root]
while stack:
x, y = stack.pop()
grid[y, x] = 0
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]:
stack.append((x+dx, y+dy))
count += 1
return count
ans = 'Yes'
for i, j in product(list(range(h)), list(range(w))):
if grid[i, j]:
if dfs((j, i)) == 1:
ans = 'No'
break
print(ans) | 55 | 54 | 1,717 | 1,661 | from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()
class Grid:
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return "\n".join([" ".join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:], function=lambda x: int(x == "#"))
from collections import deque
def bfs(root):
count = 1
x, y = root
grid[y, x] = 0
queue = deque([root])
while queue:
x, y = queue.popleft()
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
if grid.is_valid_xy(x + dx, y + dy) and grid[y + dy, x + dx]:
queue.append((x + dx, y + dy))
grid[y + dy, x + dx] = 0
count += 1
return count
ans = "Yes"
for i, j in product(list(range(h)), list(range(w))):
if grid[i, j]:
if bfs((j, i)) == 1:
ans = "No"
break
print(ans)
| from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()
class Grid:
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return "\n".join([" ".join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:], function=lambda x: int(x == "#"))
def dfs(root):
count = 1
x, y = root
grid[y, x] = 0
stack = [root]
while stack:
x, y = stack.pop()
grid[y, x] = 0
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
if grid.is_valid_xy(x + dx, y + dy) and grid[y + dy, x + dx]:
stack.append((x + dx, y + dy))
count += 1
return count
ans = "Yes"
for i, j in product(list(range(h)), list(range(w))):
if grid[i, j]:
if dfs((j, i)) == 1:
ans = "No"
break
print(ans)
| false | 1.818182 | [
"-from collections import deque",
"-def bfs(root):",
"+def dfs(root):",
"- queue = deque([root])",
"- while queue:",
"- x, y = queue.popleft()",
"+ stack = [root]",
"+ while stack:",
"+ x, y = stack.pop()",
"+ grid[y, x] = 0",
"- queue.append((x + dx, y + dy))",
"- grid[y + dy, x + dx] = 0",
"+ stack.append((x + dx, y + dy))",
"- if bfs((j, i)) == 1:",
"+ if dfs((j, i)) == 1:"
]
| false | 0.289992 | 0.153809 | 1.885402 | [
"s185719154",
"s252019264"
]
|
u912237403 | p00066 | python | s637008420 | s241553658 | 20 | 10 | 4,220 | 4,216 | Accepted | Accepted | 50 | import sys
x=["ooo","xxx"]
for s in sys.stdin:
c="d"
for i in range(3):
if s[i:9:3]in x:
c=s[i]
break
j=i*3
if s[j:j+3]in x:
c=s[j]
break
else:
if s[0::4] in x or s[2:7:2] in x:c=s[4]
print(c) | import sys
def f(a,b,c):
return a if a!="s"and a==b==c else 0
for s in sys.stdin:
for i in range(3):
c=f(*s[i:9:3])
if c: break
j=i*3
c=f(*s[j:j+3])
if c: break
else:
a=s[4]
if f(*s[0:9:4])or f(*s[2:7:2]):c=a
else:c="d"
print(c) | 15 | 15 | 301 | 321 | import sys
x = ["ooo", "xxx"]
for s in sys.stdin:
c = "d"
for i in range(3):
if s[i:9:3] in x:
c = s[i]
break
j = i * 3
if s[j : j + 3] in x:
c = s[j]
break
else:
if s[0::4] in x or s[2:7:2] in x:
c = s[4]
print(c)
| import sys
def f(a, b, c):
return a if a != "s" and a == b == c else 0
for s in sys.stdin:
for i in range(3):
c = f(*s[i:9:3])
if c:
break
j = i * 3
c = f(*s[j : j + 3])
if c:
break
else:
a = s[4]
if f(*s[0:9:4]) or f(*s[2:7:2]):
c = a
else:
c = "d"
print(c)
| false | 0 | [
"-x = [\"ooo\", \"xxx\"]",
"+",
"+def f(a, b, c):",
"+ return a if a != \"s\" and a == b == c else 0",
"+",
"+",
"- c = \"d\"",
"- if s[i:9:3] in x:",
"- c = s[i]",
"+ c = f(*s[i:9:3])",
"+ if c:",
"- if s[j : j + 3] in x:",
"- c = s[j]",
"+ c = f(*s[j : j + 3])",
"+ if c:",
"- if s[0::4] in x or s[2:7:2] in x:",
"- c = s[4]",
"+ a = s[4]",
"+ if f(*s[0:9:4]) or f(*s[2:7:2]):",
"+ c = a",
"+ else:",
"+ c = \"d\""
]
| false | 0.040674 | 0.097335 | 0.417876 | [
"s637008420",
"s241553658"
]
|
u089376182 | p03556 | python | s614206444 | s941975006 | 21 | 18 | 3,316 | 3,188 | Accepted | Accepted | 14.29 | n = int(eval(input()))
print((int(int(n**.5)**2))) | n = int(eval(input()))
print((int(n**0.5)**2)) | 2 | 2 | 43 | 39 | n = int(eval(input()))
print((int(int(n**0.5) ** 2)))
| n = int(eval(input()))
print((int(n**0.5) ** 2))
| false | 0 | [
"-print((int(int(n**0.5) ** 2)))",
"+print((int(n**0.5) ** 2))"
]
| false | 0.110774 | 0.042835 | 2.586043 | [
"s614206444",
"s941975006"
]
|
u494058663 | p02683 | python | s681296965 | s054488916 | 98 | 72 | 9,780 | 9,232 | Accepted | Accepted | 26.53 | n,m,x = list(map(int,input().split()))
pattern = []
for i in range(2**(n)):
tmp = [0 for i in range(n)]
for j in range(n):
if i>>j & 1:
tmp[j] = 1
pattern.append(tmp)
ans = 10**9
Input= []
for i in range(n):
tmp = [int(i) for i in input().split()]
Input.append(tmp)
for i in pattern:
score = [0 for j in range(m)]
tmp_ans = 0
Flag = True
for j in range(len(i)):
if i[j]==0:
continue
else:
tmp_ans += Input[j][0]
for k in range(m):
score[k] += Input[j][k+1]
for k in range(m):
if score[k]<x:
Flag = False
if Flag == False:
continue
ans = min(ans,tmp_ans)
if ans==10**9:
print((-1))
else:
print(ans)
| def main():
n,m,x = list(map(int,input().split()))
A = []
ans = 10**9
for i in range(n):
tmp = [int(i) for i in input().split()]
A.append(tmp)
for i in range(2**n):
arg = [0 for j in range(m+1)]
cost = 0
for j in range(n):
if (i>>j)&1 ==1:
cost += A[j][0]
for k in range(1,m+1):
arg[k] += A[j][k]
flag = True
for k in range(1,m+1):
if arg[k]<x:
flag = False
break
if flag:
ans = min(ans,cost)
if ans==10**9:
print('-1')
else:
print(ans)
main() | 35 | 27 | 797 | 691 | n, m, x = list(map(int, input().split()))
pattern = []
for i in range(2 ** (n)):
tmp = [0 for i in range(n)]
for j in range(n):
if i >> j & 1:
tmp[j] = 1
pattern.append(tmp)
ans = 10**9
Input = []
for i in range(n):
tmp = [int(i) for i in input().split()]
Input.append(tmp)
for i in pattern:
score = [0 for j in range(m)]
tmp_ans = 0
Flag = True
for j in range(len(i)):
if i[j] == 0:
continue
else:
tmp_ans += Input[j][0]
for k in range(m):
score[k] += Input[j][k + 1]
for k in range(m):
if score[k] < x:
Flag = False
if Flag == False:
continue
ans = min(ans, tmp_ans)
if ans == 10**9:
print((-1))
else:
print(ans)
| def main():
n, m, x = list(map(int, input().split()))
A = []
ans = 10**9
for i in range(n):
tmp = [int(i) for i in input().split()]
A.append(tmp)
for i in range(2**n):
arg = [0 for j in range(m + 1)]
cost = 0
for j in range(n):
if (i >> j) & 1 == 1:
cost += A[j][0]
for k in range(1, m + 1):
arg[k] += A[j][k]
flag = True
for k in range(1, m + 1):
if arg[k] < x:
flag = False
break
if flag:
ans = min(ans, cost)
if ans == 10**9:
print("-1")
else:
print(ans)
main()
| false | 22.857143 | [
"-n, m, x = list(map(int, input().split()))",
"-pattern = []",
"-for i in range(2 ** (n)):",
"- tmp = [0 for i in range(n)]",
"- for j in range(n):",
"- if i >> j & 1:",
"- tmp[j] = 1",
"- pattern.append(tmp)",
"-ans = 10**9",
"-Input = []",
"-for i in range(n):",
"- tmp = [int(i) for i in input().split()]",
"- Input.append(tmp)",
"-for i in pattern:",
"- score = [0 for j in range(m)]",
"- tmp_ans = 0",
"- Flag = True",
"- for j in range(len(i)):",
"- if i[j] == 0:",
"- continue",
"- else:",
"- tmp_ans += Input[j][0]",
"- for k in range(m):",
"- score[k] += Input[j][k + 1]",
"- for k in range(m):",
"- if score[k] < x:",
"- Flag = False",
"- if Flag == False:",
"- continue",
"- ans = min(ans, tmp_ans)",
"-if ans == 10**9:",
"- print((-1))",
"-else:",
"- print(ans)",
"+def main():",
"+ n, m, x = list(map(int, input().split()))",
"+ A = []",
"+ ans = 10**9",
"+ for i in range(n):",
"+ tmp = [int(i) for i in input().split()]",
"+ A.append(tmp)",
"+ for i in range(2**n):",
"+ arg = [0 for j in range(m + 1)]",
"+ cost = 0",
"+ for j in range(n):",
"+ if (i >> j) & 1 == 1:",
"+ cost += A[j][0]",
"+ for k in range(1, m + 1):",
"+ arg[k] += A[j][k]",
"+ flag = True",
"+ for k in range(1, m + 1):",
"+ if arg[k] < x:",
"+ flag = False",
"+ break",
"+ if flag:",
"+ ans = min(ans, cost)",
"+ if ans == 10**9:",
"+ print(\"-1\")",
"+ else:",
"+ print(ans)",
"+",
"+",
"+main()"
]
| false | 0.061045 | 0.03753 | 1.626567 | [
"s681296965",
"s054488916"
]
|
u893063840 | p02949 | python | s397282002 | s081446694 | 1,114 | 334 | 49,240 | 25,040 | Accepted | Accepted | 70.02 | n, m, p = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
# loop 0 - (n-1) : bellman ford
# loop n - (2n-1): check g can be updated
dist = [float("inf")] * n
dist[s] = 0
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
cost = -(c - p)
if dist[b] > dist[a] + cost:
dist[b] = dist[a] + cost
if i >= n:
dist[b] = -float("inf")
if dist[g] == -float("inf"):
return -1
else:
return max(-dist[g], 0)
ans = bellman_ford(0, n - 1)
print(ans)
| from scipy.sparse.csgraph import bellman_ford, NegativeCycleError
from scipy.sparse import csr_matrix
from collections import defaultdict
n, m, p = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
INF = 10 ** 9
fwd = [[] for _ in range(n + 1)]
rev = [[] for _ in range(n + 1)]
for a, b, c in abc:
fwd[a].append(b)
rev[b].append(a)
def dfs(s, adj):
stack = [s]
arrived = [False] * (n + 1)
arrived[s] = True
while stack:
u = stack.pop()
for v in adj[u]:
if not arrived[v]:
arrived[v] = True
stack.append(v)
return arrived
can_go_fwd = dfs(1, fwd)
can_go_rev = dfs(n, rev)
data = defaultdict(lambda: INF)
for a, b, c in abc:
if can_go_fwd[a] and can_go_rev[b]:
data[(a, b)] = min(data[(a, b)], p - c)
row = []
col = []
cost = []
for (a, b), c in list(data.items()):
row.append(a)
col.append(b)
cost.append(c)
g = csr_matrix((cost, (row, col)), shape=(n + 1, n + 1))
try:
dist = bellman_ford(g, indices=[1]).astype(int)
ans = max(0, -dist[0][n])
print(ans)
except NegativeCycleError:
print((-1))
| 29 | 54 | 688 | 1,212 | n, m, p = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
# loop 0 - (n-1) : bellman ford
# loop n - (2n-1): check g can be updated
dist = [float("inf")] * n
dist[s] = 0
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
cost = -(c - p)
if dist[b] > dist[a] + cost:
dist[b] = dist[a] + cost
if i >= n:
dist[b] = -float("inf")
if dist[g] == -float("inf"):
return -1
else:
return max(-dist[g], 0)
ans = bellman_ford(0, n - 1)
print(ans)
| from scipy.sparse.csgraph import bellman_ford, NegativeCycleError
from scipy.sparse import csr_matrix
from collections import defaultdict
n, m, p = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
INF = 10**9
fwd = [[] for _ in range(n + 1)]
rev = [[] for _ in range(n + 1)]
for a, b, c in abc:
fwd[a].append(b)
rev[b].append(a)
def dfs(s, adj):
stack = [s]
arrived = [False] * (n + 1)
arrived[s] = True
while stack:
u = stack.pop()
for v in adj[u]:
if not arrived[v]:
arrived[v] = True
stack.append(v)
return arrived
can_go_fwd = dfs(1, fwd)
can_go_rev = dfs(n, rev)
data = defaultdict(lambda: INF)
for a, b, c in abc:
if can_go_fwd[a] and can_go_rev[b]:
data[(a, b)] = min(data[(a, b)], p - c)
row = []
col = []
cost = []
for (a, b), c in list(data.items()):
row.append(a)
col.append(b)
cost.append(c)
g = csr_matrix((cost, (row, col)), shape=(n + 1, n + 1))
try:
dist = bellman_ford(g, indices=[1]).astype(int)
ans = max(0, -dist[0][n])
print(ans)
except NegativeCycleError:
print((-1))
| false | 46.296296 | [
"+from scipy.sparse.csgraph import bellman_ford, NegativeCycleError",
"+from scipy.sparse import csr_matrix",
"+from collections import defaultdict",
"+",
"+INF = 10**9",
"+fwd = [[] for _ in range(n + 1)]",
"+rev = [[] for _ in range(n + 1)]",
"+for a, b, c in abc:",
"+ fwd[a].append(b)",
"+ rev[b].append(a)",
"-def bellman_ford(s, g):",
"- # loop 0 - (n-1) : bellman ford",
"- # loop n - (2n-1): check g can be updated",
"- dist = [float(\"inf\")] * n",
"- dist[s] = 0",
"- for i in range(2 * n):",
"- for a, b, c in abc:",
"- a -= 1",
"- b -= 1",
"- cost = -(c - p)",
"- if dist[b] > dist[a] + cost:",
"- dist[b] = dist[a] + cost",
"- if i >= n:",
"- dist[b] = -float(\"inf\")",
"- if dist[g] == -float(\"inf\"):",
"- return -1",
"- else:",
"- return max(-dist[g], 0)",
"+def dfs(s, adj):",
"+ stack = [s]",
"+ arrived = [False] * (n + 1)",
"+ arrived[s] = True",
"+ while stack:",
"+ u = stack.pop()",
"+ for v in adj[u]:",
"+ if not arrived[v]:",
"+ arrived[v] = True",
"+ stack.append(v)",
"+ return arrived",
"-ans = bellman_ford(0, n - 1)",
"-print(ans)",
"+can_go_fwd = dfs(1, fwd)",
"+can_go_rev = dfs(n, rev)",
"+data = defaultdict(lambda: INF)",
"+for a, b, c in abc:",
"+ if can_go_fwd[a] and can_go_rev[b]:",
"+ data[(a, b)] = min(data[(a, b)], p - c)",
"+row = []",
"+col = []",
"+cost = []",
"+for (a, b), c in list(data.items()):",
"+ row.append(a)",
"+ col.append(b)",
"+ cost.append(c)",
"+g = csr_matrix((cost, (row, col)), shape=(n + 1, n + 1))",
"+try:",
"+ dist = bellman_ford(g, indices=[1]).astype(int)",
"+ ans = max(0, -dist[0][n])",
"+ print(ans)",
"+except NegativeCycleError:",
"+ print((-1))"
]
| false | 0.036803 | 0.259546 | 0.1418 | [
"s397282002",
"s081446694"
]
|
u628538573 | p03282 | python | s828093556 | s875864622 | 24 | 17 | 3,064 | 2,940 | Accepted | Accepted | 29.17 | s = eval(input())
k = int(eval(input()))
flag = -1
n = len(s)
if n >= k:
n = k
for i in range(n):
if flag == -1:
if s[i] != '1':
flag = i
if flag == -1:
print('1')
else:
print((s[flag])) | s = eval(input())
k = int(eval(input()))
i = 0
while s[i] == "1":
i += 1
if i > len(s) - 1:
break
if k <= len(s) and i >= k:
print((1))
else:
print((s[i])) | 17 | 13 | 200 | 159 | s = eval(input())
k = int(eval(input()))
flag = -1
n = len(s)
if n >= k:
n = k
for i in range(n):
if flag == -1:
if s[i] != "1":
flag = i
if flag == -1:
print("1")
else:
print((s[flag]))
| s = eval(input())
k = int(eval(input()))
i = 0
while s[i] == "1":
i += 1
if i > len(s) - 1:
break
if k <= len(s) and i >= k:
print((1))
else:
print((s[i]))
| false | 23.529412 | [
"-flag = -1",
"-n = len(s)",
"-if n >= k:",
"- n = k",
"-for i in range(n):",
"- if flag == -1:",
"- if s[i] != \"1\":",
"- flag = i",
"-if flag == -1:",
"- print(\"1\")",
"+i = 0",
"+while s[i] == \"1\":",
"+ i += 1",
"+ if i > len(s) - 1:",
"+ break",
"+if k <= len(s) and i >= k:",
"+ print((1))",
"- print((s[flag]))",
"+ print((s[i]))"
]
| false | 0.036527 | 0.078794 | 0.463573 | [
"s828093556",
"s875864622"
]
|
u777923818 | p03043 | python | s405476109 | s445543604 | 174 | 58 | 38,640 | 5,128 | Accepted | Accepted | 66.67 | from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))
N, K = inpl()
ans = 0
X = 17
for i in range(1, N+1):
while X and i * 2**(X-1) >= K:
X -= 1
ans += .5 ** X
print((ans/N)) | def inpl(): return list(map(int, input().split()))
N, K = inpl()
X = [0] + [1/N if i <= N else 0 for i in range(1, K)]
w = max(0, N-K+1)/N
for i in range(K):
if (i*2 >= K):
w += X[i]/2
else:
X[i*2] += X[i]/2
print(w) | 13 | 11 | 252 | 251 | from collections import defaultdict, deque, Counter
def inpl():
return list(map(int, input().split()))
N, K = inpl()
ans = 0
X = 17
for i in range(1, N + 1):
while X and i * 2 ** (X - 1) >= K:
X -= 1
ans += 0.5**X
print((ans / N))
| def inpl():
return list(map(int, input().split()))
N, K = inpl()
X = [0] + [1 / N if i <= N else 0 for i in range(1, K)]
w = max(0, N - K + 1) / N
for i in range(K):
if i * 2 >= K:
w += X[i] / 2
else:
X[i * 2] += X[i] / 2
print(w)
| false | 15.384615 | [
"-from collections import defaultdict, deque, Counter",
"-",
"-",
"-ans = 0",
"-X = 17",
"-for i in range(1, N + 1):",
"- while X and i * 2 ** (X - 1) >= K:",
"- X -= 1",
"- ans += 0.5**X",
"-print((ans / N))",
"+X = [0] + [1 / N if i <= N else 0 for i in range(1, K)]",
"+w = max(0, N - K + 1) / N",
"+for i in range(K):",
"+ if i * 2 >= K:",
"+ w += X[i] / 2",
"+ else:",
"+ X[i * 2] += X[i] / 2",
"+print(w)"
]
| false | 0.045618 | 0.03616 | 1.261563 | [
"s405476109",
"s445543604"
]
|
u729133443 | p03308 | python | s809796923 | s732192004 | 188 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.96 | eval(input());*a,=list(map(int,input().split()));print((max(a)-min(a))) | _,a=open(0);*a,=list(map(int,a.split()));print((max(a)-min(a))) | 1 | 1 | 57 | 55 | eval(input())
(*a,) = list(map(int, input().split()))
print((max(a) - min(a)))
| _, a = open(0)
(*a,) = list(map(int, a.split()))
print((max(a) - min(a)))
| false | 0 | [
"-eval(input())",
"-(*a,) = list(map(int, input().split()))",
"+_, a = open(0)",
"+(*a,) = list(map(int, a.split()))"
]
| false | 0.083354 | 0.045616 | 1.827302 | [
"s809796923",
"s732192004"
]
|
u343977188 | p02820 | python | s285003026 | s225328890 | 57 | 38 | 4,084 | 4,084 | Accepted | Accepted | 33.33 | N,K=list(map(int,input().split()))
R,S,P=list(map(int,input().split()))
T=list(eval(input()))
score={'r':P,'s':R,'p':S}
ans=0
for i in range(K):
ans += score[T[i]]
for i in range(K,N):
if T[i-K] == T[i]:
T[i] = ''
continue
ans += score[T[i]]
print(ans) | def resolve():
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(eval(input()))
score = {'r': P, 's': R, 'p': S}
ans = 0
for i in range(K):
ans += score[T[i]]
for i in range(K, N):
if T[i-K] == T[i]:
T[i] = ' '
continue
ans += score[T[i]]
print(ans)
if __name__ == "__main__":
resolve() | 17 | 21 | 268 | 423 | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(eval(input()))
score = {"r": P, "s": R, "p": S}
ans = 0
for i in range(K):
ans += score[T[i]]
for i in range(K, N):
if T[i - K] == T[i]:
T[i] = ""
continue
ans += score[T[i]]
print(ans)
| def resolve():
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(eval(input()))
score = {"r": P, "s": R, "p": S}
ans = 0
for i in range(K):
ans += score[T[i]]
for i in range(K, N):
if T[i - K] == T[i]:
T[i] = " "
continue
ans += score[T[i]]
print(ans)
if __name__ == "__main__":
resolve()
| false | 19.047619 | [
"-N, K = list(map(int, input().split()))",
"-R, S, P = list(map(int, input().split()))",
"-T = list(eval(input()))",
"-score = {\"r\": P, \"s\": R, \"p\": S}",
"-ans = 0",
"-for i in range(K):",
"- ans += score[T[i]]",
"-for i in range(K, N):",
"- if T[i - K] == T[i]:",
"- T[i] = \"\"",
"- continue",
"- ans += score[T[i]]",
"-print(ans)",
"+def resolve():",
"+ N, K = list(map(int, input().split()))",
"+ R, S, P = list(map(int, input().split()))",
"+ T = list(eval(input()))",
"+ score = {\"r\": P, \"s\": R, \"p\": S}",
"+ ans = 0",
"+ for i in range(K):",
"+ ans += score[T[i]]",
"+ for i in range(K, N):",
"+ if T[i - K] == T[i]:",
"+ T[i] = \" \"",
"+ continue",
"+ ans += score[T[i]]",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
]
| false | 0.008304 | 0.041905 | 0.198163 | [
"s285003026",
"s225328890"
]
|
u192154323 | p03339 | python | s330241451 | s327224680 | 463 | 296 | 33,976 | 17,612 | Accepted | Accepted | 36.07 | n = int(eval(input()))
s = eval(input())
W_csum = [0] * n
E_csum = [0] * n
if s[0] == 'W':
W_csum[0] = 1
else:
E_csum[0] = 1
for i in range(1,n):
if s[i] == 'W':
W_csum[i] = W_csum[i-1] + 1
E_csum[i] = E_csum[i-1]
else:
W_csum[i] = W_csum[i-1]
E_csum[i] = E_csum[i-1] + 1
W_csum_r = [0] * n
E_csum_r = [0] * n
if s[-1] == 'W':
W_csum_r[0] = 1
else:
E_csum_r[0] = 1
for i,j in enumerate(list(range(n-2,-1,-1)),1):
if s[j] == 'W':
W_csum_r[i] = W_csum_r[i-1] + 1
E_csum_r[i] = E_csum_r[i-1]
else:
W_csum_r[i] = W_csum_r[i-1]
E_csum_r[i] = E_csum_r[i-1] + 1
W_csum_r.reverse()
E_csum_r.reverse()
ans = float('inf')
for i in range(1,n-1):
num = 0
if s[i] == 'W':
num += E_csum_r[i+1]
num += W_csum[i-1]
else:
num += E_csum_r[i+1]
num += W_csum[i-1]
if num < ans:
ans = num
if ans > E_csum_r[1]:
ans = E_csum_r[1]
if ans > W_csum[-2]:
ans = W_csum[-2]
print(ans)
| n = int(eval(input()))
s = eval(input())
W_csum = [0] * (n+1)
E_csum = [0] * (n+1)
for i in range(n):
if s[i] == 'W':
W_csum[i+1] = W_csum[i] + 1
E_csum[i+1] = E_csum[i]
else:
W_csum[i+1] = W_csum[i]
E_csum[i+1] = E_csum[i] + 1
E_csum.append(E_csum[-1])
ans = float('inf')
for i in range(1,n+1):
count = 0
count += W_csum[i-1]
count += E_csum[-1] - E_csum[i]
if count < ans:
ans = count
print(ans) | 54 | 22 | 1,065 | 473 | n = int(eval(input()))
s = eval(input())
W_csum = [0] * n
E_csum = [0] * n
if s[0] == "W":
W_csum[0] = 1
else:
E_csum[0] = 1
for i in range(1, n):
if s[i] == "W":
W_csum[i] = W_csum[i - 1] + 1
E_csum[i] = E_csum[i - 1]
else:
W_csum[i] = W_csum[i - 1]
E_csum[i] = E_csum[i - 1] + 1
W_csum_r = [0] * n
E_csum_r = [0] * n
if s[-1] == "W":
W_csum_r[0] = 1
else:
E_csum_r[0] = 1
for i, j in enumerate(list(range(n - 2, -1, -1)), 1):
if s[j] == "W":
W_csum_r[i] = W_csum_r[i - 1] + 1
E_csum_r[i] = E_csum_r[i - 1]
else:
W_csum_r[i] = W_csum_r[i - 1]
E_csum_r[i] = E_csum_r[i - 1] + 1
W_csum_r.reverse()
E_csum_r.reverse()
ans = float("inf")
for i in range(1, n - 1):
num = 0
if s[i] == "W":
num += E_csum_r[i + 1]
num += W_csum[i - 1]
else:
num += E_csum_r[i + 1]
num += W_csum[i - 1]
if num < ans:
ans = num
if ans > E_csum_r[1]:
ans = E_csum_r[1]
if ans > W_csum[-2]:
ans = W_csum[-2]
print(ans)
| n = int(eval(input()))
s = eval(input())
W_csum = [0] * (n + 1)
E_csum = [0] * (n + 1)
for i in range(n):
if s[i] == "W":
W_csum[i + 1] = W_csum[i] + 1
E_csum[i + 1] = E_csum[i]
else:
W_csum[i + 1] = W_csum[i]
E_csum[i + 1] = E_csum[i] + 1
E_csum.append(E_csum[-1])
ans = float("inf")
for i in range(1, n + 1):
count = 0
count += W_csum[i - 1]
count += E_csum[-1] - E_csum[i]
if count < ans:
ans = count
print(ans)
| false | 59.259259 | [
"-W_csum = [0] * n",
"-E_csum = [0] * n",
"-if s[0] == \"W\":",
"- W_csum[0] = 1",
"-else:",
"- E_csum[0] = 1",
"-for i in range(1, n):",
"+W_csum = [0] * (n + 1)",
"+E_csum = [0] * (n + 1)",
"+for i in range(n):",
"- W_csum[i] = W_csum[i - 1] + 1",
"- E_csum[i] = E_csum[i - 1]",
"+ W_csum[i + 1] = W_csum[i] + 1",
"+ E_csum[i + 1] = E_csum[i]",
"- W_csum[i] = W_csum[i - 1]",
"- E_csum[i] = E_csum[i - 1] + 1",
"-W_csum_r = [0] * n",
"-E_csum_r = [0] * n",
"-if s[-1] == \"W\":",
"- W_csum_r[0] = 1",
"-else:",
"- E_csum_r[0] = 1",
"-for i, j in enumerate(list(range(n - 2, -1, -1)), 1):",
"- if s[j] == \"W\":",
"- W_csum_r[i] = W_csum_r[i - 1] + 1",
"- E_csum_r[i] = E_csum_r[i - 1]",
"- else:",
"- W_csum_r[i] = W_csum_r[i - 1]",
"- E_csum_r[i] = E_csum_r[i - 1] + 1",
"-W_csum_r.reverse()",
"-E_csum_r.reverse()",
"+ W_csum[i + 1] = W_csum[i]",
"+ E_csum[i + 1] = E_csum[i] + 1",
"+E_csum.append(E_csum[-1])",
"-for i in range(1, n - 1):",
"- num = 0",
"- if s[i] == \"W\":",
"- num += E_csum_r[i + 1]",
"- num += W_csum[i - 1]",
"- else:",
"- num += E_csum_r[i + 1]",
"- num += W_csum[i - 1]",
"- if num < ans:",
"- ans = num",
"-if ans > E_csum_r[1]:",
"- ans = E_csum_r[1]",
"-if ans > W_csum[-2]:",
"- ans = W_csum[-2]",
"+for i in range(1, n + 1):",
"+ count = 0",
"+ count += W_csum[i - 1]",
"+ count += E_csum[-1] - E_csum[i]",
"+ if count < ans:",
"+ ans = count"
]
| false | 0.088691 | 0.045997 | 1.928214 | [
"s330241451",
"s327224680"
]
|
u054871430 | p02695 | python | s212189224 | s438971869 | 288 | 170 | 119,560 | 84,592 | Accepted | Accepted | 40.97 | import sys
import copy
from collections import deque
def main():
N, M, Q = list(map(int, input().split()))
ABCD = [[int(_) for _ in input().split()] for i in range(Q)]
seq_list = make_sequence(N, M)
max_score = 0
for i_seq in seq_list:
score = 0
for a, b, c, d in ABCD:
if (i_seq[b-1] - i_seq[a-1]) == c:
score += d
max_score = max(max_score, score)
print(max_score)
return
def make_sequence(N, M):
seq_list = []
sequence = [-1] * N
seq_deque = deque()
now_ele = 0
for i in range(M):
sequence[0] = i
now_seq = copy.copy(sequence)
seq_deque.append([now_ele, now_seq])
while len(seq_deque) > 0:
pre_ele ,pre_seq = seq_deque.popleft()
if pre_seq[-1] != -1:
seq_list.append(pre_seq)
continue
end_ele = M - sum(pre_seq[0:pre_ele+1])
for i in range(end_ele):
pre_seq[pre_ele+1] = i
now_seq = copy.copy(pre_seq)
seq_deque.append([pre_ele+1 ,now_seq])
for i_seq in seq_list:
now_value = 1
for i, i_value in enumerate(i_seq):
now_value += i_value
i_seq[i] = now_value
return seq_list
if __name__ == '__main__':
main()
sys.exit(0) | import sys
import itertools
def main():
N, M, Q = list(map(int, input().split()))
ABCD = [[int(_) for _ in input().split()] for i in range(Q)]
value_range = list(range(1, M+1))
seq_list = list(itertools.combinations_with_replacement(value_range, N))
max_score = 0
for i_seq in seq_list:
score = 0
for a, b, c, d in ABCD:
if (i_seq[b-1] - i_seq[a-1]) == c:
score += d
max_score = max(max_score, score)
print(max_score)
return
if __name__ == '__main__':
main()
sys.exit(0) | 59 | 24 | 1,375 | 584 | import sys
import copy
from collections import deque
def main():
N, M, Q = list(map(int, input().split()))
ABCD = [[int(_) for _ in input().split()] for i in range(Q)]
seq_list = make_sequence(N, M)
max_score = 0
for i_seq in seq_list:
score = 0
for a, b, c, d in ABCD:
if (i_seq[b - 1] - i_seq[a - 1]) == c:
score += d
max_score = max(max_score, score)
print(max_score)
return
def make_sequence(N, M):
seq_list = []
sequence = [-1] * N
seq_deque = deque()
now_ele = 0
for i in range(M):
sequence[0] = i
now_seq = copy.copy(sequence)
seq_deque.append([now_ele, now_seq])
while len(seq_deque) > 0:
pre_ele, pre_seq = seq_deque.popleft()
if pre_seq[-1] != -1:
seq_list.append(pre_seq)
continue
end_ele = M - sum(pre_seq[0 : pre_ele + 1])
for i in range(end_ele):
pre_seq[pre_ele + 1] = i
now_seq = copy.copy(pre_seq)
seq_deque.append([pre_ele + 1, now_seq])
for i_seq in seq_list:
now_value = 1
for i, i_value in enumerate(i_seq):
now_value += i_value
i_seq[i] = now_value
return seq_list
if __name__ == "__main__":
main()
sys.exit(0)
| import sys
import itertools
def main():
N, M, Q = list(map(int, input().split()))
ABCD = [[int(_) for _ in input().split()] for i in range(Q)]
value_range = list(range(1, M + 1))
seq_list = list(itertools.combinations_with_replacement(value_range, N))
max_score = 0
for i_seq in seq_list:
score = 0
for a, b, c, d in ABCD:
if (i_seq[b - 1] - i_seq[a - 1]) == c:
score += d
max_score = max(max_score, score)
print(max_score)
return
if __name__ == "__main__":
main()
sys.exit(0)
| false | 59.322034 | [
"-import copy",
"-from collections import deque",
"+import itertools",
"- seq_list = make_sequence(N, M)",
"+ value_range = list(range(1, M + 1))",
"+ seq_list = list(itertools.combinations_with_replacement(value_range, N))",
"-def make_sequence(N, M):",
"- seq_list = []",
"- sequence = [-1] * N",
"- seq_deque = deque()",
"- now_ele = 0",
"- for i in range(M):",
"- sequence[0] = i",
"- now_seq = copy.copy(sequence)",
"- seq_deque.append([now_ele, now_seq])",
"- while len(seq_deque) > 0:",
"- pre_ele, pre_seq = seq_deque.popleft()",
"- if pre_seq[-1] != -1:",
"- seq_list.append(pre_seq)",
"- continue",
"- end_ele = M - sum(pre_seq[0 : pre_ele + 1])",
"- for i in range(end_ele):",
"- pre_seq[pre_ele + 1] = i",
"- now_seq = copy.copy(pre_seq)",
"- seq_deque.append([pre_ele + 1, now_seq])",
"- for i_seq in seq_list:",
"- now_value = 1",
"- for i, i_value in enumerate(i_seq):",
"- now_value += i_value",
"- i_seq[i] = now_value",
"- return seq_list",
"-",
"-"
]
| false | 0.104642 | 0.062675 | 1.669588 | [
"s212189224",
"s438971869"
]
|
u780962115 | p02754 | python | s200681922 | s704388392 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | n,a,b=list(map(int,input().split()))
K=n//(a+b)
J=n%(a+b)
if J<=a:
print((K*a+J))
else:
print((K*a+a)) | n,a,b=list(map(int,input().split()))
print((a*(n//(a+b))+min(a,n%(a+b))))
| 7 | 3 | 106 | 69 | n, a, b = list(map(int, input().split()))
K = n // (a + b)
J = n % (a + b)
if J <= a:
print((K * a + J))
else:
print((K * a + a))
| n, a, b = list(map(int, input().split()))
print((a * (n // (a + b)) + min(a, n % (a + b))))
| false | 57.142857 | [
"-K = n // (a + b)",
"-J = n % (a + b)",
"-if J <= a:",
"- print((K * a + J))",
"-else:",
"- print((K * a + a))",
"+print((a * (n // (a + b)) + min(a, n % (a + b))))"
]
| false | 0.042779 | 0.043429 | 0.985025 | [
"s200681922",
"s704388392"
]
|
u506858457 | p02995 | python | s247649334 | s450671703 | 20 | 18 | 3,064 | 3,064 | Accepted | Accepted | 10 | #@k0gane_p
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
while y:
x,y = y, x%y
return x
def lcm(x,y):#最小公倍数
return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
D=A//B
E=A//C
F=A // lcm(B,C)
return A-D-E+F
ans = count(b, c, d) - count(a, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
if(a % c != 0 and a % d != 0):
ans += 1#AがCでもDでも割り切れないなら、足す1
print(ans) | #@k0gane_p
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
while y:
x,y = y, x%y
return x
def lcm(x,y):#最小公倍数
return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
D=A//B
E=A//C
F=A // lcm(B,C)
return A-D-E+F
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#if(a % c != 0 and a % d != 0):
#ans += 1#AがCでもDでも割り切れないなら、足す1
print(ans) | 18 | 18 | 435 | 439 | # @k0gane_p
a, b, c, d = [int(i) for i in input().split()]
def gcd(x, y): # 最大公約数
while y:
x, y = y, x % y
return x
def lcm(x, y): # 最小公倍数
return x * y // gcd(x, y)
def count(A, B, C): # A以下で、BでもCでも割り切れない個数
D = A // B
E = A // C
F = A // lcm(B, C)
return A - D - E + F
ans = count(b, c, d) - count(a, c, d)
# A以上B以下の整数のうち、CでもDでも割り切れないものの個数
if a % c != 0 and a % d != 0:
ans += 1 # AがCでもDでも割り切れないなら、足す1
print(ans)
| # @k0gane_p
a, b, c, d = [int(i) for i in input().split()]
def gcd(x, y): # 最大公約数
while y:
x, y = y, x % y
return x
def lcm(x, y): # 最小公倍数
return x * y // gcd(x, y)
def count(A, B, C): # A以下で、BでもCでも割り切れない個数
D = A // B
E = A // C
F = A // lcm(B, C)
return A - D - E + F
ans = count(b, c, d) - count(a - 1, c, d)
# A以上B以下の整数のうち、CでもDでも割り切れないものの個数
# if(a % c != 0 and a % d != 0):
# ans += 1#AがCでもDでも割り切れないなら、足す1
print(ans)
| false | 0 | [
"-ans = count(b, c, d) - count(a, c, d)",
"+ans = count(b, c, d) - count(a - 1, c, d)",
"-if a % c != 0 and a % d != 0:",
"- ans += 1 # AがCでもDでも割り切れないなら、足す1",
"+# if(a % c != 0 and a % d != 0):",
"+# ans += 1#AがCでもDでも割り切れないなら、足す1"
]
| false | 0.044412 | 0.04604 | 0.964635 | [
"s247649334",
"s450671703"
]
|
u522945737 | p02660 | python | s432889189 | s384458361 | 195 | 117 | 27,172 | 9,416 | Accepted | Accepted | 40 | import numpy as np
import math
def fuctrization(n):
arr = []
tmp = n
for i in range(2,math.ceil(n**(1/2))+1):
if tmp%i==0:
j = 0
while tmp%i==0:
j += 1
tmp //= i
arr.append([i,j])
if tmp != 1:
arr.append([tmp,1])
if arr:
pass
else:
arr.append([n,1])
return arr
n = int(eval(input()))
if n == 1:
print((0))
else:
arr = fuctrization(n)
nn = 0
for i in range(len(arr)):
k = arr[i][1]
nnn = 1
while k-nnn>=0:
k -= nnn
nnn += 1
nn +=1
print(nn)
| import sys
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
N = int(eval(input()))
if N == 1:
print((0))
sys.exit()
a = factorization(N)
ans = 0
for i in range(len(a)):
k = a[i][1]
cnt = 1
while k-cnt>=0:
k -= cnt
cnt += 1
ans += cnt-1
print(ans) | 38 | 37 | 722 | 629 | import numpy as np
import math
def fuctrization(n):
arr = []
tmp = n
for i in range(2, math.ceil(n ** (1 / 2)) + 1):
if tmp % i == 0:
j = 0
while tmp % i == 0:
j += 1
tmp //= i
arr.append([i, j])
if tmp != 1:
arr.append([tmp, 1])
if arr:
pass
else:
arr.append([n, 1])
return arr
n = int(eval(input()))
if n == 1:
print((0))
else:
arr = fuctrization(n)
nn = 0
for i in range(len(arr)):
k = arr[i][1]
nnn = 1
while k - nnn >= 0:
k -= nnn
nnn += 1
nn += 1
print(nn)
| import sys
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
N = int(eval(input()))
if N == 1:
print((0))
sys.exit()
a = factorization(N)
ans = 0
for i in range(len(a)):
k = a[i][1]
cnt = 1
while k - cnt >= 0:
k -= cnt
cnt += 1
ans += cnt - 1
print(ans)
| false | 2.631579 | [
"-import numpy as np",
"-import math",
"+import sys",
"-def fuctrization(n):",
"+def factorization(n):",
"- tmp = n",
"- for i in range(2, math.ceil(n ** (1 / 2)) + 1):",
"- if tmp % i == 0:",
"- j = 0",
"- while tmp % i == 0:",
"- j += 1",
"- tmp //= i",
"- arr.append([i, j])",
"- if tmp != 1:",
"- arr.append([tmp, 1])",
"- if arr:",
"- pass",
"- else:",
"+ temp = n",
"+ for i in range(2, int(-(-(n**0.5) // 1)) + 1):",
"+ if temp % i == 0:",
"+ cnt = 0",
"+ while temp % i == 0:",
"+ cnt += 1",
"+ temp //= i",
"+ arr.append([i, cnt])",
"+ if temp != 1:",
"+ arr.append([temp, 1])",
"+ if arr == []:",
"-n = int(eval(input()))",
"-if n == 1:",
"+N = int(eval(input()))",
"+if N == 1:",
"-else:",
"- arr = fuctrization(n)",
"- nn = 0",
"- for i in range(len(arr)):",
"- k = arr[i][1]",
"- nnn = 1",
"- while k - nnn >= 0:",
"- k -= nnn",
"- nnn += 1",
"- nn += 1",
"- print(nn)",
"+ sys.exit()",
"+a = factorization(N)",
"+ans = 0",
"+for i in range(len(a)):",
"+ k = a[i][1]",
"+ cnt = 1",
"+ while k - cnt >= 0:",
"+ k -= cnt",
"+ cnt += 1",
"+ ans += cnt - 1",
"+print(ans)"
]
| false | 0.145536 | 0.059329 | 2.453037 | [
"s432889189",
"s384458361"
]
|
u606146341 | p02731 | python | s308842186 | s815389918 | 34 | 18 | 5,204 | 3,060 | Accepted | Accepted | 47.06 | from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
L =int(eval(input()))
ans = Decimal((L/3)**3)
print((float(round(ans, 10)))) | L = float(eval(input()))
ans = float((L/3)**3)
print(ans) | 7 | 5 | 137 | 57 | from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
L = int(eval(input()))
ans = Decimal((L / 3) ** 3)
print((float(round(ans, 10))))
| L = float(eval(input()))
ans = float((L / 3) ** 3)
print(ans)
| false | 28.571429 | [
"-from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN",
"-",
"-L = int(eval(input()))",
"-ans = Decimal((L / 3) ** 3)",
"-print((float(round(ans, 10))))",
"+L = float(eval(input()))",
"+ans = float((L / 3) ** 3)",
"+print(ans)"
]
| false | 0.042723 | 0.083066 | 0.51433 | [
"s308842186",
"s815389918"
]
|
u503111914 | p03523 | python | s944096142 | s001029482 | 31 | 26 | 8,968 | 9,076 | Accepted | Accepted | 16.13 | S=eval(input())
pos={"AKIHABARA","KIHABARA","AKIHBARA","KIHBARA","AKIHABRA","KIHABRA","AKIHBRA","KIHBRA","AKIHABAR","KIHABAR","AKIHBAR","KIHBAR","AKIHABR","KIHABR","AKIHBR","KIHBR"}
if S in pos:
print("YES")
else:
print("NO")
| S=eval(input())
A = ["AKIHABARA","KIHABARA","AKIHBARA","KIHBARA","AKIHABRA","KIHABRA","AKIHBRA","KIHBRA","AKIHABAR","KIHABAR","AKIHBAR","KIHBAR","AKIHABR","KIHABR","AKIHBR","KIHBR"]
print(("YES" if A.count(S)>=1 else "NO")) | 8 | 3 | 238 | 222 | S = eval(input())
pos = {
"AKIHABARA",
"KIHABARA",
"AKIHBARA",
"KIHBARA",
"AKIHABRA",
"KIHABRA",
"AKIHBRA",
"KIHBRA",
"AKIHABAR",
"KIHABAR",
"AKIHBAR",
"KIHBAR",
"AKIHABR",
"KIHABR",
"AKIHBR",
"KIHBR",
}
if S in pos:
print("YES")
else:
print("NO")
| S = eval(input())
A = [
"AKIHABARA",
"KIHABARA",
"AKIHBARA",
"KIHBARA",
"AKIHABRA",
"KIHABRA",
"AKIHBRA",
"KIHBRA",
"AKIHABAR",
"KIHABAR",
"AKIHBAR",
"KIHBAR",
"AKIHABR",
"KIHABR",
"AKIHBR",
"KIHBR",
]
print(("YES" if A.count(S) >= 1 else "NO"))
| false | 62.5 | [
"-pos = {",
"+A = [",
"-}",
"-if S in pos:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+]",
"+print((\"YES\" if A.count(S) >= 1 else \"NO\"))"
]
| false | 0.1404 | 0.048008 | 2.924536 | [
"s944096142",
"s001029482"
]
|
u729133443 | p03401 | python | s765540734 | s199748541 | 388 | 175 | 67,288 | 13,800 | Accepted | Accepted | 54.9 | n,*a=list(map(int,open(0).read().split()))
a=[0]+a+[0]
A=abs
c=sum(A(j-i)for i,j in zip(a,a[1:]))
for i,j,k in zip(a,a[1:],a[2:]):print((c-A(j-i)-A(k-j)+A(k-i))) | _,a=open(0)
a=[0]+list(map(int,a.split()))+[0]
A=abs
c=sum(A(j-i)for i,j in zip(a,a[1:]))
for i,j,k in zip(a,a[1:],a[2:]):print((c-A(j-i)-A(k-j)+A(k-i))) | 5 | 5 | 157 | 155 | n, *a = list(map(int, open(0).read().split()))
a = [0] + a + [0]
A = abs
c = sum(A(j - i) for i, j in zip(a, a[1:]))
for i, j, k in zip(a, a[1:], a[2:]):
print((c - A(j - i) - A(k - j) + A(k - i)))
| _, a = open(0)
a = [0] + list(map(int, a.split())) + [0]
A = abs
c = sum(A(j - i) for i, j in zip(a, a[1:]))
for i, j, k in zip(a, a[1:], a[2:]):
print((c - A(j - i) - A(k - j) + A(k - i)))
| false | 0 | [
"-n, *a = list(map(int, open(0).read().split()))",
"-a = [0] + a + [0]",
"+_, a = open(0)",
"+a = [0] + list(map(int, a.split())) + [0]"
]
| false | 0.0852 | 0.108805 | 0.78305 | [
"s765540734",
"s199748541"
]
|
u400765446 | p02384 | python | s180044457 | s048084139 | 40 | 20 | 8,192 | 5,592 | Accepted | Accepted | 50 | class Dice:
def __init__(self):
# 初期値がない場合
# 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
self.t = 1
self.s = 2
self.e = 3
self.w = 4
self.n = 5
self.b = 6
self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}
def __init__(self, t, s, e, w, n, b):
# 初期値が指定される場合
self.t = t
self.s = s
self.e = e
self.w = w
self.n = n
self.b = b
self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}
def rot(self, way):
if way == 0:
self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
elif way == 1:
self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
elif way == 2:
self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
elif way == 3:
self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
def main():
import random
t,s,e,w,n,b = list(map(int, input().split()))
dice2 = Dice(t,s,e,w,n,b)
q = int(eval(input()))
for _ in range(q):
top, front = list(map(int, input().split()))
while True:
if dice2.t == top and dice2.s == front:
break
else:
seed = random.randint(0, 3)
dice2.rot(seed)
print((dice2.e))
if __name__ == '__main__':
main()
| rot_set = [
(1,2,4,3,1), #0
(0,3,5,2,0), #1
(0,1,5,4,0), #2
(0,4,5,1,0), #3
(0,2,5,3,0), #4
(1,3,4,2,1) #5
]
dice_int = list(map(int, input().split()))
q = int(eval(input()))
right_face = []
for _ in range(q):
a, b = list(map(int, input().split()))
a_idx = dice_int.index(a)
b_idx = dice_int.index(b)
for i in range(6):
for j in range(4):
if (a_idx, b_idx) == (rot_set[i][j], rot_set[i][j+1]):
right_face.append(dice_int[i])
for i in range(q):
print((right_face[i]))
| 55 | 25 | 1,576 | 562 | class Dice:
def __init__(self):
# 初期値がない場合
# 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
self.t = 1
self.s = 2
self.e = 3
self.w = 4
self.n = 5
self.b = 6
self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}
def __init__(self, t, s, e, w, n, b):
# 初期値が指定される場合
self.t = t
self.s = s
self.e = e
self.w = w
self.n = n
self.b = b
self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}
def rot(self, way):
if way == 0:
self.t, self.s, self.e, self.w, self.n, self.b = (
self.n,
self.t,
self.e,
self.w,
self.b,
self.s,
)
elif way == 1:
self.t, self.s, self.e, self.w, self.n, self.b = (
self.s,
self.b,
self.e,
self.w,
self.t,
self.n,
)
elif way == 2:
self.t, self.s, self.e, self.w, self.n, self.b = (
self.w,
self.s,
self.t,
self.b,
self.n,
self.e,
)
elif way == 3:
self.t, self.s, self.e, self.w, self.n, self.b = (
self.e,
self.s,
self.b,
self.t,
self.n,
self.w,
)
def main():
import random
t, s, e, w, n, b = list(map(int, input().split()))
dice2 = Dice(t, s, e, w, n, b)
q = int(eval(input()))
for _ in range(q):
top, front = list(map(int, input().split()))
while True:
if dice2.t == top and dice2.s == front:
break
else:
seed = random.randint(0, 3)
dice2.rot(seed)
print((dice2.e))
if __name__ == "__main__":
main()
| rot_set = [
(1, 2, 4, 3, 1), # 0
(0, 3, 5, 2, 0), # 1
(0, 1, 5, 4, 0), # 2
(0, 4, 5, 1, 0), # 3
(0, 2, 5, 3, 0), # 4
(1, 3, 4, 2, 1), # 5
]
dice_int = list(map(int, input().split()))
q = int(eval(input()))
right_face = []
for _ in range(q):
a, b = list(map(int, input().split()))
a_idx = dice_int.index(a)
b_idx = dice_int.index(b)
for i in range(6):
for j in range(4):
if (a_idx, b_idx) == (rot_set[i][j], rot_set[i][j + 1]):
right_face.append(dice_int[i])
for i in range(q):
print((right_face[i]))
| false | 54.545455 | [
"-class Dice:",
"- def __init__(self):",
"- # 初期値がない場合",
"- # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定",
"- self.t = 1",
"- self.s = 2",
"- self.e = 3",
"- self.w = 4",
"- self.n = 5",
"- self.b = 6",
"- self.rotway = {\"S\": 0, \"N\": 1, \"E\": 2, \"W\": 3}",
"-",
"- def __init__(self, t, s, e, w, n, b):",
"- # 初期値が指定される場合",
"- self.t = t",
"- self.s = s",
"- self.e = e",
"- self.w = w",
"- self.n = n",
"- self.b = b",
"- self.rotway = {\"S\": 0, \"N\": 1, \"E\": 2, \"W\": 3}",
"-",
"- def rot(self, way):",
"- if way == 0:",
"- self.t, self.s, self.e, self.w, self.n, self.b = (",
"- self.n,",
"- self.t,",
"- self.e,",
"- self.w,",
"- self.b,",
"- self.s,",
"- )",
"- elif way == 1:",
"- self.t, self.s, self.e, self.w, self.n, self.b = (",
"- self.s,",
"- self.b,",
"- self.e,",
"- self.w,",
"- self.t,",
"- self.n,",
"- )",
"- elif way == 2:",
"- self.t, self.s, self.e, self.w, self.n, self.b = (",
"- self.w,",
"- self.s,",
"- self.t,",
"- self.b,",
"- self.n,",
"- self.e,",
"- )",
"- elif way == 3:",
"- self.t, self.s, self.e, self.w, self.n, self.b = (",
"- self.e,",
"- self.s,",
"- self.b,",
"- self.t,",
"- self.n,",
"- self.w,",
"- )",
"-",
"-",
"-def main():",
"- import random",
"-",
"- t, s, e, w, n, b = list(map(int, input().split()))",
"- dice2 = Dice(t, s, e, w, n, b)",
"- q = int(eval(input()))",
"- for _ in range(q):",
"- top, front = list(map(int, input().split()))",
"- while True:",
"- if dice2.t == top and dice2.s == front:",
"- break",
"- else:",
"- seed = random.randint(0, 3)",
"- dice2.rot(seed)",
"- print((dice2.e))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+rot_set = [",
"+ (1, 2, 4, 3, 1), # 0",
"+ (0, 3, 5, 2, 0), # 1",
"+ (0, 1, 5, 4, 0), # 2",
"+ (0, 4, 5, 1, 0), # 3",
"+ (0, 2, 5, 3, 0), # 4",
"+ (1, 3, 4, 2, 1), # 5",
"+]",
"+dice_int = list(map(int, input().split()))",
"+q = int(eval(input()))",
"+right_face = []",
"+for _ in range(q):",
"+ a, b = list(map(int, input().split()))",
"+ a_idx = dice_int.index(a)",
"+ b_idx = dice_int.index(b)",
"+ for i in range(6):",
"+ for j in range(4):",
"+ if (a_idx, b_idx) == (rot_set[i][j], rot_set[i][j + 1]):",
"+ right_face.append(dice_int[i])",
"+for i in range(q):",
"+ print((right_face[i]))"
]
| false | 0.049979 | 0.008478 | 5.89501 | [
"s180044457",
"s048084139"
]
|
u503263570 | p00554 | python | s366933068 | s932765229 | 40 | 30 | 7,900 | 7,888 | Accepted | Accepted | 25 | n,m=list(map(int,input().split()))
p=[list(map(int,input().split()))for i in range(m)]
c=[]
for i in p:
a,b=i
if a>=n:o=0
else:o=n-a
c.append(o)
c.sort()
c.pop()
print((sum(c))) | n,m=list(map(int,input().split()))
p=[list(map(int,input().split()))for i in range(m)]
c=[n-a if n>a else 0for a,b in p]
print((sum(c)-max(c))) | 11 | 4 | 183 | 138 | n, m = list(map(int, input().split()))
p = [list(map(int, input().split())) for i in range(m)]
c = []
for i in p:
a, b = i
if a >= n:
o = 0
else:
o = n - a
c.append(o)
c.sort()
c.pop()
print((sum(c)))
| n, m = list(map(int, input().split()))
p = [list(map(int, input().split())) for i in range(m)]
c = [n - a if n > a else 0 for a, b in p]
print((sum(c) - max(c)))
| false | 63.636364 | [
"-c = []",
"-for i in p:",
"- a, b = i",
"- if a >= n:",
"- o = 0",
"- else:",
"- o = n - a",
"- c.append(o)",
"-c.sort()",
"-c.pop()",
"-print((sum(c)))",
"+c = [n - a if n > a else 0 for a, b in p]",
"+print((sum(c) - max(c)))"
]
| false | 0.048573 | 0.045711 | 1.062604 | [
"s366933068",
"s932765229"
]
|
u225388820 | p03171 | python | s378104162 | s198621485 | 263 | 222 | 41,580 | 39,664 | Accepted | Accepted | 15.59 | import sys
input = sys.stdin.readline
n=int(eval(input()))
a=list(map(int,input().split()))
dp=[0]*3000
for i in range(n):
dp[i]=a[i]
for i in range(1,n):
for j in range(i-1,-1,-1):
dp[j]=max(a[i]-dp[j],a[j]-dp[j+1])
print((dp[0])) | def solve():
import sys
input = sys.stdin.readline
n=int(eval(input()))
a=list(map(int,input().split()))
dp=a[:]
for i in range(1,n):
for j in range(i-1,-1,-1):
dp[j]=max(a[i]-dp[j],a[j]-dp[j+1])
print((dp[0]))
solve() | 11 | 11 | 249 | 268 | import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
dp = [0] * 3000
for i in range(n):
dp[i] = a[i]
for i in range(1, n):
for j in range(i - 1, -1, -1):
dp[j] = max(a[i] - dp[j], a[j] - dp[j + 1])
print((dp[0]))
| def solve():
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
dp = a[:]
for i in range(1, n):
for j in range(i - 1, -1, -1):
dp[j] = max(a[i] - dp[j], a[j] - dp[j + 1])
print((dp[0]))
solve()
| false | 0 | [
"-import sys",
"+def solve():",
"+ import sys",
"-input = sys.stdin.readline",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-dp = [0] * 3000",
"-for i in range(n):",
"- dp[i] = a[i]",
"-for i in range(1, n):",
"- for j in range(i - 1, -1, -1):",
"- dp[j] = max(a[i] - dp[j], a[j] - dp[j + 1])",
"-print((dp[0]))",
"+ input = sys.stdin.readline",
"+ n = int(eval(input()))",
"+ a = list(map(int, input().split()))",
"+ dp = a[:]",
"+ for i in range(1, n):",
"+ for j in range(i - 1, -1, -1):",
"+ dp[j] = max(a[i] - dp[j], a[j] - dp[j + 1])",
"+ print((dp[0]))",
"+",
"+",
"+solve()"
]
| false | 0.052376 | 0.036213 | 1.446351 | [
"s378104162",
"s198621485"
]
|
u055875839 | p02727 | python | s310625720 | s580093730 | 393 | 303 | 22,556 | 22,520 | Accepted | Accepted | 22.9 | import heapq
x, y, a, b, c = list(map(int, input().split()))
def max_listup(limit):
l = list([int(x)*-1 for x in input().split()])
heapq.heapify(l)
cnt = 1
res = []
while l:
if cnt > limit:
break
m = heapq.heappop(l)
res.append(m*-1)
cnt += 1
return res
if __name__ == "__main__":
all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
ans = 0
for _ in range(x+y):
ans += all.pop()
print(ans)
| import heapq
x, y, a, b, c = list(map(int, input().split()))
def max_listup(limit):
l = sorted(list(map(int, input().split())))
cnt = 1
res = []
while l:
if cnt > limit:
break
m = l.pop()
res.append(m)
cnt += 1
return res
if __name__ == "__main__":
all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
ans = 0
for _ in range(x+y):
ans += all.pop()
print(ans)
| 24 | 23 | 487 | 448 | import heapq
x, y, a, b, c = list(map(int, input().split()))
def max_listup(limit):
l = list([int(x) * -1 for x in input().split()])
heapq.heapify(l)
cnt = 1
res = []
while l:
if cnt > limit:
break
m = heapq.heappop(l)
res.append(m * -1)
cnt += 1
return res
if __name__ == "__main__":
all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
ans = 0
for _ in range(x + y):
ans += all.pop()
print(ans)
| import heapq
x, y, a, b, c = list(map(int, input().split()))
def max_listup(limit):
l = sorted(list(map(int, input().split())))
cnt = 1
res = []
while l:
if cnt > limit:
break
m = l.pop()
res.append(m)
cnt += 1
return res
if __name__ == "__main__":
all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
ans = 0
for _ in range(x + y):
ans += all.pop()
print(ans)
| false | 4.166667 | [
"- l = list([int(x) * -1 for x in input().split()])",
"- heapq.heapify(l)",
"+ l = sorted(list(map(int, input().split())))",
"- m = heapq.heappop(l)",
"- res.append(m * -1)",
"+ m = l.pop()",
"+ res.append(m)"
]
| false | 0.044677 | 0.109705 | 0.40725 | [
"s310625720",
"s580093730"
]
|
u697696097 | p02762 | python | s745063048 | s300573930 | 881 | 781 | 7,188 | 17,096 | Accepted | Accepted | 11.35 | import sys
#from io import StringIO
#import unittest
class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if(x == y):
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif(self.rnk[x] > self.rnk[y]):
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if(self.rnk[x] == self.rnk[y]):
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
def resolve():
int1 = lambda x: int(x) - 1
readline=sys.stdin.readline
n,m,k=map(int, readline().strip().split())
uf = UnionFind(n)
exc=[0]*n
for i in range(m):
a,b=map(int1, readline().strip().split())
uf.Unite(a,b)
exc[a]+=1
exc[b]+=1
for i in range(k):
a,b=map(int1, readline().strip().split())
if uf.isSameGroup(a,b):
exc[a]+=1
exc[b]+=1
rescnt=[]
for i in range(n):
#ri=uf.Count(i)-1-exc[i]
#rescnt.append(str(ri))
if i==(n-1):
print(uf.Count(i)-1-exc[i])
else:
print(uf.Count(i)-1-exc[i],end=" ")
#print(" ".join(rescnt),end="")
resolve()
| import sys
from io import StringIO
import unittest
class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if(x == y):
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif(self.rnk[x] > self.rnk[y]):
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if(self.rnk[x] == self.rnk[y]):
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
def resolve():
int1 = lambda x: int(x) - 1
readline=sys.stdin.readline
n,m,k=list(map(int, readline().strip().split()))
uf = UnionFind(n)
exc=[0]*n
for i in range(m):
a,b=list(map(int1, readline().strip().split()))
uf.Unite(a,b)
exc[a]+=1
exc[b]+=1
for i in range(k):
a,b=list(map(int1, readline().strip().split()))
if uf.isSameGroup(a,b):
exc[a]+=1
exc[b]+=1
rescnt=[]
for i in range(n):
ri=uf.Count(i)-1-exc[i]
rescnt.append(str(ri))
print((" ".join(rescnt)))
resolve() | 85 | 81 | 2,153 | 2,010 | import sys
# from io import StringIO
# import unittest
class UnionFind:
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1] * (n + 1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0] * (n + 1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if x == y:
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
def resolve():
int1 = lambda x: int(x) - 1
readline = sys.stdin.readline
n, m, k = map(int, readline().strip().split())
uf = UnionFind(n)
exc = [0] * n
for i in range(m):
a, b = map(int1, readline().strip().split())
uf.Unite(a, b)
exc[a] += 1
exc[b] += 1
for i in range(k):
a, b = map(int1, readline().strip().split())
if uf.isSameGroup(a, b):
exc[a] += 1
exc[b] += 1
rescnt = []
for i in range(n):
# ri=uf.Count(i)-1-exc[i]
# rescnt.append(str(ri))
if i == (n - 1):
print(uf.Count(i) - 1 - exc[i])
else:
print(uf.Count(i) - 1 - exc[i], end=" ")
# print(" ".join(rescnt),end="")
resolve()
| import sys
from io import StringIO
import unittest
class UnionFind:
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1] * (n + 1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0] * (n + 1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if x == y:
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
def resolve():
int1 = lambda x: int(x) - 1
readline = sys.stdin.readline
n, m, k = list(map(int, readline().strip().split()))
uf = UnionFind(n)
exc = [0] * n
for i in range(m):
a, b = list(map(int1, readline().strip().split()))
uf.Unite(a, b)
exc[a] += 1
exc[b] += 1
for i in range(k):
a, b = list(map(int1, readline().strip().split()))
if uf.isSameGroup(a, b):
exc[a] += 1
exc[b] += 1
rescnt = []
for i in range(n):
ri = uf.Count(i) - 1 - exc[i]
rescnt.append(str(ri))
print((" ".join(rescnt)))
resolve()
| false | 4.705882 | [
"+from io import StringIO",
"+import unittest",
"-# from io import StringIO",
"-# import unittest",
"+",
"- n, m, k = map(int, readline().strip().split())",
"+ n, m, k = list(map(int, readline().strip().split()))",
"- a, b = map(int1, readline().strip().split())",
"+ a, b = list(map(int1, readline().strip().split()))",
"- a, b = map(int1, readline().strip().split())",
"+ a, b = list(map(int1, readline().strip().split()))",
"- # ri=uf.Count(i)-1-exc[i]",
"- # rescnt.append(str(ri))",
"- if i == (n - 1):",
"- print(uf.Count(i) - 1 - exc[i])",
"- else:",
"- print(uf.Count(i) - 1 - exc[i], end=\" \")",
"- # print(\" \".join(rescnt),end=\"\")",
"+ ri = uf.Count(i) - 1 - exc[i]",
"+ rescnt.append(str(ri))",
"+ print((\" \".join(rescnt)))"
]
| false | 0.035323 | 0.036196 | 0.975886 | [
"s745063048",
"s300573930"
]
|
u459150945 | p02696 | python | s879630724 | s244745371 | 24 | 20 | 9,000 | 9,080 | Accepted | Accepted | 16.67 | a, b, n = list(map(int, input().split()))
ans = 0
if n < b:
ans = max(ans, a*n//b)
else:
ans = max(ans, (a*n)//b)-a*(n//b)
ans = max(ans, ((a*(b*(n//b)-1))//b)-a*(n//b - 1))
print(ans)
| import math
a, b, n = list(map(int, input().split()))
ans = math.floor(a*min((b-1), n)/b)
print(ans)
| 8 | 4 | 198 | 98 | a, b, n = list(map(int, input().split()))
ans = 0
if n < b:
ans = max(ans, a * n // b)
else:
ans = max(ans, (a * n) // b) - a * (n // b)
ans = max(ans, ((a * (b * (n // b) - 1)) // b) - a * (n // b - 1))
print(ans)
| import math
a, b, n = list(map(int, input().split()))
ans = math.floor(a * min((b - 1), n) / b)
print(ans)
| false | 50 | [
"+import math",
"+",
"-ans = 0",
"-if n < b:",
"- ans = max(ans, a * n // b)",
"-else:",
"- ans = max(ans, (a * n) // b) - a * (n // b)",
"- ans = max(ans, ((a * (b * (n // b) - 1)) // b) - a * (n // b - 1))",
"+ans = math.floor(a * min((b - 1), n) / b)"
]
| false | 0.047896 | 0.048498 | 0.987604 | [
"s879630724",
"s244745371"
]
|
u367701763 | p02793 | python | s017254961 | s324628200 | 673 | 232 | 74,632 | 78,756 | Accepted | Accepted | 65.53 | import sys
input = sys.stdin.readline
import math
big = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
num = A[0]
for i in range(1, N):
num = num * A[i] // math.gcd(num, A[i])
res = 0
for a in A:
res += num * pow(a, big-2, big)
print((res % big))
| from collections import Counter, defaultdict
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
# mを法とするaの乗法的逆元
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
# 素因数分解
def prime_factors(n):
i = 2
while i * i <= n:
if n % i:
i += 1
else:
n //= i
yield i
if n > 1:
yield n
# mを法とするときのa^n
def modpow(a,n,m):
res = 1
t = a
while n:
if n%2:
res = (res*t)%m
t = (t*t)%m
n //= 2
return res
def lcm_mod(nums, mod):
p = defaultdict(int)
for n in nums:
c = Counter(prime_factors(n))
for v,cnt in list(c.items()):
p[v] = max(p[v],cnt)
res = 1
for v,cnt in list(p.items()):
res *= modpow(v,cnt,mod)
res %= mod
return res
MOD = 10**9+7
N = int(eval(input()))
A = list(map(int,input().split()))
s = sum(modinv(a,MOD) for a in A)%MOD
s *= lcm_mod(A, MOD)
print((s%MOD))
| 17 | 66 | 291 | 1,231 | import sys
input = sys.stdin.readline
import math
big = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
num = A[0]
for i in range(1, N):
num = num * A[i] // math.gcd(num, A[i])
res = 0
for a in A:
res += num * pow(a, big - 2, big)
print((res % big))
| from collections import Counter, defaultdict
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
# mを法とするaの乗法的逆元
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception("modular inverse does not exist")
else:
return x % m
# 素因数分解
def prime_factors(n):
i = 2
while i * i <= n:
if n % i:
i += 1
else:
n //= i
yield i
if n > 1:
yield n
# mを法とするときのa^n
def modpow(a, n, m):
res = 1
t = a
while n:
if n % 2:
res = (res * t) % m
t = (t * t) % m
n //= 2
return res
def lcm_mod(nums, mod):
p = defaultdict(int)
for n in nums:
c = Counter(prime_factors(n))
for v, cnt in list(c.items()):
p[v] = max(p[v], cnt)
res = 1
for v, cnt in list(p.items()):
res *= modpow(v, cnt, mod)
res %= mod
return res
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
s = sum(modinv(a, MOD) for a in A) % MOD
s *= lcm_mod(A, MOD)
print((s % MOD))
| false | 74.242424 | [
"-import sys",
"+from collections import Counter, defaultdict",
"-input = sys.stdin.readline",
"-import math",
"+# 拡張ユークリッド互除法",
"+# ax + by = gcd(a,b)の最小整数解を返す",
"+def egcd(a, b):",
"+ if a == 0:",
"+ return (b, 0, 1)",
"+ else:",
"+ g, y, x = egcd(b % a, a)",
"+ return (g, x - (b // a) * y, y)",
"-big = 10**9 + 7",
"+",
"+# mを法とするaの乗法的逆元",
"+def modinv(a, m):",
"+ g, x, y = egcd(a, m)",
"+ if g != 1:",
"+ raise Exception(\"modular inverse does not exist\")",
"+ else:",
"+ return x % m",
"+",
"+",
"+# 素因数分解",
"+def prime_factors(n):",
"+ i = 2",
"+ while i * i <= n:",
"+ if n % i:",
"+ i += 1",
"+ else:",
"+ n //= i",
"+ yield i",
"+ if n > 1:",
"+ yield n",
"+",
"+",
"+# mを法とするときのa^n",
"+def modpow(a, n, m):",
"+ res = 1",
"+ t = a",
"+ while n:",
"+ if n % 2:",
"+ res = (res * t) % m",
"+ t = (t * t) % m",
"+ n //= 2",
"+ return res",
"+",
"+",
"+def lcm_mod(nums, mod):",
"+ p = defaultdict(int)",
"+ for n in nums:",
"+ c = Counter(prime_factors(n))",
"+ for v, cnt in list(c.items()):",
"+ p[v] = max(p[v], cnt)",
"+ res = 1",
"+ for v, cnt in list(p.items()):",
"+ res *= modpow(v, cnt, mod)",
"+ res %= mod",
"+ return res",
"+",
"+",
"+MOD = 10**9 + 7",
"-num = A[0]",
"-for i in range(1, N):",
"- num = num * A[i] // math.gcd(num, A[i])",
"-res = 0",
"-for a in A:",
"- res += num * pow(a, big - 2, big)",
"-print((res % big))",
"+s = sum(modinv(a, MOD) for a in A) % MOD",
"+s *= lcm_mod(A, MOD)",
"+print((s % MOD))"
]
| false | 0.114895 | 0.046654 | 2.46268 | [
"s017254961",
"s324628200"
]
|
u869790980 | p03266 | python | s694170180 | s648731154 | 380 | 58 | 107,204 | 70,428 | Accepted | Accepted | 84.74 |
import collections
n,k = list(map(int, input().split(' ')))
cc= collections.Counter()
left = n % k
for ii in range(k):
cc[ii] += n / k
if 0<ii <= left:
cc[ii] += 1
r = 0
for ii in cc:
if (- 2*ii) % k == 0:
r += cc[ii] * ((cc[(k - ii) % k ]) ** 2)
print(r) |
import collections
n,k = list(map(int, input().split(' ')))
left = n % k
cc = [0] * k
for ii in range(k):
cc[ii] += n / k
if 0<ii <= left:
cc[ii] += 1
r = 0
for ii in range(len(cc)):
if (- 2*ii) % k == 0:
r += cc[ii] * ((cc[(k - ii) % k ]) ** 2)
print(r) | 18 | 18 | 284 | 282 | import collections
n, k = list(map(int, input().split(" ")))
cc = collections.Counter()
left = n % k
for ii in range(k):
cc[ii] += n / k
if 0 < ii <= left:
cc[ii] += 1
r = 0
for ii in cc:
if (-2 * ii) % k == 0:
r += cc[ii] * ((cc[(k - ii) % k]) ** 2)
print(r)
| import collections
n, k = list(map(int, input().split(" ")))
left = n % k
cc = [0] * k
for ii in range(k):
cc[ii] += n / k
if 0 < ii <= left:
cc[ii] += 1
r = 0
for ii in range(len(cc)):
if (-2 * ii) % k == 0:
r += cc[ii] * ((cc[(k - ii) % k]) ** 2)
print(r)
| false | 0 | [
"-cc = collections.Counter()",
"+cc = [0] * k",
"-for ii in cc:",
"+for ii in range(len(cc)):"
]
| false | 0.063198 | 0.038528 | 1.640294 | [
"s694170180",
"s648731154"
]
|
u843175622 | p03584 | python | s399607776 | s128125848 | 788 | 422 | 22,452 | 23,488 | Accepted | Accepted | 46.45 | n, k = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
# そのままの k
ans = 0
for a, b in ab:
if k & a == a:
ans += b
for i in range(31):
# 上からi桁目までいっち、あとは1111
if k >> i & 1 == 0:
continue
nk = k
nk &= ~(1 << i)
for j in range(i - 1, -1, -1):
nk |= 1 << j
cnt = 0
for j in range(n):
a, b = ab[j]
if (a & nk) == a:
cnt += b
ans = max(ans, cnt)
print(ans)
| n, k = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ans = sum([b for a, b in ab if k & a == a])
for i in range(30):
if k >> i & 1:
nk = 1 << i ^ k
for j in range(i):
nk |= 1 << j
ans = max(ans, sum([b for a, b in ab if nk & a == a]))
print(ans)
| 25 | 12 | 500 | 337 | n, k = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
# そのままの k
ans = 0
for a, b in ab:
if k & a == a:
ans += b
for i in range(31):
# 上からi桁目までいっち、あとは1111
if k >> i & 1 == 0:
continue
nk = k
nk &= ~(1 << i)
for j in range(i - 1, -1, -1):
nk |= 1 << j
cnt = 0
for j in range(n):
a, b = ab[j]
if (a & nk) == a:
cnt += b
ans = max(ans, cnt)
print(ans)
| n, k = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ans = sum([b for a, b in ab if k & a == a])
for i in range(30):
if k >> i & 1:
nk = 1 << i ^ k
for j in range(i):
nk |= 1 << j
ans = max(ans, sum([b for a, b in ab if nk & a == a]))
print(ans)
| false | 52 | [
"-# そのままの k",
"-ans = 0",
"-for a, b in ab:",
"- if k & a == a:",
"- ans += b",
"-for i in range(31):",
"- # 上からi桁目までいっち、あとは1111",
"- if k >> i & 1 == 0:",
"- continue",
"- nk = k",
"- nk &= ~(1 << i)",
"- for j in range(i - 1, -1, -1):",
"- nk |= 1 << j",
"- cnt = 0",
"- for j in range(n):",
"- a, b = ab[j]",
"- if (a & nk) == a:",
"- cnt += b",
"- ans = max(ans, cnt)",
"+ans = sum([b for a, b in ab if k & a == a])",
"+for i in range(30):",
"+ if k >> i & 1:",
"+ nk = 1 << i ^ k",
"+ for j in range(i):",
"+ nk |= 1 << j",
"+ ans = max(ans, sum([b for a, b in ab if nk & a == a]))"
]
| false | 0.038435 | 0.038982 | 0.985964 | [
"s399607776",
"s128125848"
]
|
u644907318 | p03438 | python | s261584236 | s939716078 | 97 | 77 | 68,384 | 73,920 | Accepted | Accepted | 20.62 | N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sa = sum(A)
sb = sum(B)
if sa>sb:
print("No")
else:
d1 = 0
d2 = 0
for i in range(N):
if A[i]>B[i]:
d1 += A[i]-B[i]
elif B[i]>A[i]:
d2 += (B[i]-A[i])//2
if d2>=d1:
print("Yes")
else:
print("No") | N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
cp = 0
cm = 0
for i in range(N):
if A[i]>B[i]:
cm += A[i]-B[i]
elif B[i]>A[i]:
cp += (B[i]-A[i])//2
if cp>=cm:
print("Yes")
else:
print("No") | 19 | 14 | 378 | 273 | N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sa = sum(A)
sb = sum(B)
if sa > sb:
print("No")
else:
d1 = 0
d2 = 0
for i in range(N):
if A[i] > B[i]:
d1 += A[i] - B[i]
elif B[i] > A[i]:
d2 += (B[i] - A[i]) // 2
if d2 >= d1:
print("Yes")
else:
print("No")
| N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cp = 0
cm = 0
for i in range(N):
if A[i] > B[i]:
cm += A[i] - B[i]
elif B[i] > A[i]:
cp += (B[i] - A[i]) // 2
if cp >= cm:
print("Yes")
else:
print("No")
| false | 26.315789 | [
"-sa = sum(A)",
"-sb = sum(B)",
"-if sa > sb:",
"+cp = 0",
"+cm = 0",
"+for i in range(N):",
"+ if A[i] > B[i]:",
"+ cm += A[i] - B[i]",
"+ elif B[i] > A[i]:",
"+ cp += (B[i] - A[i]) // 2",
"+if cp >= cm:",
"+ print(\"Yes\")",
"+else:",
"-else:",
"- d1 = 0",
"- d2 = 0",
"- for i in range(N):",
"- if A[i] > B[i]:",
"- d1 += A[i] - B[i]",
"- elif B[i] > A[i]:",
"- d2 += (B[i] - A[i]) // 2",
"- if d2 >= d1:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")"
]
| false | 0.0359 | 0.037732 | 0.951447 | [
"s261584236",
"s939716078"
]
|
u623819879 | p03805 | python | s469161712 | s312443110 | 276 | 199 | 49,880 | 40,688 | Accepted | Accepted | 27.9 | n,m=list(map(int,input().split()))
l=list(range(2,n+1))
v=[[] for i in range(1+n)]
for i in range(m):
a,b=list(map(int,input().split()))
v[a].append(b)
v[b].append(a)
def check(ls):
fr=1
for to in ls:
if int(to) not in v[fr]:
return 0
fr=int(to)
return 1
def gen(ls):
if not ls:
return [[]]
return [[a]+b for i,a in enumerate(ls) for b in gen(ls[:i]+ls[i+1:])]
print((sum([check(i) for i in gen(l)]))) | from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
return int(input())
def MI():
return map(int,input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i)-1 for i in input().split()]
def StoI():
return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
if show_flg:
print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True
n,m=MI()
g=[[] for _ in range(n)]
t=1<<n
mask=t-1
for i in range(m):
a,b=LI_()
g[a].append(b)
g[b].append(a)
dp=[[0]*n for _ in range(t)]
dp[1][0]=1
for s in range(t):
for h in range(n):
if s&(1<<h)==0:
#show('pas1')
continue
for f in g[h]:
if s&(1<<f)==0:
#show('pas2')
continue
dp[s][h]+=dp[s-(1<<h)][f]
show('!dp','s,h,f',bin(s+t)[3:],h,f,'|',dp[s][h],dp[s-(1<<h)][f])
ans=0
for i in range(1,n):
ans+=dp[t-1][i]
print(ans)
show(g)
show(dp)
| 22 | 63 | 483 | 1,324 | n, m = list(map(int, input().split()))
l = list(range(2, n + 1))
v = [[] for i in range(1 + n)]
for i in range(m):
a, b = list(map(int, input().split()))
v[a].append(b)
v[b].append(a)
def check(ls):
fr = 1
for to in ls:
if int(to) not in v[fr]:
return 0
fr = int(to)
return 1
def gen(ls):
if not ls:
return [[]]
return [[a] + b for i, a in enumerate(ls) for b in gen(ls[:i] + ls[i + 1 :])]
print((sum([check(i) for i in gen(l)])))
| from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
# import math
# import time
# import random
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 for i in input()]
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YN = ["Yes", "No"]
mo = 10**9 + 7
# ts=time.time()
# sys.setrecursionlimit(10**6)
input = sys.stdin.readline
show_flg = False
# show_flg=True
n, m = MI()
g = [[] for _ in range(n)]
t = 1 << n
mask = t - 1
for i in range(m):
a, b = LI_()
g[a].append(b)
g[b].append(a)
dp = [[0] * n for _ in range(t)]
dp[1][0] = 1
for s in range(t):
for h in range(n):
if s & (1 << h) == 0:
# show('pas1')
continue
for f in g[h]:
if s & (1 << f) == 0:
# show('pas2')
continue
dp[s][h] += dp[s - (1 << h)][f]
show(
"!dp", "s,h,f", bin(s + t)[3:], h, f, "|", dp[s][h], dp[s - (1 << h)][f]
)
ans = 0
for i in range(1, n):
ans += dp[t - 1][i]
print(ans)
show(g)
show(dp)
| false | 65.079365 | [
"-n, m = list(map(int, input().split()))",
"-l = list(range(2, n + 1))",
"-v = [[] for i in range(1 + n)]",
"-for i in range(m):",
"- a, b = list(map(int, input().split()))",
"- v[a].append(b)",
"- v[b].append(a)",
"+from heapq import heappush, heappop",
"+from collections import deque, defaultdict, Counter",
"+import itertools",
"+from itertools import permutations, combinations",
"+import sys",
"+import bisect",
"+import string",
"+",
"+# import math",
"+# import time",
"+# import random",
"+def I():",
"+ return int(input())",
"-def check(ls):",
"- fr = 1",
"- for to in ls:",
"- if int(to) not in v[fr]:",
"- return 0",
"- fr = int(to)",
"- return 1",
"+def MI():",
"+ return map(int, input().split())",
"-def gen(ls):",
"- if not ls:",
"- return [[]]",
"- return [[a] + b for i, a in enumerate(ls) for b in gen(ls[:i] + ls[i + 1 :])]",
"+def LI():",
"+ return [int(i) for i in input().split()]",
"-print((sum([check(i) for i in gen(l)])))",
"+def LI_():",
"+ return [int(i) - 1 for i in input().split()]",
"+",
"+",
"+def StoI():",
"+ return [ord(i) - 97 for i in input()]",
"+",
"+",
"+def show(*inp, end=\"\\n\"):",
"+ if show_flg:",
"+ print(*inp, end=end)",
"+",
"+",
"+YN = [\"Yes\", \"No\"]",
"+mo = 10**9 + 7",
"+# ts=time.time()",
"+# sys.setrecursionlimit(10**6)",
"+input = sys.stdin.readline",
"+show_flg = False",
"+# show_flg=True",
"+n, m = MI()",
"+g = [[] for _ in range(n)]",
"+t = 1 << n",
"+mask = t - 1",
"+for i in range(m):",
"+ a, b = LI_()",
"+ g[a].append(b)",
"+ g[b].append(a)",
"+dp = [[0] * n for _ in range(t)]",
"+dp[1][0] = 1",
"+for s in range(t):",
"+ for h in range(n):",
"+ if s & (1 << h) == 0:",
"+ # show('pas1')",
"+ continue",
"+ for f in g[h]:",
"+ if s & (1 << f) == 0:",
"+ # show('pas2')",
"+ continue",
"+ dp[s][h] += dp[s - (1 << h)][f]",
"+ show(",
"+ \"!dp\", \"s,h,f\", bin(s + t)[3:], h, f, \"|\", dp[s][h], dp[s - (1 << h)][f]",
"+ )",
"+ans = 0",
"+for i in range(1, n):",
"+ ans += dp[t - 1][i]",
"+print(ans)",
"+show(g)",
"+show(dp)"
]
| false | 0.068952 | 0.044224 | 1.559146 | [
"s469161712",
"s312443110"
]
|
u324314500 | p03077 | python | s823042672 | s290063317 | 19 | 17 | 3,064 | 3,064 | Accepted | Accepted | 10.53 | def ii2ss(n):
ss = []
for i in range(n):
ss.append(eval(input()))
return ss
def sp2nn(sp, sep=' '):
return [int(s) for s in sp.split(sep)]
def ss2nn(ss):
return [int(s) for s in list(ss)]
import math
def main(ss):
N, A, B, C, D, E = ss2nn(ss)
m = min(A, B, C, D, E)
return math.ceil(N / m) + 4
ss = ii2ss(6)
print((main(ss))) | # AtCoder Beginner Contest 123
# https://atcoder.jp/contests/abc123
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
import math
def main():
N = i2n()
ABCDE = ii2nn(5)
m = min(ABCDE)
n = int(math.ceil(N / m)) + 4
print(n)
main() | 20 | 23 | 380 | 602 | def ii2ss(n):
ss = []
for i in range(n):
ss.append(eval(input()))
return ss
def sp2nn(sp, sep=" "):
return [int(s) for s in sp.split(sep)]
def ss2nn(ss):
return [int(s) for s in list(ss)]
import math
def main(ss):
N, A, B, C, D, E = ss2nn(ss)
m = min(A, B, C, D, E)
return math.ceil(N / m) + 4
ss = ii2ss(6)
print((main(ss)))
| # AtCoder Beginner Contest 123
# https://atcoder.jp/contests/abc123
import sys
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
import math
def main():
N = i2n()
ABCDE = ii2nn(5)
m = min(ABCDE)
n = int(math.ceil(N / m)) + 4
print(n)
main()
| false | 13.043478 | [
"-def ii2ss(n):",
"- ss = []",
"- for i in range(n):",
"- ss.append(eval(input()))",
"- return ss",
"+# AtCoder Beginner Contest 123",
"+# https://atcoder.jp/contests/abc123",
"+import sys",
"-",
"-def sp2nn(sp, sep=\" \"):",
"- return [int(s) for s in sp.split(sep)]",
"-",
"-",
"-def ss2nn(ss):",
"- return [int(s) for s in list(ss)]",
"-",
"-",
"+s2nn = lambda s: [int(c) for c in s.split(\" \")]",
"+ss2nn = lambda ss: [int(s) for s in list(ss)]",
"+ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]",
"+i2s = lambda: sys.stdin.readline().rstrip()",
"+i2n = lambda: int(i2s())",
"+i2nn = lambda: s2nn(i2s())",
"+ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]",
"+ii2nn = lambda n: ss2nn(ii2ss(n))",
"+ii2nnn = lambda n: ss2nnn(ii2ss(n))",
"-def main(ss):",
"- N, A, B, C, D, E = ss2nn(ss)",
"- m = min(A, B, C, D, E)",
"- return math.ceil(N / m) + 4",
"+def main():",
"+ N = i2n()",
"+ ABCDE = ii2nn(5)",
"+ m = min(ABCDE)",
"+ n = int(math.ceil(N / m)) + 4",
"+ print(n)",
"-ss = ii2ss(6)",
"-print((main(ss)))",
"+main()"
]
| false | 0.042528 | 0.044386 | 0.958144 | [
"s823042672",
"s290063317"
]
|
u453815934 | p04001 | python | s177436849 | s109293640 | 23 | 20 | 3,064 | 3,064 | Accepted | Accepted | 13.04 | s=eval(input())
n=len(s)-1
sum=0
List=[s[0]]
for i in range(2**n):
for j in range(n):
if (i>>j)&1:
List+=["+"]+[s[j+1]]
else:
List+=[s[j+1]]
m=0
for h in List:
if h=="+":
sum+=m
m=0
else:
m*=10
m+=int(h)
sum+=m
List=[s[0]]
print(sum)
| S=eval(input())
n=len(S)
ans=0
for i in range(2**(n-1)):
s=0
c=int(S[0])
for j in range(n-1):
if (i>>j) & 1:
s+=c
c=int(S[j+1])
else:
c*=10
c+=int(S[j+1])
ans+=s+c
print(ans) | 22 | 15 | 384 | 222 | s = eval(input())
n = len(s) - 1
sum = 0
List = [s[0]]
for i in range(2**n):
for j in range(n):
if (i >> j) & 1:
List += ["+"] + [s[j + 1]]
else:
List += [s[j + 1]]
m = 0
for h in List:
if h == "+":
sum += m
m = 0
else:
m *= 10
m += int(h)
sum += m
List = [s[0]]
print(sum)
| S = eval(input())
n = len(S)
ans = 0
for i in range(2 ** (n - 1)):
s = 0
c = int(S[0])
for j in range(n - 1):
if (i >> j) & 1:
s += c
c = int(S[j + 1])
else:
c *= 10
c += int(S[j + 1])
ans += s + c
print(ans)
| false | 31.818182 | [
"-s = eval(input())",
"-n = len(s) - 1",
"-sum = 0",
"-List = [s[0]]",
"-for i in range(2**n):",
"- for j in range(n):",
"+S = eval(input())",
"+n = len(S)",
"+ans = 0",
"+for i in range(2 ** (n - 1)):",
"+ s = 0",
"+ c = int(S[0])",
"+ for j in range(n - 1):",
"- List += [\"+\"] + [s[j + 1]]",
"+ s += c",
"+ c = int(S[j + 1])",
"- List += [s[j + 1]]",
"- m = 0",
"- for h in List:",
"- if h == \"+\":",
"- sum += m",
"- m = 0",
"- else:",
"- m *= 10",
"- m += int(h)",
"- sum += m",
"- List = [s[0]]",
"-print(sum)",
"+ c *= 10",
"+ c += int(S[j + 1])",
"+ ans += s + c",
"+print(ans)"
]
| false | 0.039016 | 0.039443 | 0.98917 | [
"s177436849",
"s109293640"
]
|
u604774382 | p02399 | python | s342775743 | s994637126 | 30 | 20 | 6,740 | 4,208 | Accepted | Accepted | 33.33 | import sys
a, b = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ]
print(( "{:d} {:d} {:7f}".format( a//b, a%b, a/b ) )) | import sys
a, b = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ]
print(( "{:d} {:d} {:7f}".format( a//b, a%b, float(a)/float(b) ) )) | 4 | 4 | 133 | 148 | import sys
a, b = [int(val) for val in sys.stdin.readline().split(" ")]
print(("{:d} {:d} {:7f}".format(a // b, a % b, a / b)))
| import sys
a, b = [int(val) for val in sys.stdin.readline().split(" ")]
print(("{:d} {:d} {:7f}".format(a // b, a % b, float(a) / float(b))))
| false | 0 | [
"-print((\"{:d} {:d} {:7f}\".format(a // b, a % b, a / b)))",
"+print((\"{:d} {:d} {:7f}\".format(a // b, a % b, float(a) / float(b))))"
]
| false | 0.03958 | 0.038953 | 1.016111 | [
"s342775743",
"s994637126"
]
|
u524513264 | p02576 | python | s789830607 | s237676411 | 32 | 28 | 9,164 | 9,092 | Accepted | Accepted | 12.5 | li = list(map(int, input().split()))
if li[0] % li[1] == 0:
t = li[2] * (li[0] / li[1])
else:
t = li[2] * (int(li[0] / li[1]) +1)
print((int(t)))
| n, x, t = list(map(int, input().split()))
time = (n // x) * t
if n % x != 0:
time += t
print(time)
| 6 | 7 | 157 | 105 | li = list(map(int, input().split()))
if li[0] % li[1] == 0:
t = li[2] * (li[0] / li[1])
else:
t = li[2] * (int(li[0] / li[1]) + 1)
print((int(t)))
| n, x, t = list(map(int, input().split()))
time = (n // x) * t
if n % x != 0:
time += t
print(time)
| false | 14.285714 | [
"-li = list(map(int, input().split()))",
"-if li[0] % li[1] == 0:",
"- t = li[2] * (li[0] / li[1])",
"-else:",
"- t = li[2] * (int(li[0] / li[1]) + 1)",
"-print((int(t)))",
"+n, x, t = list(map(int, input().split()))",
"+time = (n // x) * t",
"+if n % x != 0:",
"+ time += t",
"+print(time)"
]
| false | 0.043103 | 0.039808 | 1.082784 | [
"s789830607",
"s237676411"
]
|
u150984829 | p02397 | python | s855881467 | s781749265 | 40 | 30 | 5,980 | 5,876 | Accepted | Accepted | 25 | a=[]
while 1:
n=eval(input())
if n=='0 0':break
a.append(n)
for s in a:
print((*sorted(map(int,s.split())))) | a=[]
while 1:
n=input()
if n=='0 0':break
a.append(n)
for s in a:
x,y=map(int,s.split())
print(f'{y} {x}') if x>y else print(s)
| 7 | 8 | 110 | 139 | a = []
while 1:
n = eval(input())
if n == "0 0":
break
a.append(n)
for s in a:
print((*sorted(map(int, s.split()))))
| a = []
while 1:
n = input()
if n == "0 0":
break
a.append(n)
for s in a:
x, y = map(int, s.split())
print(f"{y} {x}") if x > y else print(s)
| false | 12.5 | [
"- n = eval(input())",
"+ n = input()",
"- print((*sorted(map(int, s.split()))))",
"+ x, y = map(int, s.split())",
"+ print(f\"{y} {x}\") if x > y else print(s)"
]
| false | 0.038034 | 0.043685 | 0.870627 | [
"s855881467",
"s781749265"
]
|
u647999897 | p02720 | python | s320165710 | s180814626 | 196 | 93 | 12,716 | 11,944 | Accepted | Accepted | 52.55 | def solve():
K = int(eval(input()))
cnt = 0
n_digit = 1
numbers = []
while cnt < K:
numbers = []
dfs("", numbers, n_digit)
cnt += len(numbers)
n_digit += 1
print((numbers[-(cnt - K + 1)]))
def dfs(now, numbers, n_digit):
if len(now) == n_digit:
numbers.append(now)
return
if now == "":
for i in range(1,10):
dfs(now+str(i), numbers, n_digit)
else:
last_num = int(now[-1])
if last_num - 1 >= 0:
dfs(now+str(last_num-1), numbers, n_digit)
dfs(now+str(last_num), numbers, n_digit)
if last_num + 1 <= 9:
dfs(now+str(last_num+1), numbers, n_digit)
if __name__ == '__main__':
solve() | from collections import deque
def solve():
K = int(eval(input()))
q = deque(list(range(1,10)))
cnt = 0
tmp = 0
while cnt < K:
tmp = q.popleft()
cnt += 1
ones_place = tmp % 10
if ones_place != 0:
q.append(tmp*10+ones_place-1)
q.append(tmp*10+ones_place)
if ones_place != 9:
q.append(tmp*10+ones_place+1)
print(tmp)
if __name__ == '__main__':
solve() | 33 | 22 | 783 | 479 | def solve():
K = int(eval(input()))
cnt = 0
n_digit = 1
numbers = []
while cnt < K:
numbers = []
dfs("", numbers, n_digit)
cnt += len(numbers)
n_digit += 1
print((numbers[-(cnt - K + 1)]))
def dfs(now, numbers, n_digit):
if len(now) == n_digit:
numbers.append(now)
return
if now == "":
for i in range(1, 10):
dfs(now + str(i), numbers, n_digit)
else:
last_num = int(now[-1])
if last_num - 1 >= 0:
dfs(now + str(last_num - 1), numbers, n_digit)
dfs(now + str(last_num), numbers, n_digit)
if last_num + 1 <= 9:
dfs(now + str(last_num + 1), numbers, n_digit)
if __name__ == "__main__":
solve()
| from collections import deque
def solve():
K = int(eval(input()))
q = deque(list(range(1, 10)))
cnt = 0
tmp = 0
while cnt < K:
tmp = q.popleft()
cnt += 1
ones_place = tmp % 10
if ones_place != 0:
q.append(tmp * 10 + ones_place - 1)
q.append(tmp * 10 + ones_place)
if ones_place != 9:
q.append(tmp * 10 + ones_place + 1)
print(tmp)
if __name__ == "__main__":
solve()
| false | 33.333333 | [
"+from collections import deque",
"+",
"+",
"+ q = deque(list(range(1, 10)))",
"- n_digit = 1",
"- numbers = []",
"+ tmp = 0",
"- numbers = []",
"- dfs(\"\", numbers, n_digit)",
"- cnt += len(numbers)",
"- n_digit += 1",
"- print((numbers[-(cnt - K + 1)]))",
"-",
"-",
"-def dfs(now, numbers, n_digit):",
"- if len(now) == n_digit:",
"- numbers.append(now)",
"- return",
"- if now == \"\":",
"- for i in range(1, 10):",
"- dfs(now + str(i), numbers, n_digit)",
"- else:",
"- last_num = int(now[-1])",
"- if last_num - 1 >= 0:",
"- dfs(now + str(last_num - 1), numbers, n_digit)",
"- dfs(now + str(last_num), numbers, n_digit)",
"- if last_num + 1 <= 9:",
"- dfs(now + str(last_num + 1), numbers, n_digit)",
"+ tmp = q.popleft()",
"+ cnt += 1",
"+ ones_place = tmp % 10",
"+ if ones_place != 0:",
"+ q.append(tmp * 10 + ones_place - 1)",
"+ q.append(tmp * 10 + ones_place)",
"+ if ones_place != 9:",
"+ q.append(tmp * 10 + ones_place + 1)",
"+ print(tmp)"
]
| false | 0.073713 | 0.0582 | 1.266543 | [
"s320165710",
"s180814626"
]
|
u836737505 | p03761 | python | s503676194 | s482083828 | 24 | 18 | 3,064 | 3,060 | Accepted | Accepted | 25 | n = int(eval(input()))
a = list(eval(input()) for _ in range(n))
# n = 3
# a = ["cbaa","daacc","acacac"]
s = ""
for c in a[0]:
f = []
for i in range(n-1):
if c not in a[i+1]:
break
for d in range(len(a[i+1])):
if c == a[i+1][d]:
f.append(d)
break
else:
s += str(c)
for i in range(n-1):
a[i+1] = a[i+1][:f[i]] +""+ a[i+1][f[i]+1:]
ns = "".join(sorted(s))
print(ns) | def intersect_list(lst1, lst2):
arr = []
lst = lst1.copy()
for element in lst2:
try:
lst.remove(element)
except ValueError:
pass
else:
arr.append(element)
return arr
n = int(eval(input()))
a0 = list(eval(input()))
for i in range(n-1):
a = list(eval(input()))
a0 = intersect_list(a0, a)
print(("".join(sorted(a0)))) | 21 | 19 | 492 | 399 | n = int(eval(input()))
a = list(eval(input()) for _ in range(n))
# n = 3
# a = ["cbaa","daacc","acacac"]
s = ""
for c in a[0]:
f = []
for i in range(n - 1):
if c not in a[i + 1]:
break
for d in range(len(a[i + 1])):
if c == a[i + 1][d]:
f.append(d)
break
else:
s += str(c)
for i in range(n - 1):
a[i + 1] = a[i + 1][: f[i]] + "" + a[i + 1][f[i] + 1 :]
ns = "".join(sorted(s))
print(ns)
| def intersect_list(lst1, lst2):
arr = []
lst = lst1.copy()
for element in lst2:
try:
lst.remove(element)
except ValueError:
pass
else:
arr.append(element)
return arr
n = int(eval(input()))
a0 = list(eval(input()))
for i in range(n - 1):
a = list(eval(input()))
a0 = intersect_list(a0, a)
print(("".join(sorted(a0))))
| false | 9.52381 | [
"+def intersect_list(lst1, lst2):",
"+ arr = []",
"+ lst = lst1.copy()",
"+ for element in lst2:",
"+ try:",
"+ lst.remove(element)",
"+ except ValueError:",
"+ pass",
"+ else:",
"+ arr.append(element)",
"+ return arr",
"+",
"+",
"-a = list(eval(input()) for _ in range(n))",
"-# n = 3",
"-# a = [\"cbaa\",\"daacc\",\"acacac\"]",
"-s = \"\"",
"-for c in a[0]:",
"- f = []",
"- for i in range(n - 1):",
"- if c not in a[i + 1]:",
"- break",
"- for d in range(len(a[i + 1])):",
"- if c == a[i + 1][d]:",
"- f.append(d)",
"- break",
"- else:",
"- s += str(c)",
"- for i in range(n - 1):",
"- a[i + 1] = a[i + 1][: f[i]] + \"\" + a[i + 1][f[i] + 1 :]",
"-ns = \"\".join(sorted(s))",
"-print(ns)",
"+a0 = list(eval(input()))",
"+for i in range(n - 1):",
"+ a = list(eval(input()))",
"+ a0 = intersect_list(a0, a)",
"+print((\"\".join(sorted(a0))))"
]
| false | 0.044322 | 0.04449 | 0.996228 | [
"s503676194",
"s482083828"
]
|
u190405389 | p03310 | python | s858682831 | s202635268 | 946 | 635 | 126,044 | 108,920 | Accepted | Accepted | 32.88 | from itertools import accumulate
import bisect
n = int(eval(input()))
a = list(map(int, input().split()))
arev = list(reversed(a))
front = list(accumulate(a))
back = list(accumulate(arev))
ans = float('inf')
for i in range(1,n-2):
b = bisect.bisect_left(front,front[i]//2,0,i-1)
c = bisect.bisect_left(back,back[n-i-2]//2,0,n-i-3)
p = front[b]
q = front[i]-front[b]
s = back[c]
r = back[n-i-2]-back[c]
ans = min(max(p,q,r,s)-min(p,q,r,s),ans)
if b!=0:
p = front[b-1]
q = front[i] - front[b-1]
s = back[c]
r = back[n-i-2] - back[c]
ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
if c!=0:
p = front[b]
q = front[i] - front[b]
s = back[c-1]
r = back[n-i-2] - back[c-1]
ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
if b!=0 and c!=0:
p = front[b-1]
q = front[i] - front[b-1]
s = back[c-1]
r = back[n-i-2] - back[c-1]
ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
print(ans)
| # 解説の方法
from itertools import accumulate
n = int(eval(input()))
a = list(map(int, input().split()))
acc = list(accumulate(a))
l = 0
r = 2
ans = float('inf')
for y in range(1,n-2):
for x in range(l,y-1):
if abs(acc[y]-acc[x]*2)>=abs(acc[y]-acc[x+1]*2):
l = x+1
continue
else:
break
r = max(y+1,r)
for z in range(r,n-2):
if abs(acc[n-1]-acc[z]*2+acc[y])>=abs(acc[n-1]-acc[z+1]*2+acc[y]):
r = z+1
continue
else:
break
P = acc[l]
Q = acc[y] - acc[l]
R = acc[r] - acc[y]
S = acc[n-1] - acc[r]
ans = min(ans, max(P,Q,R,S)-min(P,Q,R,S))
print(ans)
| 52 | 35 | 1,103 | 712 | from itertools import accumulate
import bisect
n = int(eval(input()))
a = list(map(int, input().split()))
arev = list(reversed(a))
front = list(accumulate(a))
back = list(accumulate(arev))
ans = float("inf")
for i in range(1, n - 2):
b = bisect.bisect_left(front, front[i] // 2, 0, i - 1)
c = bisect.bisect_left(back, back[n - i - 2] // 2, 0, n - i - 3)
p = front[b]
q = front[i] - front[b]
s = back[c]
r = back[n - i - 2] - back[c]
ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
if b != 0:
p = front[b - 1]
q = front[i] - front[b - 1]
s = back[c]
r = back[n - i - 2] - back[c]
ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
if c != 0:
p = front[b]
q = front[i] - front[b]
s = back[c - 1]
r = back[n - i - 2] - back[c - 1]
ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
if b != 0 and c != 0:
p = front[b - 1]
q = front[i] - front[b - 1]
s = back[c - 1]
r = back[n - i - 2] - back[c - 1]
ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
print(ans)
| # 解説の方法
from itertools import accumulate
n = int(eval(input()))
a = list(map(int, input().split()))
acc = list(accumulate(a))
l = 0
r = 2
ans = float("inf")
for y in range(1, n - 2):
for x in range(l, y - 1):
if abs(acc[y] - acc[x] * 2) >= abs(acc[y] - acc[x + 1] * 2):
l = x + 1
continue
else:
break
r = max(y + 1, r)
for z in range(r, n - 2):
if abs(acc[n - 1] - acc[z] * 2 + acc[y]) >= abs(
acc[n - 1] - acc[z + 1] * 2 + acc[y]
):
r = z + 1
continue
else:
break
P = acc[l]
Q = acc[y] - acc[l]
R = acc[r] - acc[y]
S = acc[n - 1] - acc[r]
ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))
print(ans)
| false | 32.692308 | [
"+# 解説の方法",
"-import bisect",
"-arev = list(reversed(a))",
"-front = list(accumulate(a))",
"-back = list(accumulate(arev))",
"+acc = list(accumulate(a))",
"+l = 0",
"+r = 2",
"-for i in range(1, n - 2):",
"- b = bisect.bisect_left(front, front[i] // 2, 0, i - 1)",
"- c = bisect.bisect_left(back, back[n - i - 2] // 2, 0, n - i - 3)",
"- p = front[b]",
"- q = front[i] - front[b]",
"- s = back[c]",
"- r = back[n - i - 2] - back[c]",
"- ans = min(max(p, q, r, s) - min(p, q, r, s), ans)",
"- if b != 0:",
"- p = front[b - 1]",
"- q = front[i] - front[b - 1]",
"- s = back[c]",
"- r = back[n - i - 2] - back[c]",
"- ans = min(max(p, q, r, s) - min(p, q, r, s), ans)",
"- if c != 0:",
"- p = front[b]",
"- q = front[i] - front[b]",
"- s = back[c - 1]",
"- r = back[n - i - 2] - back[c - 1]",
"- ans = min(max(p, q, r, s) - min(p, q, r, s), ans)",
"- if b != 0 and c != 0:",
"- p = front[b - 1]",
"- q = front[i] - front[b - 1]",
"- s = back[c - 1]",
"- r = back[n - i - 2] - back[c - 1]",
"- ans = min(max(p, q, r, s) - min(p, q, r, s), ans)",
"+for y in range(1, n - 2):",
"+ for x in range(l, y - 1):",
"+ if abs(acc[y] - acc[x] * 2) >= abs(acc[y] - acc[x + 1] * 2):",
"+ l = x + 1",
"+ continue",
"+ else:",
"+ break",
"+ r = max(y + 1, r)",
"+ for z in range(r, n - 2):",
"+ if abs(acc[n - 1] - acc[z] * 2 + acc[y]) >= abs(",
"+ acc[n - 1] - acc[z + 1] * 2 + acc[y]",
"+ ):",
"+ r = z + 1",
"+ continue",
"+ else:",
"+ break",
"+ P = acc[l]",
"+ Q = acc[y] - acc[l]",
"+ R = acc[r] - acc[y]",
"+ S = acc[n - 1] - acc[r]",
"+ ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))"
]
| false | 0.042889 | 0.039243 | 1.092903 | [
"s858682831",
"s202635268"
]
|
u952708174 | p03361 | python | s155967147 | s448570661 | 22 | 20 | 3,064 | 3,064 | Accepted | Accepted | 9.09 | def c_grid_repainting(H, W, Grid):
is_visited = [[False] * W for h in range(H)]
delta = [(-1, 0), (1, 0), (0, -1), (0, 1)] # 上下左右
def bfs(r, c):
if Grid[r][c] == '.':
return
if is_visited[r][c]:
return
q = [(r, c)]
while q:
h, w = q.pop()
for dh, dw in delta:
nh, nw = h + dh, w + dw
if 0 <= nh < H and 0 <= nw < W and Grid[nh][nw] == '#' and not is_visited[nh][nw]:
is_visited[r][c] = True
is_visited[nh][nw] = True
q.insert(0, (nh, nw))
for h in range(H):
for w in range(W):
bfs(h, w)
for h in range(H):
for w in range(W):
if Grid[h][w] == '#' and not is_visited[h][w]:
return 'No'
return 'Yes'
H,W = [int(i) for i in input().split()]
Grid = [input().strip() for _ in range(H)]
print((c_grid_repainting(H, W, Grid))) | def c_grid_repainting(H, W, Grid):
delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for h in range(H):
for w in range(W):
if Grid[h][w] == '.': # 白マスは無視
continue
black = 0 # マス(h,w)に隣り合った黒マスの数
for dh, dw in delta:
is_internal = 0 <= h + dh < H and 0 <= w + dw < W
if is_internal and Grid[h + dh][w + dw] == '#':
# 隣のマスはキャンバスの内部で、黒だった
black += 1
if black == 0:
# 黒マス候補の隣に黒マスがなかった。そのマスは塗れない
return 'No'
return 'Yes'
H,W = [int(i) for i in input().split()]
Grid = [input().strip() for _ in range(H)]
print((c_grid_repainting(H, W, Grid))) | 30 | 20 | 1,000 | 737 | def c_grid_repainting(H, W, Grid):
is_visited = [[False] * W for h in range(H)]
delta = [(-1, 0), (1, 0), (0, -1), (0, 1)] # 上下左右
def bfs(r, c):
if Grid[r][c] == ".":
return
if is_visited[r][c]:
return
q = [(r, c)]
while q:
h, w = q.pop()
for dh, dw in delta:
nh, nw = h + dh, w + dw
if (
0 <= nh < H
and 0 <= nw < W
and Grid[nh][nw] == "#"
and not is_visited[nh][nw]
):
is_visited[r][c] = True
is_visited[nh][nw] = True
q.insert(0, (nh, nw))
for h in range(H):
for w in range(W):
bfs(h, w)
for h in range(H):
for w in range(W):
if Grid[h][w] == "#" and not is_visited[h][w]:
return "No"
return "Yes"
H, W = [int(i) for i in input().split()]
Grid = [input().strip() for _ in range(H)]
print((c_grid_repainting(H, W, Grid)))
| def c_grid_repainting(H, W, Grid):
delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for h in range(H):
for w in range(W):
if Grid[h][w] == ".": # 白マスは無視
continue
black = 0 # マス(h,w)に隣り合った黒マスの数
for dh, dw in delta:
is_internal = 0 <= h + dh < H and 0 <= w + dw < W
if is_internal and Grid[h + dh][w + dw] == "#":
# 隣のマスはキャンバスの内部で、黒だった
black += 1
if black == 0:
# 黒マス候補の隣に黒マスがなかった。そのマスは塗れない
return "No"
return "Yes"
H, W = [int(i) for i in input().split()]
Grid = [input().strip() for _ in range(H)]
print((c_grid_repainting(H, W, Grid)))
| false | 33.333333 | [
"- is_visited = [[False] * W for h in range(H)]",
"- delta = [(-1, 0), (1, 0), (0, -1), (0, 1)] # 上下左右",
"-",
"- def bfs(r, c):",
"- if Grid[r][c] == \".\":",
"- return",
"- if is_visited[r][c]:",
"- return",
"- q = [(r, c)]",
"- while q:",
"- h, w = q.pop()",
"- for dh, dw in delta:",
"- nh, nw = h + dh, w + dw",
"- if (",
"- 0 <= nh < H",
"- and 0 <= nw < W",
"- and Grid[nh][nw] == \"#\"",
"- and not is_visited[nh][nw]",
"- ):",
"- is_visited[r][c] = True",
"- is_visited[nh][nw] = True",
"- q.insert(0, (nh, nw))",
"-",
"+ delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]",
"- bfs(h, w)",
"- for h in range(H):",
"- for w in range(W):",
"- if Grid[h][w] == \"#\" and not is_visited[h][w]:",
"+ if Grid[h][w] == \".\": # 白マスは無視",
"+ continue",
"+ black = 0 # マス(h,w)に隣り合った黒マスの数",
"+ for dh, dw in delta:",
"+ is_internal = 0 <= h + dh < H and 0 <= w + dw < W",
"+ if is_internal and Grid[h + dh][w + dw] == \"#\":",
"+ # 隣のマスはキャンバスの内部で、黒だった",
"+ black += 1",
"+ if black == 0:",
"+ # 黒マス候補の隣に黒マスがなかった。そのマスは塗れない"
]
| false | 0.046465 | 0.045916 | 1.011961 | [
"s155967147",
"s448570661"
]
|
u716530146 | p02749 | python | s555569369 | s969345693 | 1,110 | 952 | 173,728 | 173,728 | Accepted | Accepted | 14.23 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**7)
n = int(eval(input()))
G = [[] for i in range(n)]
for _ in range(n-1):
a,b = list(map(int,input().split()))
a -= 1; b-=1
G[a].append(b)
G[b].append(a)
ans = [0] * n
color = [[],[]]
def coloring(node,pre,oddeven):
color[oddeven%2].append(node)
for vi in G[node]:
if vi != pre:
coloring(vi,node,oddeven+1)
return
coloring(0,-1,0)
A = n//3 + int(bool(n%3))
B = n//3 + int(n%3 == 2)
C = n//3
# この時点ではA>=Bである
# if len(color[0]) < len(color[1]):
# A,B = B,A
a=b=0; c=1
if len(color[0]) > C and len(color[1]) > C:
for i,ci in enumerate(color[0]):
if i < A:
ans[ci] = 3 * i + 1
else:
ans[ci] = 3 * c
c += 1
for i,ci in enumerate(color[1]):
if i < B:
ans[ci] = 3 * i + 2
else:
ans[ci] = 3 * c
c += 1
elif len(color[0]) <= C:
# elseが読まれるとき必ずlen(color[0]) < A
# Bは条件を満たすはず
for i ,ci in enumerate(color[0]):
ans[ci] = 3 * c
c += 1
for i ,ci in enumerate(color[1]):
if a < A:
ans[ci] = 3 * a + 1
a += 1
elif b < B:
ans[ci] = 3 * b + 2
b += 1
else:
ans[ci] = 3 * c
c += 1
else:
# elseが読まれるとき必ずlen(color[0]) < A
# そんなことなかったwwww
for i ,ci in enumerate(color[1]):
ans[ci] = 3 * c
c += 1
for i ,ci in enumerate(color[0]):
if a < A:
ans[ci] = 3 * a + 1
a += 1
elif b < B:
ans[ci] = 3 * b + 2
b += 1
else:
ans[ci] = 3 * c
c += 1
print((*ans)) | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**7)
n = int(eval(input()))
G = [[] for i in range(n)]
for _ in range(n-1):
a,b = list(map(int,input().split()))
a -= 1; b-=1
G[a].append(b)
G[b].append(a)
ans = [0] * n
color = [[],[]]
def coloring(node,pre,oddeven):
color[oddeven%2].append(node)
for vi in G[node]:
if vi != pre:
coloring(vi,node,oddeven+1)
return
coloring(0,-1,0)
A = n//3 + int(bool(n%3))
B = n//3 + int(n%3 == 2)
C = n//3
# A>=Bである
a=b=0; c=1
if len(color[0]) >= A and len(color[1]) >= B:
for i,ci in enumerate(color[0]):
if i < A:
ans[ci] = 3 * i + 1
else:
ans[ci] = 3 * c
c += 1
for i,ci in enumerate(color[1]):
if i < B:
ans[ci] = 3 * i + 2
else:
ans[ci] = 3 * c
c += 1
elif len(color[0]) < A:
# elseが読まれるとき必ずlen(color[0]) < A
# Bは条件を満たすはず
for i ,ci in enumerate(color[0]):
ans[ci] = 3 * c
c += 1
for i ,ci in enumerate(color[1]):
if a < A:
ans[ci] = 3 * a + 1
a += 1
elif b < B:
ans[ci] = 3 * b + 2
b += 1
else:
ans[ci] = 3 * c
c += 1
else:
# elseが読まれるとき必ずlen(color[0]) < A
# そんなことなかったwwww
for i ,ci in enumerate(color[1]):
ans[ci] = 3 * c
c += 1
for i ,ci in enumerate(color[0]):
if a < A:
ans[ci] = 3 * a + 1
a += 1
elif b < B:
ans[ci] = 3 * b + 2
b += 1
else:
ans[ci] = 3 * c
c += 1
print((*ans)) | 81 | 79 | 1,748 | 1,691 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
sys.setrecursionlimit(10**7)
n = int(eval(input()))
G = [[] for i in range(n)]
for _ in range(n - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
ans = [0] * n
color = [[], []]
def coloring(node, pre, oddeven):
color[oddeven % 2].append(node)
for vi in G[node]:
if vi != pre:
coloring(vi, node, oddeven + 1)
return
coloring(0, -1, 0)
A = n // 3 + int(bool(n % 3))
B = n // 3 + int(n % 3 == 2)
C = n // 3
# この時点ではA>=Bである
# if len(color[0]) < len(color[1]):
# A,B = B,A
a = b = 0
c = 1
if len(color[0]) > C and len(color[1]) > C:
for i, ci in enumerate(color[0]):
if i < A:
ans[ci] = 3 * i + 1
else:
ans[ci] = 3 * c
c += 1
for i, ci in enumerate(color[1]):
if i < B:
ans[ci] = 3 * i + 2
else:
ans[ci] = 3 * c
c += 1
elif len(color[0]) <= C:
# elseが読まれるとき必ずlen(color[0]) < A
# Bは条件を満たすはず
for i, ci in enumerate(color[0]):
ans[ci] = 3 * c
c += 1
for i, ci in enumerate(color[1]):
if a < A:
ans[ci] = 3 * a + 1
a += 1
elif b < B:
ans[ci] = 3 * b + 2
b += 1
else:
ans[ci] = 3 * c
c += 1
else:
# elseが読まれるとき必ずlen(color[0]) < A
# そんなことなかったwwww
for i, ci in enumerate(color[1]):
ans[ci] = 3 * c
c += 1
for i, ci in enumerate(color[0]):
if a < A:
ans[ci] = 3 * a + 1
a += 1
elif b < B:
ans[ci] = 3 * b + 2
b += 1
else:
ans[ci] = 3 * c
c += 1
print((*ans))
| #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
sys.setrecursionlimit(10**7)
n = int(eval(input()))
G = [[] for i in range(n)]
for _ in range(n - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
ans = [0] * n
color = [[], []]
def coloring(node, pre, oddeven):
color[oddeven % 2].append(node)
for vi in G[node]:
if vi != pre:
coloring(vi, node, oddeven + 1)
return
coloring(0, -1, 0)
A = n // 3 + int(bool(n % 3))
B = n // 3 + int(n % 3 == 2)
C = n // 3
# A>=Bである
a = b = 0
c = 1
if len(color[0]) >= A and len(color[1]) >= B:
for i, ci in enumerate(color[0]):
if i < A:
ans[ci] = 3 * i + 1
else:
ans[ci] = 3 * c
c += 1
for i, ci in enumerate(color[1]):
if i < B:
ans[ci] = 3 * i + 2
else:
ans[ci] = 3 * c
c += 1
elif len(color[0]) < A:
# elseが読まれるとき必ずlen(color[0]) < A
# Bは条件を満たすはず
for i, ci in enumerate(color[0]):
ans[ci] = 3 * c
c += 1
for i, ci in enumerate(color[1]):
if a < A:
ans[ci] = 3 * a + 1
a += 1
elif b < B:
ans[ci] = 3 * b + 2
b += 1
else:
ans[ci] = 3 * c
c += 1
else:
# elseが読まれるとき必ずlen(color[0]) < A
# そんなことなかったwwww
for i, ci in enumerate(color[1]):
ans[ci] = 3 * c
c += 1
for i, ci in enumerate(color[0]):
if a < A:
ans[ci] = 3 * a + 1
a += 1
elif b < B:
ans[ci] = 3 * b + 2
b += 1
else:
ans[ci] = 3 * c
c += 1
print((*ans))
| false | 2.469136 | [
"-# この時点ではA>=Bである",
"-# if len(color[0]) < len(color[1]):",
"-# A,B = B,A",
"+# A>=Bである",
"-if len(color[0]) > C and len(color[1]) > C:",
"+if len(color[0]) >= A and len(color[1]) >= B:",
"-elif len(color[0]) <= C:",
"+elif len(color[0]) < A:"
]
| false | 0.045025 | 0.149575 | 0.301022 | [
"s555569369",
"s969345693"
]
|
u853619096 | p02420 | python | s997106353 | s682481985 | 30 | 20 | 7,576 | 7,640 | Accepted | Accepted | 33.33 | while True:
s=eval(input())
if s == '-':
break
m=int(eval(input()))
for mi in range(m):
h = int(eval(input()))
s = s[h:] + s[:h]
print(s) |
while True:
z = list(map(str, eval(input())))
if "-" in z:
break
n = int(eval(input()))
for i in range(n):
a=int(eval(input()))
z=z[a:]+z[:a]
print(("".join(z))) | 12 | 10 | 180 | 195 | while True:
s = eval(input())
if s == "-":
break
m = int(eval(input()))
for mi in range(m):
h = int(eval(input()))
s = s[h:] + s[:h]
print(s)
| while True:
z = list(map(str, eval(input())))
if "-" in z:
break
n = int(eval(input()))
for i in range(n):
a = int(eval(input()))
z = z[a:] + z[:a]
print(("".join(z)))
| false | 16.666667 | [
"- s = eval(input())",
"- if s == \"-\":",
"+ z = list(map(str, eval(input())))",
"+ if \"-\" in z:",
"- m = int(eval(input()))",
"- for mi in range(m):",
"- h = int(eval(input()))",
"- s = s[h:] + s[:h]",
"- print(s)",
"+ n = int(eval(input()))",
"+ for i in range(n):",
"+ a = int(eval(input()))",
"+ z = z[a:] + z[:a]",
"+ print((\"\".join(z)))"
]
| false | 0.068156 | 0.066968 | 1.017733 | [
"s997106353",
"s682481985"
]
|
u017810624 | p02762 | python | s948115867 | s886729501 | 1,971 | 1,390 | 124,092 | 125,872 | Accepted | Accepted | 29.48 | n,m,k=list(map(int,input().split()))
class UF():
def __init__(self, N):
self._parent=[n for n in range(0, N)]
self._size=[1] * N
def find_root(self, x):
if self._parent[x]==x:return x
self._parent[x]=self.find_root(self._parent[x])
return self._parent[x]
def unite(self, x, y):
gx=self.find_root(x)
gy=self.find_root(y)
if gx==gy:return
if self._size[gx]<self._size[gy]:
self._parent[gx]=gy
self._size[gy]+=self._size[gx]
else:
self._parent[gy]=gx
self._size[gx]+=self._size[gy]
def size(self, x):
return self._size[self.find_root(x)]
def samegroup(self, x, y):
return self.find_root(x)==self.find_root(y)
def groupnum(self):
N=len(self._parent)
ans=0
for i in range(N):
if self.find_root(i)==i:
ans+=1
return ans
cf=[[] for i in range(n)]
cb=[[] for i in range(n)]
UFa=UF(n)
UFb=UF(n)
for i in range(m):
x,y=list(map(int,input().split()))
UFa.unite(x-1,y-1)
UFb.unite(x-1,y-1)
cf[x-1].append(y-1)
cf[y-1].append(x-1)
UFa.groupnum()
for i in range(k):
x,y=list(map(int,input().split()))
cb[x-1].append(y-1)
cb[y-1].append(x-1)
ans=[]
for i in range(n):
x=(UFa.size(i)-1)-len(cf[i])
for j in range(len(cb[i])):
if UFa.samegroup(i,cb[i][j]):
x-=1
ans.append(str(x))
print((' '.join(ans))) | import sys
input=sys.stdin.readline
n,m,k=list(map(int,input().split()))
class UF():
def __init__(self, N):
self._parent=[n for n in range(0, N)]
self._size=[1] * N
def find_root(self, x):
if self._parent[x]==x:return x
self._parent[x]=self.find_root(self._parent[x])
return self._parent[x]
def unite(self, x, y):
gx=self.find_root(x)
gy=self.find_root(y)
if gx==gy:return
if self._size[gx]<self._size[gy]:
self._parent[gx]=gy
self._size[gy]+=self._size[gx]
else:
self._parent[gy]=gx
self._size[gx]+=self._size[gy]
def size(self, x):
return self._size[self.find_root(x)]
def samegroup(self, x, y):
return self.find_root(x)==self.find_root(y)
def groupnum(self):
N=len(self._parent)
ans=0
for i in range(N):
if self.find_root(i)==i:
ans+=1
return ans
cf=[[] for i in range(n)]
cb=[[] for i in range(n)]
UFa=UF(n)
UFb=UF(n)
for i in range(m):
x,y=list(map(int,input().split()))
UFa.unite(x-1,y-1)
UFb.unite(x-1,y-1)
cf[x-1].append(y-1)
cf[y-1].append(x-1)
UFa.groupnum()
for i in range(k):
x,y=list(map(int,input().split()))
cb[x-1].append(y-1)
cb[y-1].append(x-1)
ans=[]
for i in range(n):
x=(UFa.size(i)-1)-len(cf[i])
for j in range(len(cb[i])):
if UFa.samegroup(i,cb[i][j]):
x-=1
ans.append(str(x))
print((' '.join(ans))) | 64 | 66 | 1,386 | 1,424 | n, m, k = list(map(int, input().split()))
class UF:
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
def find_root(self, x):
if self._parent[x] == x:
return x
self._parent[x] = self.find_root(self._parent[x])
return self._parent[x]
def unite(self, x, y):
gx = self.find_root(x)
gy = self.find_root(y)
if gx == gy:
return
if self._size[gx] < self._size[gy]:
self._parent[gx] = gy
self._size[gy] += self._size[gx]
else:
self._parent[gy] = gx
self._size[gx] += self._size[gy]
def size(self, x):
return self._size[self.find_root(x)]
def samegroup(self, x, y):
return self.find_root(x) == self.find_root(y)
def groupnum(self):
N = len(self._parent)
ans = 0
for i in range(N):
if self.find_root(i) == i:
ans += 1
return ans
cf = [[] for i in range(n)]
cb = [[] for i in range(n)]
UFa = UF(n)
UFb = UF(n)
for i in range(m):
x, y = list(map(int, input().split()))
UFa.unite(x - 1, y - 1)
UFb.unite(x - 1, y - 1)
cf[x - 1].append(y - 1)
cf[y - 1].append(x - 1)
UFa.groupnum()
for i in range(k):
x, y = list(map(int, input().split()))
cb[x - 1].append(y - 1)
cb[y - 1].append(x - 1)
ans = []
for i in range(n):
x = (UFa.size(i) - 1) - len(cf[i])
for j in range(len(cb[i])):
if UFa.samegroup(i, cb[i][j]):
x -= 1
ans.append(str(x))
print((" ".join(ans)))
| import sys
input = sys.stdin.readline
n, m, k = list(map(int, input().split()))
class UF:
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
def find_root(self, x):
if self._parent[x] == x:
return x
self._parent[x] = self.find_root(self._parent[x])
return self._parent[x]
def unite(self, x, y):
gx = self.find_root(x)
gy = self.find_root(y)
if gx == gy:
return
if self._size[gx] < self._size[gy]:
self._parent[gx] = gy
self._size[gy] += self._size[gx]
else:
self._parent[gy] = gx
self._size[gx] += self._size[gy]
def size(self, x):
return self._size[self.find_root(x)]
def samegroup(self, x, y):
return self.find_root(x) == self.find_root(y)
def groupnum(self):
N = len(self._parent)
ans = 0
for i in range(N):
if self.find_root(i) == i:
ans += 1
return ans
cf = [[] for i in range(n)]
cb = [[] for i in range(n)]
UFa = UF(n)
UFb = UF(n)
for i in range(m):
x, y = list(map(int, input().split()))
UFa.unite(x - 1, y - 1)
UFb.unite(x - 1, y - 1)
cf[x - 1].append(y - 1)
cf[y - 1].append(x - 1)
UFa.groupnum()
for i in range(k):
x, y = list(map(int, input().split()))
cb[x - 1].append(y - 1)
cb[y - 1].append(x - 1)
ans = []
for i in range(n):
x = (UFa.size(i) - 1) - len(cf[i])
for j in range(len(cb[i])):
if UFa.samegroup(i, cb[i][j]):
x -= 1
ans.append(str(x))
print((" ".join(ans)))
| false | 3.030303 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
]
| false | 0.03646 | 0.042096 | 0.866128 | [
"s948115867",
"s886729501"
]
|
u310431893 | p03200 | python | s471364304 | s572627371 | 57 | 46 | 3,624 | 3,500 | Accepted | Accepted | 19.3 | S = eval(input())
S.lstrip("W")
def f(s):
count = 1
for i, si in enumerate(s):
if si == 'W':
yield (i+1) - count
count += 1
print((sum(f(S))))
| c = 0
s = 0
for i in eval(input()):
if i == "W":
s += c
else:
c += 1
print(s) | 11 | 8 | 187 | 102 | S = eval(input())
S.lstrip("W")
def f(s):
count = 1
for i, si in enumerate(s):
if si == "W":
yield (i + 1) - count
count += 1
print((sum(f(S))))
| c = 0
s = 0
for i in eval(input()):
if i == "W":
s += c
else:
c += 1
print(s)
| false | 27.272727 | [
"-S = eval(input())",
"-S.lstrip(\"W\")",
"-",
"-",
"-def f(s):",
"- count = 1",
"- for i, si in enumerate(s):",
"- if si == \"W\":",
"- yield (i + 1) - count",
"- count += 1",
"-",
"-",
"-print((sum(f(S))))",
"+c = 0",
"+s = 0",
"+for i in eval(input()):",
"+ if i == \"W\":",
"+ s += c",
"+ else:",
"+ c += 1",
"+print(s)"
]
| false | 0.039345 | 0.038887 | 1.01177 | [
"s471364304",
"s572627371"
]
|
u631277801 | p03112 | python | s728974090 | s873410979 | 863 | 715 | 16,160 | 17,948 | Accepted | Accepted | 17.15 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
from bisect import bisect_right
a,b,q = li()
s = [ni() for _ in range(a)]
t = [ni() for _ in range(b)]
query = [ni() for _ in range(q)]
for qi in query:
shrine_right = float('inf')
temple_right = float('inf')
shrine_right_idx = bisect_right(s, qi)
temple_right_idx = bisect_right(t, qi)
if shrine_right_idx < a:
shrine_right = s[shrine_right_idx]
if temple_right_idx < b:
temple_right = t[temple_right_idx]
shrine_left = float('inf')
temple_left = float('inf')
if shrine_right_idx > 0:
shrine_left = s[shrine_right_idx - 1]
if temple_right_idx > 0:
temple_left = t[temple_right_idx - 1]
cand = []
# 前前
cand.append(max(abs(qi - shrine_left), abs(qi - temple_left)))
# 前後
cand.append(abs(temple_right-shrine_left) + min(abs(qi - shrine_left), abs(qi - temple_right)))
# 後前
cand.append(abs(shrine_right-temple_left) + min(abs(qi - temple_left), abs(qi - shrine_right)))
# 後後
cand.append(max(abs(qi - shrine_right), abs(qi - temple_right)))
print((min(cand))) | import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
from bisect import bisect_left
def find_left_right(lis: list, pos: int):
left_idx = bisect_left(lis, pos) - 1
left = lis[left_idx]
right = lis[left_idx+1]
return left, right
def find_min(sh_l, sh_r, tm_l, tm_r, x):
ret = 10**18
ret = min(ret, max(x-sh_l, x-tm_l))
ret = min(ret, (tm_r - sh_l + min(x-sh_l, tm_r-x)))
ret = min(ret, (sh_r - tm_l + min(x-tm_l, sh_r-x)))
ret = min(ret, max(sh_r-x, tm_r-x))
return ret
a,b,q = li()
INF = 10**18
s = [-INF] + [ni() for _ in range(a)] + [INF]
t = [-INF] + [ni() for _ in range(b)] + [INF]
x = [ni() for _ in range(q)]
for xi in x:
shrine_left, shrine_right = find_left_right(s, xi)
temple_left, temple_right = find_left_right(t, xi)
print((find_min(shrine_left, shrine_right, temple_left, temple_right, xi)))
| 58 | 41 | 1,632 | 1,280 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
from bisect import bisect_right
a, b, q = li()
s = [ni() for _ in range(a)]
t = [ni() for _ in range(b)]
query = [ni() for _ in range(q)]
for qi in query:
shrine_right = float("inf")
temple_right = float("inf")
shrine_right_idx = bisect_right(s, qi)
temple_right_idx = bisect_right(t, qi)
if shrine_right_idx < a:
shrine_right = s[shrine_right_idx]
if temple_right_idx < b:
temple_right = t[temple_right_idx]
shrine_left = float("inf")
temple_left = float("inf")
if shrine_right_idx > 0:
shrine_left = s[shrine_right_idx - 1]
if temple_right_idx > 0:
temple_left = t[temple_right_idx - 1]
cand = []
# 前前
cand.append(max(abs(qi - shrine_left), abs(qi - temple_left)))
# 前後
cand.append(
abs(temple_right - shrine_left)
+ min(abs(qi - shrine_left), abs(qi - temple_right))
)
# 後前
cand.append(
abs(shrine_right - temple_left)
+ min(abs(qi - temple_left), abs(qi - shrine_right))
)
# 後後
cand.append(max(abs(qi - shrine_right), abs(qi - temple_right)))
print((min(cand)))
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
from bisect import bisect_left
def find_left_right(lis: list, pos: int):
left_idx = bisect_left(lis, pos) - 1
left = lis[left_idx]
right = lis[left_idx + 1]
return left, right
def find_min(sh_l, sh_r, tm_l, tm_r, x):
ret = 10**18
ret = min(ret, max(x - sh_l, x - tm_l))
ret = min(ret, (tm_r - sh_l + min(x - sh_l, tm_r - x)))
ret = min(ret, (sh_r - tm_l + min(x - tm_l, sh_r - x)))
ret = min(ret, max(sh_r - x, tm_r - x))
return ret
a, b, q = li()
INF = 10**18
s = [-INF] + [ni() for _ in range(a)] + [INF]
t = [-INF] + [ni() for _ in range(b)] + [INF]
x = [ni() for _ in range(q)]
for xi in x:
shrine_left, shrine_right = find_left_right(s, xi)
temple_left, temple_right = find_left_right(t, xi)
print((find_min(shrine_left, shrine_right, temple_left, temple_right, xi)))
| false | 29.310345 | [
"-sys.setrecursionlimit(10**5)",
"+sys.setrecursionlimit(10**7)",
"-from bisect import bisect_right",
"+from bisect import bisect_left",
"+",
"+",
"+def find_left_right(lis: list, pos: int):",
"+ left_idx = bisect_left(lis, pos) - 1",
"+ left = lis[left_idx]",
"+ right = lis[left_idx + 1]",
"+ return left, right",
"+",
"+",
"+def find_min(sh_l, sh_r, tm_l, tm_r, x):",
"+ ret = 10**18",
"+ ret = min(ret, max(x - sh_l, x - tm_l))",
"+ ret = min(ret, (tm_r - sh_l + min(x - sh_l, tm_r - x)))",
"+ ret = min(ret, (sh_r - tm_l + min(x - tm_l, sh_r - x)))",
"+ ret = min(ret, max(sh_r - x, tm_r - x))",
"+ return ret",
"+",
"-s = [ni() for _ in range(a)]",
"-t = [ni() for _ in range(b)]",
"-query = [ni() for _ in range(q)]",
"-for qi in query:",
"- shrine_right = float(\"inf\")",
"- temple_right = float(\"inf\")",
"- shrine_right_idx = bisect_right(s, qi)",
"- temple_right_idx = bisect_right(t, qi)",
"- if shrine_right_idx < a:",
"- shrine_right = s[shrine_right_idx]",
"- if temple_right_idx < b:",
"- temple_right = t[temple_right_idx]",
"- shrine_left = float(\"inf\")",
"- temple_left = float(\"inf\")",
"- if shrine_right_idx > 0:",
"- shrine_left = s[shrine_right_idx - 1]",
"- if temple_right_idx > 0:",
"- temple_left = t[temple_right_idx - 1]",
"- cand = []",
"- # 前前",
"- cand.append(max(abs(qi - shrine_left), abs(qi - temple_left)))",
"- # 前後",
"- cand.append(",
"- abs(temple_right - shrine_left)",
"- + min(abs(qi - shrine_left), abs(qi - temple_right))",
"- )",
"- # 後前",
"- cand.append(",
"- abs(shrine_right - temple_left)",
"- + min(abs(qi - temple_left), abs(qi - shrine_right))",
"- )",
"- # 後後",
"- cand.append(max(abs(qi - shrine_right), abs(qi - temple_right)))",
"- print((min(cand)))",
"+INF = 10**18",
"+s = [-INF] + [ni() for _ in range(a)] + [INF]",
"+t = [-INF] + [ni() for _ in range(b)] + [INF]",
"+x = [ni() for _ in range(q)]",
"+for xi in x:",
"+ shrine_left, shrine_right = find_left_right(s, xi)",
"+ temple_left, temple_right = find_left_right(t, xi)",
"+ print((find_min(shrine_left, shrine_right, temple_left, temple_right, xi)))"
]
| false | 0.037066 | 0.084682 | 0.437706 | [
"s728974090",
"s873410979"
]
|
u612975321 | p03588 | python | s031745366 | s242960000 | 264 | 164 | 29,144 | 29,448 | Accepted | Accepted | 37.88 | n = int(eval(input()))
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x:x[0])
print((ab[-1][0] + ab[-1][1])) | import sys
input = sys.stdin.buffer.readline
n = int(eval(input()))
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x:x[0])
print((ab[-1][0] + ab[-1][1])) | 4 | 7 | 140 | 189 | n = int(eval(input()))
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x: x[0])
print((ab[-1][0] + ab[-1][1]))
| import sys
input = sys.stdin.buffer.readline
n = int(eval(input()))
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x: x[0])
print((ab[-1][0] + ab[-1][1]))
| false | 42.857143 | [
"+import sys",
"+",
"+input = sys.stdin.buffer.readline"
]
| false | 0.041822 | 0.04116 | 1.016098 | [
"s031745366",
"s242960000"
]
|
u077291787 | p03733 | python | s512500468 | s550678574 | 133 | 107 | 26,832 | 26,836 | Accepted | Accepted | 19.55 | #ARC073C - Sentou
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, lst[0]
for i in lst[1:]:
ans += min(t, i - cur)
cur = i
ans += t
print(ans) | # ARC073C - Sentou (ABC060C)
def main():
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, lst[0]
for i in lst[1:]:
ans += min(t, i - cur)
cur = i
ans += t
print(ans)
if __name__ == "__main__":
main() | 9 | 14 | 218 | 318 | # ARC073C - Sentou
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, lst[0]
for i in lst[1:]:
ans += min(t, i - cur)
cur = i
ans += t
print(ans)
| # ARC073C - Sentou (ABC060C)
def main():
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, lst[0]
for i in lst[1:]:
ans += min(t, i - cur)
cur = i
ans += t
print(ans)
if __name__ == "__main__":
main()
| false | 35.714286 | [
"-# ARC073C - Sentou",
"-n, t = list(map(int, input().rstrip().split()))",
"-lst = list(map(int, input().rstrip().split()))",
"-ans, cur = 0, lst[0]",
"-for i in lst[1:]:",
"- ans += min(t, i - cur)",
"- cur = i",
"-ans += t",
"-print(ans)",
"+# ARC073C - Sentou (ABC060C)",
"+def main():",
"+ n, t = list(map(int, input().rstrip().split()))",
"+ lst = list(map(int, input().rstrip().split()))",
"+ ans, cur = 0, lst[0]",
"+ for i in lst[1:]:",
"+ ans += min(t, i - cur)",
"+ cur = i",
"+ ans += t",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.042092 | 0.042228 | 0.99679 | [
"s512500468",
"s550678574"
]
|
u190875453 | p02899 | python | s472046347 | s870508334 | 173 | 94 | 32,452 | 15,588 | Accepted | Accepted | 45.66 | num = int(eval(input()))
li = list(map(int, input().split()))
number = list(range(num))
data = dict(list(zip(number, li)))
data_sorted = sorted(list(data.items()), key = lambda x:x[1])
data_key = [str(i[0] + 1) for i in data_sorted]
print((" ".join(data_key))) | x = int(eval(input()))
num_list = list(map(int, input().split()))
li = list("A" * x)
for index, num in enumerate(num_list):
li[num-1] = str(index+1)
print((" ".join(li))) | 8 | 9 | 248 | 174 | num = int(eval(input()))
li = list(map(int, input().split()))
number = list(range(num))
data = dict(list(zip(number, li)))
data_sorted = sorted(list(data.items()), key=lambda x: x[1])
data_key = [str(i[0] + 1) for i in data_sorted]
print((" ".join(data_key)))
| x = int(eval(input()))
num_list = list(map(int, input().split()))
li = list("A" * x)
for index, num in enumerate(num_list):
li[num - 1] = str(index + 1)
print((" ".join(li)))
| false | 11.111111 | [
"-num = int(eval(input()))",
"-li = list(map(int, input().split()))",
"-number = list(range(num))",
"-data = dict(list(zip(number, li)))",
"-data_sorted = sorted(list(data.items()), key=lambda x: x[1])",
"-data_key = [str(i[0] + 1) for i in data_sorted]",
"-print((\" \".join(data_key)))",
"+x = int(eval(input()))",
"+num_list = list(map(int, input().split()))",
"+li = list(\"A\" * x)",
"+for index, num in enumerate(num_list):",
"+ li[num - 1] = str(index + 1)",
"+print((\" \".join(li)))"
]
| false | 0.041336 | 0.040478 | 1.021201 | [
"s472046347",
"s870508334"
]
|
u188827677 | p02707 | python | s833745068 | s828175886 | 189 | 128 | 34,180 | 32,276 | Accepted | Accepted | 32.28 | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
count = Counter(a)
for i in range(n):
if i+1 in count:
print((count[i+1]))
else:
print((0)) | n = int(input())
a = list(map(int, input().split()))
l = [0]*n
for i in a: l[i-1] += 1
print(*l, sep='\n')
| 10 | 6 | 194 | 112 | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
count = Counter(a)
for i in range(n):
if i + 1 in count:
print((count[i + 1]))
else:
print((0))
| n = int(input())
a = list(map(int, input().split()))
l = [0] * n
for i in a:
l[i - 1] += 1
print(*l, sep="\n")
| false | 40 | [
"-from collections import Counter",
"-",
"-n = int(eval(input()))",
"+n = int(input())",
"-count = Counter(a)",
"-for i in range(n):",
"- if i + 1 in count:",
"- print((count[i + 1]))",
"- else:",
"- print((0))",
"+l = [0] * n",
"+for i in a:",
"+ l[i - 1] += 1",
"+print(*l, sep=\"\\n\")"
]
| false | 0.03696 | 0.036379 | 1.015951 | [
"s833745068",
"s828175886"
]
|
u261103969 | p02584 | python | s835947203 | s699373336 | 80 | 32 | 61,732 | 9,140 | Accepted | Accepted | 60 | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
x, k, d = list(map(int, readline().split()))
cur = abs(x)
rem = k
cnt = min(cur // d, k)
cur -= cnt * d
rem -= cnt
if rem % 2 == 0:
ans = cur
else:
ans = abs(cur - d)
print(ans)
if __name__ == '__main__':
main()
| x, k, d = list(map(int, input().split()))
cur = abs(x) # 座標を正にしてしまいます
rem = k # 残りの移動回数です
cnt = min(cur // d, k) # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt
# 残り回数が0回の場合分けをする必要はないのですが、一応
if rem > 0:
if rem % 2 == 1:
cur = abs(cur - d)
print(cur) | 24 | 15 | 411 | 271 | import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
def main():
x, k, d = list(map(int, readline().split()))
cur = abs(x)
rem = k
cnt = min(cur // d, k)
cur -= cnt * d
rem -= cnt
if rem % 2 == 0:
ans = cur
else:
ans = abs(cur - d)
print(ans)
if __name__ == "__main__":
main()
| x, k, d = list(map(int, input().split()))
cur = abs(x) # 座標を正にしてしまいます
rem = k # 残りの移動回数です
cnt = min(cur // d, k) # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt
# 残り回数が0回の場合分けをする必要はないのですが、一応
if rem > 0:
if rem % 2 == 1:
cur = abs(cur - d)
print(cur)
| false | 37.5 | [
"-import sys",
"-",
"-readline = sys.stdin.readline",
"-MOD = 10**9 + 7",
"-INF = float(\"INF\")",
"-sys.setrecursionlimit(10**5)",
"-",
"-",
"-def main():",
"- x, k, d = list(map(int, readline().split()))",
"- cur = abs(x)",
"- rem = k",
"- cnt = min(cur // d, k)",
"- cur -= cnt * d",
"- rem -= cnt",
"- if rem % 2 == 0:",
"- ans = cur",
"- else:",
"- ans = abs(cur - d)",
"- print(ans)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+x, k, d = list(map(int, input().split()))",
"+cur = abs(x) # 座標を正にしてしまいます",
"+rem = k # 残りの移動回数です",
"+cnt = min(cur // d, k) # 0に向かって移動する回数です",
"+cur -= d * cnt",
"+rem -= cnt",
"+# 残り回数が0回の場合分けをする必要はないのですが、一応",
"+if rem > 0:",
"+ if rem % 2 == 1:",
"+ cur = abs(cur - d)",
"+print(cur)"
]
| false | 0.034272 | 0.031252 | 1.096634 | [
"s835947203",
"s699373336"
]
|
u941438707 | p02900 | python | s026858536 | s298956947 | 483 | 402 | 5,176 | 3,060 | Accepted | Accepted | 16.77 | a,b=list(map(int,input().split()))
from fractions import *
g=gcd(a,b)
c=i=1
while g>1 and i*i<=g:
i+=1
if g%i==0:
c+=1
while g%i==0:
g//=i
print((c+(g>1))) | a,b=list(map(int,input().split()))
c=1
for i in range(2,int(max(a**.5,b**.5))+2):
if a%i==0==b%i:
c+=1
while a%i==0:
a//=i
while b%i==0:
b//=i
if a==b!=1:
c+=1
print(c) | 11 | 12 | 185 | 213 | a, b = list(map(int, input().split()))
from fractions import *
g = gcd(a, b)
c = i = 1
while g > 1 and i * i <= g:
i += 1
if g % i == 0:
c += 1
while g % i == 0:
g //= i
print((c + (g > 1)))
| a, b = list(map(int, input().split()))
c = 1
for i in range(2, int(max(a**0.5, b**0.5)) + 2):
if a % i == 0 == b % i:
c += 1
while a % i == 0:
a //= i
while b % i == 0:
b //= i
if a == b != 1:
c += 1
print(c)
| false | 8.333333 | [
"-from fractions import *",
"-",
"-g = gcd(a, b)",
"-c = i = 1",
"-while g > 1 and i * i <= g:",
"- i += 1",
"- if g % i == 0:",
"+c = 1",
"+for i in range(2, int(max(a**0.5, b**0.5)) + 2):",
"+ if a % i == 0 == b % i:",
"- while g % i == 0:",
"- g //= i",
"-print((c + (g > 1)))",
"+ while a % i == 0:",
"+ a //= i",
"+ while b % i == 0:",
"+ b //= i",
"+if a == b != 1:",
"+ c += 1",
"+print(c)"
]
| false | 0.043344 | 0.06185 | 0.700786 | [
"s026858536",
"s298956947"
]
|
u644907318 | p02879 | python | s311487066 | s716437579 | 181 | 165 | 38,384 | 38,384 | Accepted | Accepted | 8.84 | A,B = list(map(int,input().split()))
if A>=10 or B>=10:
print((-1))
else:
print((A*B)) | A,B = list(map(int,input().split()))
if A<=9 and B<=9:
print((A*B))
else:
print((-1)) | 5 | 5 | 88 | 87 | A, B = list(map(int, input().split()))
if A >= 10 or B >= 10:
print((-1))
else:
print((A * B))
| A, B = list(map(int, input().split()))
if A <= 9 and B <= 9:
print((A * B))
else:
print((-1))
| false | 0 | [
"-if A >= 10 or B >= 10:",
"+if A <= 9 and B <= 9:",
"+ print((A * B))",
"+else:",
"-else:",
"- print((A * B))"
]
| false | 0.150574 | 0.068483 | 2.198699 | [
"s311487066",
"s716437579"
]
|
u089230684 | p03814 | python | s141337922 | s143601040 | 58 | 43 | 3,516 | 3,516 | Accepted | Accepted | 25.86 | s = eval(input())
ans = []
for i in range(len(s)):
if s[i] == "A":
j = i
break
for i in range(len(s)):
if s[len(s)-i-1] == "Z":
k = len(s)-i-1
break
ans = k-j+1
print(ans) | string = eval(input())
index = -1
for i in range(len(string)):
if string[i] == "Z":
index = i
w = string.index("A")
z = string[w:index+1]
print((len(z))) | 12 | 8 | 216 | 175 | s = eval(input())
ans = []
for i in range(len(s)):
if s[i] == "A":
j = i
break
for i in range(len(s)):
if s[len(s) - i - 1] == "Z":
k = len(s) - i - 1
break
ans = k - j + 1
print(ans)
| string = eval(input())
index = -1
for i in range(len(string)):
if string[i] == "Z":
index = i
w = string.index("A")
z = string[w : index + 1]
print((len(z)))
| false | 33.333333 | [
"-s = eval(input())",
"-ans = []",
"-for i in range(len(s)):",
"- if s[i] == \"A\":",
"- j = i",
"- break",
"-for i in range(len(s)):",
"- if s[len(s) - i - 1] == \"Z\":",
"- k = len(s) - i - 1",
"- break",
"-ans = k - j + 1",
"-print(ans)",
"+string = eval(input())",
"+index = -1",
"+for i in range(len(string)):",
"+ if string[i] == \"Z\":",
"+ index = i",
"+w = string.index(\"A\")",
"+z = string[w : index + 1]",
"+print((len(z)))"
]
| false | 0.036949 | 0.035952 | 1.027731 | [
"s141337922",
"s143601040"
]
|
u761320129 | p03328 | python | s882327790 | s368737809 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | a,b = list(map(int,input().split()))
d = b-a
b_len = d*(d+1)//2
print((b_len - b)) | a,b = list(map(int,input().split()))
s = 0
for n in range(1000):
if b-a == n:
print((s-a))
break
s += n | 4 | 8 | 77 | 127 | a, b = list(map(int, input().split()))
d = b - a
b_len = d * (d + 1) // 2
print((b_len - b))
| a, b = list(map(int, input().split()))
s = 0
for n in range(1000):
if b - a == n:
print((s - a))
break
s += n
| false | 50 | [
"-d = b - a",
"-b_len = d * (d + 1) // 2",
"-print((b_len - b))",
"+s = 0",
"+for n in range(1000):",
"+ if b - a == n:",
"+ print((s - a))",
"+ break",
"+ s += n"
]
| false | 0.042195 | 0.043574 | 0.968346 | [
"s882327790",
"s368737809"
]
|
u533039576 | p02937 | python | s889789719 | s497319104 | 364 | 260 | 95,196 | 53,104 | Accepted | Accepted | 28.57 | from collections import defaultdict
s = eval(input())
t = eval(input())
ds = defaultdict(int)
for i in range(len(s)):
ds[s[i]] += 1
dt = defaultdict(int)
for i in range(len(t)):
dt[t[i]] += 1
possible = True
for ti in dt:
if ti not in ds:
possible = False
break
if possible:
n = len(s)
pos = defaultdict(list)
for i in range(n*2):
pos[s[i%n]].append(i)
edge = defaultdict(list)
for c in pos:
x = 0
for i in range(n):
if i >= pos[c][x]:
x += 1
edge[c].append(pos[c][x])
# print(pos)
# print(edge)
ans = 0
x = 0
for i in range(n):
if s[i] == t[0]:
ans = i + 1
x = i
break
# print(ans)
for i in range(1, len(t)):
ans += edge[t[i]][x%n] - x
x = edge[t[i]][x%n] % n
# print(ans, t[i])
else:
ans = -1
print(ans)
| from collections import defaultdict
from bisect import bisect_left, bisect_right
s = eval(input())
t = eval(input())
n = len(s)
ds = defaultdict(list)
for i in range(n*2):
ds[s[i%n]].append(i)
ans = 0
x = -1
for i in range(len(t)):
if t[i] not in ds:
ans = -1
break
x_next = ds[t[i]][bisect_right(ds[t[i]], x)]
ans += x_next - x
x = x_next % n
# print(ans, t[i])
print(ans)
| 52 | 23 | 966 | 428 | from collections import defaultdict
s = eval(input())
t = eval(input())
ds = defaultdict(int)
for i in range(len(s)):
ds[s[i]] += 1
dt = defaultdict(int)
for i in range(len(t)):
dt[t[i]] += 1
possible = True
for ti in dt:
if ti not in ds:
possible = False
break
if possible:
n = len(s)
pos = defaultdict(list)
for i in range(n * 2):
pos[s[i % n]].append(i)
edge = defaultdict(list)
for c in pos:
x = 0
for i in range(n):
if i >= pos[c][x]:
x += 1
edge[c].append(pos[c][x])
# print(pos)
# print(edge)
ans = 0
x = 0
for i in range(n):
if s[i] == t[0]:
ans = i + 1
x = i
break
# print(ans)
for i in range(1, len(t)):
ans += edge[t[i]][x % n] - x
x = edge[t[i]][x % n] % n
# print(ans, t[i])
else:
ans = -1
print(ans)
| from collections import defaultdict
from bisect import bisect_left, bisect_right
s = eval(input())
t = eval(input())
n = len(s)
ds = defaultdict(list)
for i in range(n * 2):
ds[s[i % n]].append(i)
ans = 0
x = -1
for i in range(len(t)):
if t[i] not in ds:
ans = -1
break
x_next = ds[t[i]][bisect_right(ds[t[i]], x)]
ans += x_next - x
x = x_next % n
# print(ans, t[i])
print(ans)
| false | 55.769231 | [
"+from bisect import bisect_left, bisect_right",
"-ds = defaultdict(int)",
"-for i in range(len(s)):",
"- ds[s[i]] += 1",
"-dt = defaultdict(int)",
"+n = len(s)",
"+ds = defaultdict(list)",
"+for i in range(n * 2):",
"+ ds[s[i % n]].append(i)",
"+ans = 0",
"+x = -1",
"- dt[t[i]] += 1",
"-possible = True",
"-for ti in dt:",
"- if ti not in ds:",
"- possible = False",
"+ if t[i] not in ds:",
"+ ans = -1",
"-if possible:",
"- n = len(s)",
"- pos = defaultdict(list)",
"- for i in range(n * 2):",
"- pos[s[i % n]].append(i)",
"- edge = defaultdict(list)",
"- for c in pos:",
"- x = 0",
"- for i in range(n):",
"- if i >= pos[c][x]:",
"- x += 1",
"- edge[c].append(pos[c][x])",
"- # print(pos)",
"- # print(edge)",
"- ans = 0",
"- x = 0",
"- for i in range(n):",
"- if s[i] == t[0]:",
"- ans = i + 1",
"- x = i",
"- break",
"- # print(ans)",
"- for i in range(1, len(t)):",
"- ans += edge[t[i]][x % n] - x",
"- x = edge[t[i]][x % n] % n",
"- # print(ans, t[i])",
"-else:",
"- ans = -1",
"+ x_next = ds[t[i]][bisect_right(ds[t[i]], x)]",
"+ ans += x_next - x",
"+ x = x_next % n",
"+ # print(ans, t[i])"
]
| false | 0.076375 | 0.041512 | 1.839836 | [
"s889789719",
"s497319104"
]
|
u500673386 | p03109 | python | s153061325 | s988481510 | 48 | 27 | 10,304 | 9,024 | Accepted | Accepted | 43.75 | import datetime as dt
S=eval(input())
s=dt.datetime.strptime(S,'%Y/%m/%d')
A='2019/04/30'
a=dt.datetime.strptime(A,'%Y/%m/%d')
if s<=a:
print('Heisei')
else:
print('TBD')
| S=eval(input())
if S<='2019/04/30':
print('Heisei')
else:
print('TBD') | 9 | 5 | 181 | 76 | import datetime as dt
S = eval(input())
s = dt.datetime.strptime(S, "%Y/%m/%d")
A = "2019/04/30"
a = dt.datetime.strptime(A, "%Y/%m/%d")
if s <= a:
print("Heisei")
else:
print("TBD")
| S = eval(input())
if S <= "2019/04/30":
print("Heisei")
else:
print("TBD")
| false | 44.444444 | [
"-import datetime as dt",
"-",
"-s = dt.datetime.strptime(S, \"%Y/%m/%d\")",
"-A = \"2019/04/30\"",
"-a = dt.datetime.strptime(A, \"%Y/%m/%d\")",
"-if s <= a:",
"+if S <= \"2019/04/30\":"
]
| false | 0.039313 | 0.063065 | 0.623368 | [
"s153061325",
"s988481510"
]
|
u546853743 | p03434 | python | s231161144 | s398549720 | 28 | 25 | 9,124 | 9,016 | Accepted | Accepted | 10.71 | n=int(eval(input()))
a=list(map(int,input().split()))
s=0
a.sort()
s=sum(a[:n:2])-sum(a[1:n:2])
if s>0:
print(s)
else:
print((-s)) | n=int(eval(input()))
a=list(map(int,input().split()))
s=0
a.sort()
s=sum(a[:n:2])-sum(a[1:n:2])
print((abs(s))) | 9 | 7 | 138 | 110 | n = int(eval(input()))
a = list(map(int, input().split()))
s = 0
a.sort()
s = sum(a[:n:2]) - sum(a[1:n:2])
if s > 0:
print(s)
else:
print((-s))
| n = int(eval(input()))
a = list(map(int, input().split()))
s = 0
a.sort()
s = sum(a[:n:2]) - sum(a[1:n:2])
print((abs(s)))
| false | 22.222222 | [
"-if s > 0:",
"- print(s)",
"-else:",
"- print((-s))",
"+print((abs(s)))"
]
| false | 0.055948 | 0.076489 | 0.731449 | [
"s231161144",
"s398549720"
]
|
u757117214 | p02897 | python | s258006166 | s435416491 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | n = int(eval(input()))
if n == 1:
print((1))
elif n % 2 == 0:
print((0.5))
else:
print(((n+1)/2/n))
| n = int(eval(input()))
print((1 if n == 1 else 0.5 if n%2 == 0 else (n+1)/2/n)) | 8 | 2 | 109 | 72 | n = int(eval(input()))
if n == 1:
print((1))
elif n % 2 == 0:
print((0.5))
else:
print(((n + 1) / 2 / n))
| n = int(eval(input()))
print((1 if n == 1 else 0.5 if n % 2 == 0 else (n + 1) / 2 / n))
| false | 75 | [
"-if n == 1:",
"- print((1))",
"-elif n % 2 == 0:",
"- print((0.5))",
"-else:",
"- print(((n + 1) / 2 / n))",
"+print((1 if n == 1 else 0.5 if n % 2 == 0 else (n + 1) / 2 / n))"
]
| false | 0.038012 | 0.03905 | 0.973424 | [
"s258006166",
"s435416491"
]
|
u604839890 | p02641 | python | s792516073 | s704802349 | 82 | 65 | 64,704 | 64,984 | Accepted | Accepted | 20.73 | x,n=list(map(int,input().split()))
if n!=0: #空行の読み込みを回避、処理を高速化するためにpiを集合型で管理する
s=set(list(map(int,input().split())))
else:
s=[]
diff=10**18
ans=10**18
for i in range(-10000,10000): #十分大きな範囲の整数について確かめる
if i in s: #{pi}に含まれる場合は計算を行わない
continue
else:
if abs(x-i)<diff: #Xとの差の絶対値が最小になるものを求める
ans=i
diff=abs(x-i)
print(ans) | x,n=list(map(int,input().split()))
if n!=0:
s=set(list(map(int,input().split())))
else:
s=[]
diff=10**18
ans=10**18
for i in range(-10000,10000):
if i in s:
continue
else:
if abs(x-i)<diff:
ans=i
diff=abs(x-i)
print(ans) | 15 | 15 | 346 | 248 | x, n = list(map(int, input().split()))
if n != 0: # 空行の読み込みを回避、処理を高速化するためにpiを集合型で管理する
s = set(list(map(int, input().split())))
else:
s = []
diff = 10**18
ans = 10**18
for i in range(-10000, 10000): # 十分大きな範囲の整数について確かめる
if i in s: # {pi}に含まれる場合は計算を行わない
continue
else:
if abs(x - i) < diff: # Xとの差の絶対値が最小になるものを求める
ans = i
diff = abs(x - i)
print(ans)
| x, n = list(map(int, input().split()))
if n != 0:
s = set(list(map(int, input().split())))
else:
s = []
diff = 10**18
ans = 10**18
for i in range(-10000, 10000):
if i in s:
continue
else:
if abs(x - i) < diff:
ans = i
diff = abs(x - i)
print(ans)
| false | 0 | [
"-if n != 0: # 空行の読み込みを回避、処理を高速化するためにpiを集合型で管理する",
"+if n != 0:",
"-for i in range(-10000, 10000): # 十分大きな範囲の整数について確かめる",
"- if i in s: # {pi}に含まれる場合は計算を行わない",
"+for i in range(-10000, 10000):",
"+ if i in s:",
"- if abs(x - i) < diff: # Xとの差の絶対値が最小になるものを求める",
"+ if abs(x - i) < diff:"
]
| false | 0.052785 | 0.059316 | 0.889888 | [
"s792516073",
"s704802349"
]
|
u099155265 | p02399 | python | s501798091 | s495655449 | 30 | 20 | 7,644 | 7,644 | Accepted | Accepted | 33.33 | a, b = list(map(int, input().split()))
print(("{0} {1} {2}".format(a//b, a%b, format(a / b, '.5f')))) | a, b = list(map(int, input().split()))
print(("{0:d} {1:d} {2:f}".format(a//b, a%b, a / b))) | 3 | 3 | 102 | 93 | a, b = list(map(int, input().split()))
print(("{0} {1} {2}".format(a // b, a % b, format(a / b, ".5f"))))
| a, b = list(map(int, input().split()))
print(("{0:d} {1:d} {2:f}".format(a // b, a % b, a / b)))
| false | 0 | [
"-print((\"{0} {1} {2}\".format(a // b, a % b, format(a / b, \".5f\"))))",
"+print((\"{0:d} {1:d} {2:f}\".format(a // b, a % b, a / b)))"
]
| false | 0.083647 | 0.040588 | 2.060889 | [
"s501798091",
"s495655449"
]
|
u553987207 | p02983 | python | s892733357 | s871544775 | 789 | 718 | 2,940 | 9,168 | Accepted | Accepted | 9 | L, R = list(map(int, input().split()))
r = L + min(2019, R - L)
ans = 2019
for i in range(L, r):
for j in range(i + 1, r + 1):
ans = min(ans, (i * j) % 2019)
print(ans) | L, R = list(map(int, input().split()))
MOD = 2019
ans = MOD
R = min(R, L + MOD)
for i in range(L, R):
for j in range(i + 1, R + 1):
ans = min(ans, (i * j) % MOD)
print(ans) | 7 | 8 | 180 | 185 | L, R = list(map(int, input().split()))
r = L + min(2019, R - L)
ans = 2019
for i in range(L, r):
for j in range(i + 1, r + 1):
ans = min(ans, (i * j) % 2019)
print(ans)
| L, R = list(map(int, input().split()))
MOD = 2019
ans = MOD
R = min(R, L + MOD)
for i in range(L, R):
for j in range(i + 1, R + 1):
ans = min(ans, (i * j) % MOD)
print(ans)
| false | 12.5 | [
"-r = L + min(2019, R - L)",
"-ans = 2019",
"-for i in range(L, r):",
"- for j in range(i + 1, r + 1):",
"- ans = min(ans, (i * j) % 2019)",
"+MOD = 2019",
"+ans = MOD",
"+R = min(R, L + MOD)",
"+for i in range(L, R):",
"+ for j in range(i + 1, R + 1):",
"+ ans = min(ans, (i * j) % MOD)"
]
| false | 0.065138 | 0.066475 | 0.979896 | [
"s892733357",
"s871544775"
]
|
u227438830 | p02406 | python | s449848899 | s638481333 | 30 | 20 | 8,440 | 5,868 | Accepted | Accepted | 33.33 | n = int(eval(input()))
list_a = [i for i in range(1,n+1) if i % 3 ==0]
list_b = []
for i in range (1,n+1):
j = i
while True:
if j == 0:
break
elif j % 10 == 3:
list_b.append(i)
break
j = j // 10
a = set(list_a)
b = set(list_b)
c =list(a | b)
c.sort()
print((" " + " ".join(map(str,c)))) | n = int(input())
for i in range(1,n+1):
if i%3 == 0 or i%10 ==3 or (i//10)%10 ==3 or (i//100)%10 ==3 or (i//1000)%10 ==3 :
print(' '+str(i),end = '')
print()
| 18 | 5 | 368 | 174 | n = int(eval(input()))
list_a = [i for i in range(1, n + 1) if i % 3 == 0]
list_b = []
for i in range(1, n + 1):
j = i
while True:
if j == 0:
break
elif j % 10 == 3:
list_b.append(i)
break
j = j // 10
a = set(list_a)
b = set(list_b)
c = list(a | b)
c.sort()
print((" " + " ".join(map(str, c))))
| n = int(input())
for i in range(1, n + 1):
if (
i % 3 == 0
or i % 10 == 3
or (i // 10) % 10 == 3
or (i // 100) % 10 == 3
or (i // 1000) % 10 == 3
):
print(" " + str(i), end="")
print()
| false | 72.222222 | [
"-n = int(eval(input()))",
"-list_a = [i for i in range(1, n + 1) if i % 3 == 0]",
"-list_b = []",
"+n = int(input())",
"- j = i",
"- while True:",
"- if j == 0:",
"- break",
"- elif j % 10 == 3:",
"- list_b.append(i)",
"- break",
"- j = j // 10",
"-a = set(list_a)",
"-b = set(list_b)",
"-c = list(a | b)",
"-c.sort()",
"-print((\" \" + \" \".join(map(str, c))))",
"+ if (",
"+ i % 3 == 0",
"+ or i % 10 == 3",
"+ or (i // 10) % 10 == 3",
"+ or (i // 100) % 10 == 3",
"+ or (i // 1000) % 10 == 3",
"+ ):",
"+ print(\" \" + str(i), end=\"\")",
"+print()"
]
| false | 0.043689 | 0.042962 | 1.016922 | [
"s449848899",
"s638481333"
]
|
u661977789 | p02607 | python | s650777884 | s013315136 | 29 | 25 | 9,080 | 9,100 | Accepted | Accepted | 13.79 | eval(input())
print((len([i for n,i in enumerate(map(int,input().split()),1) if i%2==1 and n%2]))) | eval(input())
print((len([i for i in list(map(int,input().split()))[::2] if i%2]))) | 2 | 2 | 91 | 76 | eval(input())
print(
(
len(
[
i
for n, i in enumerate(map(int, input().split()), 1)
if i % 2 == 1 and n % 2
]
)
)
)
| eval(input())
print((len([i for i in list(map(int, input().split()))[::2] if i % 2])))
| false | 0 | [
"-print(",
"- (",
"- len(",
"- [",
"- i",
"- for n, i in enumerate(map(int, input().split()), 1)",
"- if i % 2 == 1 and n % 2",
"- ]",
"- )",
"- )",
"-)",
"+print((len([i for i in list(map(int, input().split()))[::2] if i % 2])))"
]
| false | 0.042625 | 0.03252 | 1.31072 | [
"s650777884",
"s013315136"
]
|
u761320129 | p03946 | python | s535033473 | s338249098 | 97 | 79 | 15,020 | 14,292 | Accepted | Accepted | 18.56 | N,T = list(map(int,input().split()))
src = list(map(int,input().split()))
minv = src[0]
maxp = ans = 0
for i in range(1,N):
profit = src[i] - minv
if profit == maxp:
ans += 1
elif profit > maxp:
maxp = profit
ans = 1
minv = min(minv, src[i])
print(ans) | N,T = list(map(int,input().split()))
src = list(map(int,input().split()))
mincost = src[0]
maxgain = 0
sell = 0
buy = 1
for a in src[1:]:
if a < mincost:
mincost = a
buy = 1
elif a == mincost:
buy += 1
elif a > mincost + maxgain:
maxgain = a - mincost
sell = 1
elif a == mincost + maxgain:
sell += 1
print((max(sell,buy)))
| 14 | 20 | 300 | 400 | N, T = list(map(int, input().split()))
src = list(map(int, input().split()))
minv = src[0]
maxp = ans = 0
for i in range(1, N):
profit = src[i] - minv
if profit == maxp:
ans += 1
elif profit > maxp:
maxp = profit
ans = 1
minv = min(minv, src[i])
print(ans)
| N, T = list(map(int, input().split()))
src = list(map(int, input().split()))
mincost = src[0]
maxgain = 0
sell = 0
buy = 1
for a in src[1:]:
if a < mincost:
mincost = a
buy = 1
elif a == mincost:
buy += 1
elif a > mincost + maxgain:
maxgain = a - mincost
sell = 1
elif a == mincost + maxgain:
sell += 1
print((max(sell, buy)))
| false | 30 | [
"-minv = src[0]",
"-maxp = ans = 0",
"-for i in range(1, N):",
"- profit = src[i] - minv",
"- if profit == maxp:",
"- ans += 1",
"- elif profit > maxp:",
"- maxp = profit",
"- ans = 1",
"- minv = min(minv, src[i])",
"-print(ans)",
"+mincost = src[0]",
"+maxgain = 0",
"+sell = 0",
"+buy = 1",
"+for a in src[1:]:",
"+ if a < mincost:",
"+ mincost = a",
"+ buy = 1",
"+ elif a == mincost:",
"+ buy += 1",
"+ elif a > mincost + maxgain:",
"+ maxgain = a - mincost",
"+ sell = 1",
"+ elif a == mincost + maxgain:",
"+ sell += 1",
"+print((max(sell, buy)))"
]
| false | 0.050395 | 0.047046 | 1.071189 | [
"s535033473",
"s338249098"
]
|
u864197622 | p03225 | python | s609103237 | s802694309 | 1,551 | 1,010 | 56,940 | 5,108 | Accepted | Accepted | 34.88 | H, W = list(map(int, input().split()))
I = [eval(input()) for _ in range(H)]
X = [[[0, 1][a=="#"] for a in inp] for inp in I]
k = 32
def r():
global H, W, I
I = ["".join([I[H - 1 - j][i] for j in range(H)]) for i in range(W)]
H, W = W, H
def st1(s):
return int(s.replace("#", "1" * k).replace(".", "0" * k), 2)
def st2(s):
return int(s.replace("#", "0" * (k - 1) + "1").replace(".", "0" * k), 2)
def getsum(x):
for i in range(8):
x += x >> (k << i)
return x & ((1 << k) - 1)
ans = 0
for _ in range(4):
A1 = [st1(inp) for inp in I]
A2 = [st1("".join([I[i][j] for i in range(H)])) for j in range(W)]
B = [st2(inp[::-1]) for i, inp in enumerate(I)]
C = [[0] * W for _ in range(H)]
for j in range(W):
s = 0
m = (1 << j * k) - 1
for i in range(H)[::-1]:
s <<= k
s += B[i] >> (j+1) * k
s &= m
C[i][j] = s
for i in range(1, H):
for j in range(1, W):
ans += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & C[i][j]
r()
print((getsum(ans))) | H, W = list(map(int, input().split()))
I = [eval(input()) for _ in range(H)]
X = [[[0, 1][a=="#"] for a in inp] for inp in I]
k = 21
def r():
global H, W, I
I = ["".join([I[H - 1 - j][i] for j in range(H)]) for i in range(W)]
H, W = W, H
def st1(s):
return int(s.replace("#", "1" * k).replace(".", "0" * k), 2)
def st2(s):
return int(s.replace("#", "0" * (k - 1) + "1").replace(".", "0" * k), 2)
def getsum(x):
for i in range(8):
x += x >> (k << i)
return x & ((1 << k) - 1)
ans = 0
for _ in range(4):
A1 = [st1(inp) for inp in I]
A2 = [st1("".join([I[i][j] for i in range(H)])) for j in range(W)]
B = [st2(inp[::-1]) for i, inp in enumerate(I)]
for j in range(W):
s, t = 0, 0
m = (1 << j * k) - 1
for i in range(H)[::-1]:
s = ((B[i] >> (j + 1) * k) + (s << k)) & m
t += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & s
ans += getsum(t)
r()
print(ans) | 37 | 31 | 1,120 | 981 | H, W = list(map(int, input().split()))
I = [eval(input()) for _ in range(H)]
X = [[[0, 1][a == "#"] for a in inp] for inp in I]
k = 32
def r():
global H, W, I
I = ["".join([I[H - 1 - j][i] for j in range(H)]) for i in range(W)]
H, W = W, H
def st1(s):
return int(s.replace("#", "1" * k).replace(".", "0" * k), 2)
def st2(s):
return int(s.replace("#", "0" * (k - 1) + "1").replace(".", "0" * k), 2)
def getsum(x):
for i in range(8):
x += x >> (k << i)
return x & ((1 << k) - 1)
ans = 0
for _ in range(4):
A1 = [st1(inp) for inp in I]
A2 = [st1("".join([I[i][j] for i in range(H)])) for j in range(W)]
B = [st2(inp[::-1]) for i, inp in enumerate(I)]
C = [[0] * W for _ in range(H)]
for j in range(W):
s = 0
m = (1 << j * k) - 1
for i in range(H)[::-1]:
s <<= k
s += B[i] >> (j + 1) * k
s &= m
C[i][j] = s
for i in range(1, H):
for j in range(1, W):
ans += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & C[i][j]
r()
print((getsum(ans)))
| H, W = list(map(int, input().split()))
I = [eval(input()) for _ in range(H)]
X = [[[0, 1][a == "#"] for a in inp] for inp in I]
k = 21
def r():
global H, W, I
I = ["".join([I[H - 1 - j][i] for j in range(H)]) for i in range(W)]
H, W = W, H
def st1(s):
return int(s.replace("#", "1" * k).replace(".", "0" * k), 2)
def st2(s):
return int(s.replace("#", "0" * (k - 1) + "1").replace(".", "0" * k), 2)
def getsum(x):
for i in range(8):
x += x >> (k << i)
return x & ((1 << k) - 1)
ans = 0
for _ in range(4):
A1 = [st1(inp) for inp in I]
A2 = [st1("".join([I[i][j] for i in range(H)])) for j in range(W)]
B = [st2(inp[::-1]) for i, inp in enumerate(I)]
for j in range(W):
s, t = 0, 0
m = (1 << j * k) - 1
for i in range(H)[::-1]:
s = ((B[i] >> (j + 1) * k) + (s << k)) & m
t += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & s
ans += getsum(t)
r()
print(ans)
| false | 16.216216 | [
"-k = 32",
"+k = 21",
"- C = [[0] * W for _ in range(H)]",
"- s = 0",
"+ s, t = 0, 0",
"- s <<= k",
"- s += B[i] >> (j + 1) * k",
"- s &= m",
"- C[i][j] = s",
"- for i in range(1, H):",
"- for j in range(1, W):",
"- ans += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & C[i][j]",
"+ s = ((B[i] >> (j + 1) * k) + (s << k)) & m",
"+ t += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & s",
"+ ans += getsum(t)",
"-print((getsum(ans)))",
"+print(ans)"
]
| false | 0.044153 | 0.037498 | 1.177474 | [
"s609103237",
"s802694309"
]
|
u025501820 | p02727 | python | s751940979 | s527547245 | 957 | 258 | 51,988 | 22,504 | Accepted | Accepted | 73.04 | X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
red = [[i, "r"] for i in p]
green = [[i, "g"] for i in q]
white = [[i, "w"] for i in r]
total = sorted(red + green + white)[::-1]
ans = 0
cnt = 0
r_cnt = 0
g_cnt = 0
for t in total:
if t[1] == "r" and r_cnt == X:
continue
if t[1] == "g" and g_cnt == Y:
continue
ans += t[0]
if t[1] == "r":
r_cnt += 1
elif t[1] == "g":
g_cnt += 1
cnt += 1
if cnt == X + Y:
break
print(ans) | X, Y, A, B, C = list(map(int, input().split()))
p = sorted(list(map(int, input().split())))[-X:]
q = sorted(list(map(int, input().split())))[-Y:]
r = list(map(int, input().split()))
total = sorted(p + q + r)[::-1]
print((sum(total[:X + Y])))
| 30 | 7 | 623 | 241 | X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
red = [[i, "r"] for i in p]
green = [[i, "g"] for i in q]
white = [[i, "w"] for i in r]
total = sorted(red + green + white)[::-1]
ans = 0
cnt = 0
r_cnt = 0
g_cnt = 0
for t in total:
if t[1] == "r" and r_cnt == X:
continue
if t[1] == "g" and g_cnt == Y:
continue
ans += t[0]
if t[1] == "r":
r_cnt += 1
elif t[1] == "g":
g_cnt += 1
cnt += 1
if cnt == X + Y:
break
print(ans)
| X, Y, A, B, C = list(map(int, input().split()))
p = sorted(list(map(int, input().split())))[-X:]
q = sorted(list(map(int, input().split())))[-Y:]
r = list(map(int, input().split()))
total = sorted(p + q + r)[::-1]
print((sum(total[: X + Y])))
| false | 76.666667 | [
"-p = list(map(int, input().split()))",
"-q = list(map(int, input().split()))",
"+p = sorted(list(map(int, input().split())))[-X:]",
"+q = sorted(list(map(int, input().split())))[-Y:]",
"-red = [[i, \"r\"] for i in p]",
"-green = [[i, \"g\"] for i in q]",
"-white = [[i, \"w\"] for i in r]",
"-total = sorted(red + green + white)[::-1]",
"-ans = 0",
"-cnt = 0",
"-r_cnt = 0",
"-g_cnt = 0",
"-for t in total:",
"- if t[1] == \"r\" and r_cnt == X:",
"- continue",
"- if t[1] == \"g\" and g_cnt == Y:",
"- continue",
"- ans += t[0]",
"- if t[1] == \"r\":",
"- r_cnt += 1",
"- elif t[1] == \"g\":",
"- g_cnt += 1",
"- cnt += 1",
"- if cnt == X + Y:",
"- break",
"-print(ans)",
"+total = sorted(p + q + r)[::-1]",
"+print((sum(total[: X + Y])))"
]
| false | 0.060826 | 0.057376 | 1.060131 | [
"s751940979",
"s527547245"
]
|
u098968285 | p03088 | python | s517157188 | s109753291 | 641 | 569 | 55,132 | 53,980 | Accepted | Accepted | 11.23 | import re
def makelist(n, m):
return [[0 for i in range(m)] for j in range(n)]
N = int(eval(input()))
acgt = ["A", "C", "G", "T"]
changed = [".*GAC.*", ".*ACG.*", ".*A.GC.*", ".*AG.C.*"]
bad = ".*AGC"
# initialize
dp = {}
for a in acgt:
for b in acgt:
for c in acgt:
now = a+b+c
if re.match(bad, now):
dp[now] = 0
elif any([re.match(ch, now) for ch in changed]):
dp[now] = 0
else:
dp[now] = 1
N -= 3
MOD = int(1e9) + 7
# main
while N > 0:
dpNow = {}
for a in acgt:
for b in acgt:
for c in acgt:
abc = (a + b + c)[:min(N, 3)]
dpNow[abc] = 0
for key, value in list(dp.items()):
now = key + abc
if re.match(bad, now):
()
elif any([re.match(ch, now) for ch in changed]):
()
else:
dpNow[abc] += value
dpNow[abc] %= MOD
dp = dpNow
N -= 3
ans = 0
for v in list(dp.values()):
ans += v
ans %= MOD
print(ans)
| import re
def makelist(n, m):
return [[0 for i in range(m)] for j in range(n)]
N = int(eval(input()))
acgt = ["A", "C", "G", "T"]
changed = [".*AGC", ".*GAC", ".*ACG", ".*A.GC", ".*AG.C"]
# initialize
dp = {}
for a in acgt:
for b in acgt:
for c in acgt:
now = a+b+c
if any([re.match(ch, now) for ch in changed]):
dp[now] = 0
else:
dp[now] = 1
N -= 3
MOD = int(1e9) + 7
# main
while N > 0:
dpNow = {}
for a in acgt:
for b in acgt:
for c in acgt:
abc = (a + b + c)[:min(N, 3)]
dpNow[abc] = 0
for key, value in list(dp.items()):
now = key + abc
if not any([re.match(ch, now) for ch in changed]):
dpNow[abc] += value
dpNow[abc] %= MOD
dp = dpNow
N -= 3
ans = 0
for v in list(dp.values()):
ans += v
ans %= MOD
print(ans)
| 57 | 50 | 1,275 | 1,069 | import re
def makelist(n, m):
return [[0 for i in range(m)] for j in range(n)]
N = int(eval(input()))
acgt = ["A", "C", "G", "T"]
changed = [".*GAC.*", ".*ACG.*", ".*A.GC.*", ".*AG.C.*"]
bad = ".*AGC"
# initialize
dp = {}
for a in acgt:
for b in acgt:
for c in acgt:
now = a + b + c
if re.match(bad, now):
dp[now] = 0
elif any([re.match(ch, now) for ch in changed]):
dp[now] = 0
else:
dp[now] = 1
N -= 3
MOD = int(1e9) + 7
# main
while N > 0:
dpNow = {}
for a in acgt:
for b in acgt:
for c in acgt:
abc = (a + b + c)[: min(N, 3)]
dpNow[abc] = 0
for key, value in list(dp.items()):
now = key + abc
if re.match(bad, now):
()
elif any([re.match(ch, now) for ch in changed]):
()
else:
dpNow[abc] += value
dpNow[abc] %= MOD
dp = dpNow
N -= 3
ans = 0
for v in list(dp.values()):
ans += v
ans %= MOD
print(ans)
| import re
def makelist(n, m):
return [[0 for i in range(m)] for j in range(n)]
N = int(eval(input()))
acgt = ["A", "C", "G", "T"]
changed = [".*AGC", ".*GAC", ".*ACG", ".*A.GC", ".*AG.C"]
# initialize
dp = {}
for a in acgt:
for b in acgt:
for c in acgt:
now = a + b + c
if any([re.match(ch, now) for ch in changed]):
dp[now] = 0
else:
dp[now] = 1
N -= 3
MOD = int(1e9) + 7
# main
while N > 0:
dpNow = {}
for a in acgt:
for b in acgt:
for c in acgt:
abc = (a + b + c)[: min(N, 3)]
dpNow[abc] = 0
for key, value in list(dp.items()):
now = key + abc
if not any([re.match(ch, now) for ch in changed]):
dpNow[abc] += value
dpNow[abc] %= MOD
dp = dpNow
N -= 3
ans = 0
for v in list(dp.values()):
ans += v
ans %= MOD
print(ans)
| false | 12.280702 | [
"-changed = [\".*GAC.*\", \".*ACG.*\", \".*A.GC.*\", \".*AG.C.*\"]",
"-bad = \".*AGC\"",
"+changed = [\".*AGC\", \".*GAC\", \".*ACG\", \".*A.GC\", \".*AG.C\"]",
"- if re.match(bad, now):",
"- dp[now] = 0",
"- elif any([re.match(ch, now) for ch in changed]):",
"+ if any([re.match(ch, now) for ch in changed]):",
"- if re.match(bad, now):",
"- ()",
"- elif any([re.match(ch, now) for ch in changed]):",
"- ()",
"- else:",
"+ if not any([re.match(ch, now) for ch in changed]):"
]
| false | 0.392318 | 0.509233 | 0.770409 | [
"s517157188",
"s109753291"
]
|
u811276793 | p03074 | python | s317279149 | s386898399 | 81 | 58 | 7,932 | 8,820 | Accepted | Accepted | 28.4 | # -*- coding: utf-8 -*-
def main(N, K, S):
cnts = []
now = 1
cnt = 0
for n in S:
if now == int(n):
cnt += 1
else:
cnts.append(cnt)
cnt = 1
now = 1 - now
if cnt != 0: cnts.append(cnt)
if len(cnts) % 2 == 0: cnts.append(0)
ans = 0
Add = 2 * K + 1
sums = [0]
for c in cnts:
sums.append(sums[-1] + c)
for i in range(0,len(cnts),2):
left = i
right = min(i + Add, len(cnts))
tmp = sums[right] - sums[left]
ans = max(tmp, ans)
print(ans)
if __name__ == "__main__":
n, k = list(map(int, input().split()))
s = eval(input())
main(n, k, s)
| # -*- coding: utf-8 -*-
from itertools import accumulate
def main(N, K, S):
cnts = []
now = '1'
cnt = 0
for n in S:
if now == n:
cnt += 1
else:
cnts.append(cnt)
cnt = 1
now = n
cnts.append(cnt)
if now == '0': cnts.append(0)
ans = 0
Add = 2 * K + 1
sums = [0] + list(accumulate(cnts))
for i in range(0,len(cnts),2):
left = i
right = min(i + Add, len(cnts))
tmp = sums[right] - sums[left]
ans = max(tmp, ans)
print(ans)
if __name__ == "__main__":
n, k = list(map(int, input().split()))
s = eval(input())
main(n, k, s)
| 37 | 36 | 736 | 709 | # -*- coding: utf-8 -*-
def main(N, K, S):
cnts = []
now = 1
cnt = 0
for n in S:
if now == int(n):
cnt += 1
else:
cnts.append(cnt)
cnt = 1
now = 1 - now
if cnt != 0:
cnts.append(cnt)
if len(cnts) % 2 == 0:
cnts.append(0)
ans = 0
Add = 2 * K + 1
sums = [0]
for c in cnts:
sums.append(sums[-1] + c)
for i in range(0, len(cnts), 2):
left = i
right = min(i + Add, len(cnts))
tmp = sums[right] - sums[left]
ans = max(tmp, ans)
print(ans)
if __name__ == "__main__":
n, k = list(map(int, input().split()))
s = eval(input())
main(n, k, s)
| # -*- coding: utf-8 -*-
from itertools import accumulate
def main(N, K, S):
cnts = []
now = "1"
cnt = 0
for n in S:
if now == n:
cnt += 1
else:
cnts.append(cnt)
cnt = 1
now = n
cnts.append(cnt)
if now == "0":
cnts.append(0)
ans = 0
Add = 2 * K + 1
sums = [0] + list(accumulate(cnts))
for i in range(0, len(cnts), 2):
left = i
right = min(i + Add, len(cnts))
tmp = sums[right] - sums[left]
ans = max(tmp, ans)
print(ans)
if __name__ == "__main__":
n, k = list(map(int, input().split()))
s = eval(input())
main(n, k, s)
| false | 2.702703 | [
"+from itertools import accumulate",
"+",
"+",
"- now = 1",
"+ now = \"1\"",
"- if now == int(n):",
"+ if now == n:",
"- now = 1 - now",
"- if cnt != 0:",
"- cnts.append(cnt)",
"- if len(cnts) % 2 == 0:",
"+ now = n",
"+ cnts.append(cnt)",
"+ if now == \"0\":",
"- sums = [0]",
"- for c in cnts:",
"- sums.append(sums[-1] + c)",
"+ sums = [0] + list(accumulate(cnts))"
]
| false | 0.092589 | 0.111799 | 0.828172 | [
"s317279149",
"s386898399"
]
|
u191874006 | p02913 | python | s958305761 | s186329756 | 958 | 629 | 230,332 | 49,884 | Accepted | Accepted | 34.34 | #!/usr/bin/env python3
#ABC141 E
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
s = eval(input())
dp = [[0]*(n+1) for _ in range(n+1)]
dp[-1][-1] = 1
for i in range(n)[::-1]:
for j in range(n)[::-1]:
if s[i] == s[j]:
dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(n):
for j in range(n):
ans = max(ans,min(i-j,dp[i][j]))
print(ans) | #!/usr/bin/env python3
#ABC141 E
#Z-algorithm
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def z_algorithm(s):
n = len(s)
Z = [0] * n
Z[0] = n
L,R = 0,0
for i in range(1, n):
if i >= R: #過去の結果が使えない
L = R = i
while R < n and s[R-L] == s[R]:
R += 1
Z[i] = R - L
elif Z[i-L] < R-i:#過去の結果が全て使える
Z[i] = Z[i - L]
else:#過去の結果が一部使える
L = i
while R < n and s[R-L] == s[R]:
R += 1
Z[i] = R - L
return Z
n = I()
s = eval(input())
ans = 0
for i in range(n):
Z = z_algorithm(s[i:])
for j,z in enumerate(Z):
if j < z:
continue
ans = max(ans,z)
print(ans) | 33 | 51 | 875 | 1,257 | #!/usr/bin/env python3
# ABC141 E
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
n = I()
s = eval(input())
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[-1][-1] = 1
for i in range(n)[::-1]:
for j in range(n)[::-1]:
if s[i] == s[j]:
dp[i][j] = dp[i + 1][j + 1] + 1
ans = 0
for i in range(n):
for j in range(n):
ans = max(ans, min(i - j, dp[i][j]))
print(ans)
| #!/usr/bin/env python3
# ABC141 E
# Z-algorithm
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def z_algorithm(s):
n = len(s)
Z = [0] * n
Z[0] = n
L, R = 0, 0
for i in range(1, n):
if i >= R: # 過去の結果が使えない
L = R = i
while R < n and s[R - L] == s[R]:
R += 1
Z[i] = R - L
elif Z[i - L] < R - i: # 過去の結果が全て使える
Z[i] = Z[i - L]
else: # 過去の結果が一部使える
L = i
while R < n and s[R - L] == s[R]:
R += 1
Z[i] = R - L
return Z
n = I()
s = eval(input())
ans = 0
for i in range(n):
Z = z_algorithm(s[i:])
for j, z in enumerate(Z):
if j < z:
continue
ans = max(ans, z)
print(ans)
| false | 35.294118 | [
"+# Z-algorithm",
"+def z_algorithm(s):",
"+ n = len(s)",
"+ Z = [0] * n",
"+ Z[0] = n",
"+ L, R = 0, 0",
"+ for i in range(1, n):",
"+ if i >= R: # 過去の結果が使えない",
"+ L = R = i",
"+ while R < n and s[R - L] == s[R]:",
"+ R += 1",
"+ Z[i] = R - L",
"+ elif Z[i - L] < R - i: # 過去の結果が全て使える",
"+ Z[i] = Z[i - L]",
"+ else: # 過去の結果が一部使える",
"+ L = i",
"+ while R < n and s[R - L] == s[R]:",
"+ R += 1",
"+ Z[i] = R - L",
"+ return Z",
"+",
"+",
"-dp = [[0] * (n + 1) for _ in range(n + 1)]",
"-dp[-1][-1] = 1",
"-for i in range(n)[::-1]:",
"- for j in range(n)[::-1]:",
"- if s[i] == s[j]:",
"- dp[i][j] = dp[i + 1][j + 1] + 1",
"- for j in range(n):",
"- ans = max(ans, min(i - j, dp[i][j]))",
"+ Z = z_algorithm(s[i:])",
"+ for j, z in enumerate(Z):",
"+ if j < z:",
"+ continue",
"+ ans = max(ans, z)"
]
| false | 0.036704 | 0.037138 | 0.98831 | [
"s958305761",
"s186329756"
]
|
u077291787 | p03911 | python | s368348076 | s627749895 | 475 | 357 | 44,996 | 18,116 | Accepted | Accepted | 24.84 | # cf16-finalC - Interpretation
# bipartite graph
def dfs() -> None:
stack = [(1, 1)]
seen_m[1] = 1
while stack:
v, flg = stack.pop()
if flg:
for u in men[v]:
if not seen_l[u]:
stack.append((u, 0))
seen_l[u] = 1
else:
for u in langs[v]:
if not seen_m[u]:
stack.append((u, 1))
seen_m[u] = 1
def main():
global men, langs, seen_m, seen_l
N, M = tuple(map(int, input().split()))
A = tuple(tuple(map(int, input().split())) for _ in range(N))
men, langs = [[] for _ in range(N + 1)], [[] for _ in range(M + 1)]
for person, lang in enumerate(A, 1): # construct a bipartite graph
for l in lang[1:]:
men[person].append(l), langs[l].append(person)
seen_m, seen_l = [0] * (N + 1), [0] * (M + 1)
dfs()
flg = all(i for i in seen_m[1:])
print(("YES" if flg else "NO"))
if __name__ == "__main__":
main() | # cf16-finalC - Interpretation
class UnionFind: # O(α(N))
def __init__(self, size): # construct a Union-Find tree (1-idx)
self.parent = [i for i in range(size + 1)]
self.rank = [0] * (size + 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: # in 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():
N, M = list(map(int, input().split()))
A = tuple(tuple(map(int, input().split())) for _ in range(N))
uf, spoken = UnionFind(M), set()
for _, *langs in A:
spoken.update(langs)
primary = langs[0]
for l in langs[1:]:
uf.unite(primary, l)
cur = uf.find(spoken.pop())
flg = all(uf.find(lang) == cur for lang in spoken)
print(("YES" if flg else "NO"))
if __name__ == "__main__":
main() | 35 | 44 | 1,057 | 1,432 | # cf16-finalC - Interpretation
# bipartite graph
def dfs() -> None:
stack = [(1, 1)]
seen_m[1] = 1
while stack:
v, flg = stack.pop()
if flg:
for u in men[v]:
if not seen_l[u]:
stack.append((u, 0))
seen_l[u] = 1
else:
for u in langs[v]:
if not seen_m[u]:
stack.append((u, 1))
seen_m[u] = 1
def main():
global men, langs, seen_m, seen_l
N, M = tuple(map(int, input().split()))
A = tuple(tuple(map(int, input().split())) for _ in range(N))
men, langs = [[] for _ in range(N + 1)], [[] for _ in range(M + 1)]
for person, lang in enumerate(A, 1): # construct a bipartite graph
for l in lang[1:]:
men[person].append(l), langs[l].append(person)
seen_m, seen_l = [0] * (N + 1), [0] * (M + 1)
dfs()
flg = all(i for i in seen_m[1:])
print(("YES" if flg else "NO"))
if __name__ == "__main__":
main()
| # cf16-finalC - Interpretation
class UnionFind: # O(α(N))
def __init__(self, size): # construct a Union-Find tree (1-idx)
self.parent = [i for i in range(size + 1)]
self.rank = [0] * (size + 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: # in 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():
N, M = list(map(int, input().split()))
A = tuple(tuple(map(int, input().split())) for _ in range(N))
uf, spoken = UnionFind(M), set()
for _, *langs in A:
spoken.update(langs)
primary = langs[0]
for l in langs[1:]:
uf.unite(primary, l)
cur = uf.find(spoken.pop())
flg = all(uf.find(lang) == cur for lang in spoken)
print(("YES" if flg else "NO"))
if __name__ == "__main__":
main()
| false | 20.454545 | [
"-# bipartite graph",
"-def dfs() -> None:",
"- stack = [(1, 1)]",
"- seen_m[1] = 1",
"- while stack:",
"- v, flg = stack.pop()",
"- if flg:",
"- for u in men[v]:",
"- if not seen_l[u]:",
"- stack.append((u, 0))",
"- seen_l[u] = 1",
"+class UnionFind: # O(α(N))",
"+ def __init__(self, size): # construct a Union-Find tree (1-idx)",
"+ self.parent = [i for i in range(size + 1)]",
"+ self.rank = [0] * (size + 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: # in 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",
"- for u in langs[v]:",
"- if not seen_m[u]:",
"- stack.append((u, 1))",
"- seen_m[u] = 1",
"+ self.parent[y] = x",
"+ if self.rank[x] == self.rank[y]:",
"+ self.rank[x] += 1",
"- global men, langs, seen_m, seen_l",
"- N, M = tuple(map(int, input().split()))",
"+ N, M = list(map(int, input().split()))",
"- men, langs = [[] for _ in range(N + 1)], [[] for _ in range(M + 1)]",
"- for person, lang in enumerate(A, 1): # construct a bipartite graph",
"- for l in lang[1:]:",
"- men[person].append(l), langs[l].append(person)",
"- seen_m, seen_l = [0] * (N + 1), [0] * (M + 1)",
"- dfs()",
"- flg = all(i for i in seen_m[1:])",
"+ uf, spoken = UnionFind(M), set()",
"+ for _, *langs in A:",
"+ spoken.update(langs)",
"+ primary = langs[0]",
"+ for l in langs[1:]:",
"+ uf.unite(primary, l)",
"+ cur = uf.find(spoken.pop())",
"+ flg = all(uf.find(lang) == cur for lang in spoken)"
]
| false | 0.043916 | 0.083238 | 0.527596 | [
"s368348076",
"s627749895"
]
|
u066551652 | p02773 | python | s758705854 | s855041415 | 797 | 712 | 46,236 | 32,988 | Accepted | Accepted | 10.66 | n = int(eval(input()))
s_dic = {}
for i in range(n):
tmp = str(eval(input()))
if tmp not in s_dic:
s_dic[tmp] = 1
else:
s_dic[tmp] += 1
max_value = max(s_dic.values())
s_dic = sorted(list(s_dic.items()), key=lambda x:x[0])
for i in s_dic:
if i[1] == max_value:
print((i[0])) | n = int(eval(input()))
s_dic = {}
for i in range(n):
tmp = str(eval(input()))
if tmp not in s_dic:
s_dic[tmp] = 1
else:
s_dic[tmp] += 1
tmp = max(s_dic.values())
max_s_key = [s_value[0] for s_value in list(s_dic.items()) if s_value[1] == tmp]
max_s_key = sorted(max_s_key)
for i in max_s_key:
print(i) | 17 | 18 | 314 | 337 | n = int(eval(input()))
s_dic = {}
for i in range(n):
tmp = str(eval(input()))
if tmp not in s_dic:
s_dic[tmp] = 1
else:
s_dic[tmp] += 1
max_value = max(s_dic.values())
s_dic = sorted(list(s_dic.items()), key=lambda x: x[0])
for i in s_dic:
if i[1] == max_value:
print((i[0]))
| n = int(eval(input()))
s_dic = {}
for i in range(n):
tmp = str(eval(input()))
if tmp not in s_dic:
s_dic[tmp] = 1
else:
s_dic[tmp] += 1
tmp = max(s_dic.values())
max_s_key = [s_value[0] for s_value in list(s_dic.items()) if s_value[1] == tmp]
max_s_key = sorted(max_s_key)
for i in max_s_key:
print(i)
| false | 5.555556 | [
"-max_value = max(s_dic.values())",
"-s_dic = sorted(list(s_dic.items()), key=lambda x: x[0])",
"-for i in s_dic:",
"- if i[1] == max_value:",
"- print((i[0]))",
"+tmp = max(s_dic.values())",
"+max_s_key = [s_value[0] for s_value in list(s_dic.items()) if s_value[1] == tmp]",
"+max_s_key = sorted(max_s_key)",
"+for i in max_s_key:",
"+ print(i)"
]
| false | 0.041869 | 0.043032 | 0.972987 | [
"s758705854",
"s855041415"
]
|
u940533000 | p02623 | python | s909678054 | s488933596 | 343 | 296 | 48,776 | 47,360 | Accepted | Accepted | 13.7 | N,M,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
tmp = 0
for i in range(N):
tmp += A[i]
a.append(tmp)
tmp = 0
for i in range(M):
tmp += B[i]
b.append(tmp)
total = 0
count = []
best_j = len(b)-1
for i in range(len(a)):
if a[i] <= K:
for j in range(best_j, -1, -1):
total = a[i] + b[j]
if total <= K:
count.append(i+j)
best_j = j
break
if len(count) == 0:
print((0))
else:
print((max(count)))
| N,M,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
tmp = 0
for i in range(N):
tmp += A[i]
a.append(tmp)
tmp = 0
for i in range(M):
tmp += B[i]
b.append(tmp)
j = len(b)-1
ans = 0
for i in range(len(a)):
if a[i] > K:
break
while a[i] + b[j] > K:
j -= 1
ans = max(ans, i+j)
print(ans)
| 31 | 25 | 553 | 408 | N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
tmp = 0
for i in range(N):
tmp += A[i]
a.append(tmp)
tmp = 0
for i in range(M):
tmp += B[i]
b.append(tmp)
total = 0
count = []
best_j = len(b) - 1
for i in range(len(a)):
if a[i] <= K:
for j in range(best_j, -1, -1):
total = a[i] + b[j]
if total <= K:
count.append(i + j)
best_j = j
break
if len(count) == 0:
print((0))
else:
print((max(count)))
| N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
tmp = 0
for i in range(N):
tmp += A[i]
a.append(tmp)
tmp = 0
for i in range(M):
tmp += B[i]
b.append(tmp)
j = len(b) - 1
ans = 0
for i in range(len(a)):
if a[i] > K:
break
while a[i] + b[j] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
| false | 19.354839 | [
"-total = 0",
"-count = []",
"-best_j = len(b) - 1",
"+j = len(b) - 1",
"+ans = 0",
"- if a[i] <= K:",
"- for j in range(best_j, -1, -1):",
"- total = a[i] + b[j]",
"- if total <= K:",
"- count.append(i + j)",
"- best_j = j",
"- break",
"-if len(count) == 0:",
"- print((0))",
"-else:",
"- print((max(count)))",
"+ if a[i] > K:",
"+ break",
"+ while a[i] + b[j] > K:",
"+ j -= 1",
"+ ans = max(ans, i + j)",
"+print(ans)"
]
| false | 0.038056 | 0.049004 | 0.776586 | [
"s909678054",
"s488933596"
]
|
u918601425 | p02848 | python | s447876725 | s900574030 | 177 | 22 | 39,280 | 3,064 | Accepted | Accepted | 87.57 | ls=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
N=26-int(eval(input()))
S=eval(input())
ans=[]
for i in range(len(S)):
x=ls.index(S[i])
ans.append(ls[x-N])
print(("".join(ans))) | ls=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
N=int(eval(input()))
S=eval(input())
ans=[ls[(ls.index(S[i])+N)%26] for i in range(len(S))]
print(("".join(ans))) | 8 | 5 | 164 | 141 | ls = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
N = 26 - int(eval(input()))
S = eval(input())
ans = []
for i in range(len(S)):
x = ls.index(S[i])
ans.append(ls[x - N])
print(("".join(ans)))
| ls = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
N = int(eval(input()))
S = eval(input())
ans = [ls[(ls.index(S[i]) + N) % 26] for i in range(len(S))]
print(("".join(ans)))
| false | 37.5 | [
"-N = 26 - int(eval(input()))",
"+N = int(eval(input()))",
"-ans = []",
"-for i in range(len(S)):",
"- x = ls.index(S[i])",
"- ans.append(ls[x - N])",
"+ans = [ls[(ls.index(S[i]) + N) % 26] for i in range(len(S))]"
]
| false | 0.181776 | 0.037313 | 4.871697 | [
"s447876725",
"s900574030"
]
|
u948911484 | p03369 | python | s020194035 | s870511309 | 26 | 24 | 9,060 | 9,028 | Accepted | Accepted | 7.69 | print((700+input().count("o")*100)) | print(([7,8,9,10][input().count("o")]*100)) | 1 | 1 | 33 | 41 | print((700 + input().count("o") * 100))
| print(([7, 8, 9, 10][input().count("o")] * 100))
| false | 0 | [
"-print((700 + input().count(\"o\") * 100))",
"+print(([7, 8, 9, 10][input().count(\"o\")] * 100))"
]
| false | 0.036752 | 0.044323 | 0.829184 | [
"s020194035",
"s870511309"
]
|
u631025015 | p02641 | python | s548481868 | s491223632 | 30 | 26 | 9,148 | 9,136 | Accepted | Accepted | 13.33 | x,n = input().split()
x=int(x)
n=int(n)
list=input().split()
for i in range(0, len(list)):
list[i] = int(list[i])
diff = 200
for i in range(-1, 102):
if i not in list and abs(i-x) < diff:
diff = abs(i-x)
ans = i
print(ans) | x,n = input().split()
x=int(x)
list=input().split()
diff = 200
for i in range(-1, 102):
if str(i) not in list and abs(i-x) < diff:
diff = abs(i-x)
ans = i
print(ans) | 12 | 9 | 257 | 193 | x, n = input().split()
x = int(x)
n = int(n)
list = input().split()
for i in range(0, len(list)):
list[i] = int(list[i])
diff = 200
for i in range(-1, 102):
if i not in list and abs(i - x) < diff:
diff = abs(i - x)
ans = i
print(ans)
| x, n = input().split()
x = int(x)
list = input().split()
diff = 200
for i in range(-1, 102):
if str(i) not in list and abs(i - x) < diff:
diff = abs(i - x)
ans = i
print(ans)
| false | 25 | [
"-n = int(n)",
"-for i in range(0, len(list)):",
"- list[i] = int(list[i])",
"- if i not in list and abs(i - x) < diff:",
"+ if str(i) not in list and abs(i - x) < diff:"
]
| false | 0.033879 | 0.03573 | 0.948187 | [
"s548481868",
"s491223632"
]
|
u075012704 | p03863 | python | s816512153 | s740522620 | 36 | 18 | 3,316 | 3,316 | Accepted | Accepted | 50 | S = eval(input())
N = len(S)
x = S[0]
y = S[1]
for i in range(2, N):
if i % 2 == 0:
if S[i] != x:
break
else:
if S[i] != y:
break
else:
print("Second")
exit()
if S[0]==S[-1]:
if N % 2 == 0:
print("First")
else:
print("Second")
else:
if N % 2 == 0:
print("Second")
else:
print("First")
| S = eval(input())
if S[0] == S[-1]:
C1 = True
else:
C1 = False
if len(S) % 2 == 1:
C2 = True
else:
C2 = False
if C1 ^ C2 == 0:
print('Second')
else:
print('First')
| 26 | 16 | 410 | 200 | S = eval(input())
N = len(S)
x = S[0]
y = S[1]
for i in range(2, N):
if i % 2 == 0:
if S[i] != x:
break
else:
if S[i] != y:
break
else:
print("Second")
exit()
if S[0] == S[-1]:
if N % 2 == 0:
print("First")
else:
print("Second")
else:
if N % 2 == 0:
print("Second")
else:
print("First")
| S = eval(input())
if S[0] == S[-1]:
C1 = True
else:
C1 = False
if len(S) % 2 == 1:
C2 = True
else:
C2 = False
if C1 ^ C2 == 0:
print("Second")
else:
print("First")
| false | 38.461538 | [
"-N = len(S)",
"-x = S[0]",
"-y = S[1]",
"-for i in range(2, N):",
"- if i % 2 == 0:",
"- if S[i] != x:",
"- break",
"- else:",
"- if S[i] != y:",
"- break",
"+if S[0] == S[-1]:",
"+ C1 = True",
"+ C1 = False",
"+if len(S) % 2 == 1:",
"+ C2 = True",
"+else:",
"+ C2 = False",
"+if C1 ^ C2 == 0:",
"- exit()",
"-if S[0] == S[-1]:",
"- if N % 2 == 0:",
"- print(\"First\")",
"- else:",
"- print(\"Second\")",
"- if N % 2 == 0:",
"- print(\"Second\")",
"- else:",
"- print(\"First\")",
"+ print(\"First\")"
]
| false | 0.034315 | 0.033246 | 1.032151 | [
"s816512153",
"s740522620"
]
|
u718706790 | p03609 | python | s448396779 | s371923347 | 19 | 17 | 3,316 | 2,940 | Accepted | Accepted | 10.53 | x, t = list(map(int, input().split()))
if x - t >= 0:
print((x - t))
else:
print((0)) | x, t = list(map(int, input().split()))
if x > t:
print((x - t))
else:
print((0)) | 6 | 6 | 85 | 80 | x, t = list(map(int, input().split()))
if x - t >= 0:
print((x - t))
else:
print((0))
| x, t = list(map(int, input().split()))
if x > t:
print((x - t))
else:
print((0))
| false | 0 | [
"-if x - t >= 0:",
"+if x > t:"
]
| false | 0.040575 | 0.040196 | 1.009424 | [
"s448396779",
"s371923347"
]
|
u647766105 | p00009 | python | s004881555 | s554388598 | 1,400 | 430 | 12,104 | 35,964 | Accepted | Accepted | 69.29 | import sys
n=10**6
s=[True]*n
s[0]=False
s[1]=False
for x in range(2, int(n**0.5)+1):
if s[x]:
for i in range(x+x,n,x):
s[i]=False
for x in sys.stdin.readlines():
x=int(x)+1
cnt=0
for i in range(x):
if s[i]:
cnt=cnt+1
print(cnt) | import sys
n=10**6
p=[1]*n
p[0],p[1]=0,0
for i in range(2,int(n**0.5)+1):
if p[i]==1:
for j in range(i**2,n,i):
p[j]=0
for i in range(2,n):
p[i]+=p[i-1]
for line in sys.stdin.readlines():
print(p[int(line)]) | 16 | 12 | 305 | 252 | import sys
n = 10**6
s = [True] * n
s[0] = False
s[1] = False
for x in range(2, int(n**0.5) + 1):
if s[x]:
for i in range(x + x, n, x):
s[i] = False
for x in sys.stdin.readlines():
x = int(x) + 1
cnt = 0
for i in range(x):
if s[i]:
cnt = cnt + 1
print(cnt)
| import sys
n = 10**6
p = [1] * n
p[0], p[1] = 0, 0
for i in range(2, int(n**0.5) + 1):
if p[i] == 1:
for j in range(i**2, n, i):
p[j] = 0
for i in range(2, n):
p[i] += p[i - 1]
for line in sys.stdin.readlines():
print(p[int(line)])
| false | 25 | [
"-s = [True] * n",
"-s[0] = False",
"-s[1] = False",
"-for x in range(2, int(n**0.5) + 1):",
"- if s[x]:",
"- for i in range(x + x, n, x):",
"- s[i] = False",
"-for x in sys.stdin.readlines():",
"- x = int(x) + 1",
"- cnt = 0",
"- for i in range(x):",
"- if s[i]:",
"- cnt = cnt + 1",
"- print(cnt)",
"+p = [1] * n",
"+p[0], p[1] = 0, 0",
"+for i in range(2, int(n**0.5) + 1):",
"+ if p[i] == 1:",
"+ for j in range(i**2, n, i):",
"+ p[j] = 0",
"+for i in range(2, n):",
"+ p[i] += p[i - 1]",
"+for line in sys.stdin.readlines():",
"+ print(p[int(line)])"
]
| false | 0.575581 | 0.983218 | 0.585405 | [
"s004881555",
"s554388598"
]
|
u691501673 | p02861 | python | s177662649 | s547976527 | 398 | 118 | 3,064 | 3,064 | Accepted | Accepted | 70.35 | import math
import itertools
N = int(eval(input()))
array = [list(map(int, input().split())) for _ in range(N)]
result = 0
count = 0
permutation_list = itertools.permutations([x for x in range(N)])
for data in permutation_list:
count += 1
for i in range(1, len(data)):
result += math.sqrt((array[data[i]][0] - array[data[i - 1]][0]) ** 2 +
(array[data[i]][1] - array[data[i - 1]][1]) ** 2)
print((result / count))
| import math
import itertools
N = int(eval(input()))
array = [list(map(int, input().split())) for _ in range(N)]
result = 0
count = 0
permutation_list = itertools.permutations([x for x in range(N)])
calc = [[0] * 10 for i in range(10)]
for i in range(N):
for j in range(N):
calc[i][j] = math.sqrt((array[i][0] - array[j][0]) ** 2 +
(array[i][1] - array[j][1]) ** 2)
calc[j][i] = math.sqrt((array[i][0] - array[j][0]) ** 2 +
(array[i][1] - array[j][1]) ** 2)
for data in permutation_list:
count += 1
for i in range(1, len(data)):
result += calc[data[i - 1]][data[i]]
print((result / count))
| 17 | 25 | 470 | 709 | import math
import itertools
N = int(eval(input()))
array = [list(map(int, input().split())) for _ in range(N)]
result = 0
count = 0
permutation_list = itertools.permutations([x for x in range(N)])
for data in permutation_list:
count += 1
for i in range(1, len(data)):
result += math.sqrt(
(array[data[i]][0] - array[data[i - 1]][0]) ** 2
+ (array[data[i]][1] - array[data[i - 1]][1]) ** 2
)
print((result / count))
| import math
import itertools
N = int(eval(input()))
array = [list(map(int, input().split())) for _ in range(N)]
result = 0
count = 0
permutation_list = itertools.permutations([x for x in range(N)])
calc = [[0] * 10 for i in range(10)]
for i in range(N):
for j in range(N):
calc[i][j] = math.sqrt(
(array[i][0] - array[j][0]) ** 2 + (array[i][1] - array[j][1]) ** 2
)
calc[j][i] = math.sqrt(
(array[i][0] - array[j][0]) ** 2 + (array[i][1] - array[j][1]) ** 2
)
for data in permutation_list:
count += 1
for i in range(1, len(data)):
result += calc[data[i - 1]][data[i]]
print((result / count))
| false | 32 | [
"+calc = [[0] * 10 for i in range(10)]",
"+for i in range(N):",
"+ for j in range(N):",
"+ calc[i][j] = math.sqrt(",
"+ (array[i][0] - array[j][0]) ** 2 + (array[i][1] - array[j][1]) ** 2",
"+ )",
"+ calc[j][i] = math.sqrt(",
"+ (array[i][0] - array[j][0]) ** 2 + (array[i][1] - array[j][1]) ** 2",
"+ )",
"- result += math.sqrt(",
"- (array[data[i]][0] - array[data[i - 1]][0]) ** 2",
"- + (array[data[i]][1] - array[data[i - 1]][1]) ** 2",
"- )",
"+ result += calc[data[i - 1]][data[i]]"
]
| false | 0.040566 | 0.040573 | 0.999832 | [
"s177662649",
"s547976527"
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.