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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u146816547
|
p00009
|
python
|
s923367253
|
s351592258
| 860 | 550 | 61,684 | 75,976 |
Accepted
|
Accepted
| 36.05 |
era = [True]*1000001
for i in range(2, 1000001):
if era[i-2]:
for j in range(i*2, 1000001, i):
era[j-2] = False
while True:
try:
n = int(input())
print(era[:n-1].count(True))
except EOFError:
break
|
IsPrimes = [True] * 1000002
IsPrimes[0], IsPrimes[1] = False, False
for i in range(2, 1001):
if IsPrimes[i]:
for j in range(i*i, 1000001, i):
IsPrimes[j]= False
cnt = [0] * 1000001
for i in range(1000001):
if IsPrimes[i]:
cnt[i] += 1
for i in range(1, 1000001):
cnt[i] += cnt[i-1]
while True:
try:
n = int(input())
print(cnt[n])
except EOFError:
break
| 14 | 25 | 244 | 458 |
era = [True] * 1000001
for i in range(2, 1000001):
if era[i - 2]:
for j in range(i * 2, 1000001, i):
era[j - 2] = False
while True:
try:
n = int(input())
print(era[: n - 1].count(True))
except EOFError:
break
|
IsPrimes = [True] * 1000002
IsPrimes[0], IsPrimes[1] = False, False
for i in range(2, 1001):
if IsPrimes[i]:
for j in range(i * i, 1000001, i):
IsPrimes[j] = False
cnt = [0] * 1000001
for i in range(1000001):
if IsPrimes[i]:
cnt[i] += 1
for i in range(1, 1000001):
cnt[i] += cnt[i - 1]
while True:
try:
n = int(input())
print(cnt[n])
except EOFError:
break
| false | 44 |
[
"-era = [True] * 1000001",
"-for i in range(2, 1000001):",
"- if era[i - 2]:",
"- for j in range(i * 2, 1000001, i):",
"- era[j - 2] = False",
"+IsPrimes = [True] * 1000002",
"+IsPrimes[0], IsPrimes[1] = False, False",
"+for i in range(2, 1001):",
"+ if IsPrimes[i]:",
"+ for j in range(i * i, 1000001, i):",
"+ IsPrimes[j] = False",
"+cnt = [0] * 1000001",
"+for i in range(1000001):",
"+ if IsPrimes[i]:",
"+ cnt[i] += 1",
"+for i in range(1, 1000001):",
"+ cnt[i] += cnt[i - 1]",
"- print(era[: n - 1].count(True))",
"+ print(cnt[n])"
] | false | 1.054801 | 1.411396 | 0.747346 |
[
"s923367253",
"s351592258"
] |
u904331908
|
p02947
|
python
|
s199202335
|
s062214302
| 519 | 252 | 32,216 | 28,228 |
Accepted
|
Accepted
| 51.45 |
import itertools,math
n = int(eval(input()))
word = [eval(input()) for _ in range(n)]
count = 0
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
word[i] = sorted(word[i])
new_word = list(sorted(word))
x = 1
for i in range(n-1):
if new_word[i] == new_word[i+1]:
x += 1
elif x >= 2:
count += combinations_count(x,2)
x = 1
if x >= 2:
count += combinations_count(x,2)
print(count)
|
#他の人の回答
import collections
N = int(eval(input()))
s = ["".join(sorted(eval(input()))) for _ in range(N)]
#sortedでリストになった文字列をjoinでもう一度文字列に
c = collections.Counter(s)
#cは辞書の形をとる
ans = 0
# sから重複を無くす
for si in set(s):
n = c[si]
ans += n * (n - 1) // 2
# n C 2を計算
print(ans)
| 25 | 16 | 511 | 288 |
import itertools, math
n = int(eval(input()))
word = [eval(input()) for _ in range(n)]
count = 0
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
word[i] = sorted(word[i])
new_word = list(sorted(word))
x = 1
for i in range(n - 1):
if new_word[i] == new_word[i + 1]:
x += 1
elif x >= 2:
count += combinations_count(x, 2)
x = 1
if x >= 2:
count += combinations_count(x, 2)
print(count)
|
# 他の人の回答
import collections
N = int(eval(input()))
s = ["".join(sorted(eval(input()))) for _ in range(N)]
# sortedでリストになった文字列をjoinでもう一度文字列に
c = collections.Counter(s)
# cは辞書の形をとる
ans = 0
# sから重複を無くす
for si in set(s):
n = c[si]
ans += n * (n - 1) // 2
# n C 2を計算
print(ans)
| false | 36 |
[
"-import itertools, math",
"+# 他の人の回答",
"+import collections",
"-n = int(eval(input()))",
"-word = [eval(input()) for _ in range(n)]",
"-count = 0",
"-",
"-",
"-def combinations_count(n, r):",
"- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))",
"-",
"-",
"-for i in range(n):",
"- word[i] = sorted(word[i])",
"-new_word = list(sorted(word))",
"-x = 1",
"-for i in range(n - 1):",
"- if new_word[i] == new_word[i + 1]:",
"- x += 1",
"- elif x >= 2:",
"- count += combinations_count(x, 2)",
"- x = 1",
"-if x >= 2:",
"- count += combinations_count(x, 2)",
"-print(count)",
"+N = int(eval(input()))",
"+s = [\"\".join(sorted(eval(input()))) for _ in range(N)]",
"+# sortedでリストになった文字列をjoinでもう一度文字列に",
"+c = collections.Counter(s)",
"+# cは辞書の形をとる",
"+ans = 0",
"+# sから重複を無くす",
"+for si in set(s):",
"+ n = c[si]",
"+ ans += n * (n - 1) // 2",
"+ # n C 2を計算",
"+print(ans)"
] | false | 0.086759 | 0.034206 | 2.536399 |
[
"s199202335",
"s062214302"
] |
u078042885
|
p00254
|
python
|
s009066415
|
s599691416
| 310 | 230 | 7,672 | 7,600 |
Accepted
|
Accepted
| 25.81 |
while 1:
n,c=eval(input()),0
if int(n)==0:break
if n.count(n[0])==4:
print('NA')
continue
while n!='6174':
n = str(int(''.join(reversed(sorted(list(n))))) - int(''.join(sorted(list(n))))).zfill(4)
c+=1
print(c)
|
while 1:
n,c=eval(input()),0
if int(n)==0:break
if n.count(n[0])==4:
print('NA')
continue
while n!='6174':
n=''.join(sorted(n))
n = str(int(n[::-1]) - int(n)).zfill(4)
c+=1
print(c)
| 10 | 11 | 265 | 245 |
while 1:
n, c = eval(input()), 0
if int(n) == 0:
break
if n.count(n[0]) == 4:
print("NA")
continue
while n != "6174":
n = str(
int("".join(reversed(sorted(list(n))))) - int("".join(sorted(list(n))))
).zfill(4)
c += 1
print(c)
|
while 1:
n, c = eval(input()), 0
if int(n) == 0:
break
if n.count(n[0]) == 4:
print("NA")
continue
while n != "6174":
n = "".join(sorted(n))
n = str(int(n[::-1]) - int(n)).zfill(4)
c += 1
print(c)
| false | 9.090909 |
[
"- n = str(",
"- int(\"\".join(reversed(sorted(list(n))))) - int(\"\".join(sorted(list(n))))",
"- ).zfill(4)",
"+ n = \"\".join(sorted(n))",
"+ n = str(int(n[::-1]) - int(n)).zfill(4)"
] | false | 0.036869 | 0.035496 | 1.038699 |
[
"s009066415",
"s599691416"
] |
u909514237
|
p02580
|
python
|
s793398297
|
s190053262
| 1,046 | 579 | 83,332 | 176,548 |
Accepted
|
Accepted
| 44.65 |
H,W,M = list(map(int, input().split()))
hs = [0] * H
ws = [0] * W
s = set()
for i in range(M):
h,w = list(map(int, input().split()))
h -= 1
w -= 1
hs[h] += 1
ws[w] += 1
s.add((h,w))
mh = 0
mw = 0
for i in range(H):
mh = max(mh, hs[i])
for j in range(W):
mw = max(mw, ws[j])
l_s = list()
j_s = list()
for i in range(H):
if mh == hs[i]:
l_s.append(i)
for j in range(W):
if mw == ws[j]:
j_s.append(j)
ans = mh+mw
for i in l_s:
for j in j_s:
if (i,j) in s:
continue
print(ans)
exit()
ans -= 1
print(ans)
|
H,W,M = list(map(int, input().split()))
hs = [0] * H
ws = [0] * W
s = set()
for i in range(M):
h,w = list(map(int, input().split()))
h -= 1
w -= 1
hs[h] += 1
ws[w] += 1
s.add((h,w))
mh = 0
mw = 0
for i in range(H):
mh = max(mh, hs[i])
for j in range(W):
mw = max(mw, ws[j])
i_s = list()
j_s = list()
for i in range(H):
if hs[i] == mh:
i_s.append(i)
for j in range(W):
if ws[j] == mw:
j_s.append(j)
ans = mh + mw
for i in i_s:
for j in j_s:
if (i,j) in s:
continue
print(ans)
exit()
ans -= 1
print(ans)
| 39 | 38 | 584 | 586 |
H, W, M = list(map(int, input().split()))
hs = [0] * H
ws = [0] * W
s = set()
for i in range(M):
h, w = list(map(int, input().split()))
h -= 1
w -= 1
hs[h] += 1
ws[w] += 1
s.add((h, w))
mh = 0
mw = 0
for i in range(H):
mh = max(mh, hs[i])
for j in range(W):
mw = max(mw, ws[j])
l_s = list()
j_s = list()
for i in range(H):
if mh == hs[i]:
l_s.append(i)
for j in range(W):
if mw == ws[j]:
j_s.append(j)
ans = mh + mw
for i in l_s:
for j in j_s:
if (i, j) in s:
continue
print(ans)
exit()
ans -= 1
print(ans)
|
H, W, M = list(map(int, input().split()))
hs = [0] * H
ws = [0] * W
s = set()
for i in range(M):
h, w = list(map(int, input().split()))
h -= 1
w -= 1
hs[h] += 1
ws[w] += 1
s.add((h, w))
mh = 0
mw = 0
for i in range(H):
mh = max(mh, hs[i])
for j in range(W):
mw = max(mw, ws[j])
i_s = list()
j_s = list()
for i in range(H):
if hs[i] == mh:
i_s.append(i)
for j in range(W):
if ws[j] == mw:
j_s.append(j)
ans = mh + mw
for i in i_s:
for j in j_s:
if (i, j) in s:
continue
print(ans)
exit()
ans -= 1
print(ans)
| false | 2.564103 |
[
"-l_s = list()",
"+i_s = list()",
"- if mh == hs[i]:",
"- l_s.append(i)",
"+ if hs[i] == mh:",
"+ i_s.append(i)",
"- if mw == ws[j]:",
"+ if ws[j] == mw:",
"-for i in l_s:",
"+for i in i_s:"
] | false | 0.06663 | 0.074092 | 0.899278 |
[
"s793398297",
"s190053262"
] |
u554954744
|
p03645
|
python
|
s836359269
|
s441094154
| 1,089 | 1,001 | 87,244 | 66,508 |
Accepted
|
Accepted
| 8.08 |
N, M = list(map(int, input().split()))
s = [[] for i in range(N+1)]
e = [[] for i in range(N+1)]
for i in range(M):
a, b = list(map(int, input().split()))
s[a].append(b)
e[b].append(a)
for i in s[1]:
if N in s[i]:
print('POSSIBLE')
exit()
print('IMPOSSIBLE')
|
N, M = list(map(int, input().split()))
s = [[] for i in range(N+1)]
for i in range(M):
a, b = list(map(int, input().split()))
s[a].append(b)
for i in s[1]:
if N in s[i]:
print('POSSIBLE')
exit()
print('IMPOSSIBLE')
| 14 | 12 | 293 | 243 |
N, M = list(map(int, input().split()))
s = [[] for i in range(N + 1)]
e = [[] for i in range(N + 1)]
for i in range(M):
a, b = list(map(int, input().split()))
s[a].append(b)
e[b].append(a)
for i in s[1]:
if N in s[i]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
|
N, M = list(map(int, input().split()))
s = [[] for i in range(N + 1)]
for i in range(M):
a, b = list(map(int, input().split()))
s[a].append(b)
for i in s[1]:
if N in s[i]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
| false | 14.285714 |
[
"-e = [[] for i in range(N + 1)]",
"- e[b].append(a)"
] | false | 0.084128 | 0.161246 | 0.521738 |
[
"s836359269",
"s441094154"
] |
u347640436
|
p02820
|
python
|
s974795020
|
s873927245
| 146 | 79 | 4,212 | 3,956 |
Accepted
|
Accepted
| 45.89 |
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
hands = [None] * N
d1 = {'r': 'p', 's': 'r', 'p': 's'}
d2 = {'r': P, 's': R, 'p': S}
result = 0
for i in range(len(T)):
if i >= K and d1[T[i]] == hands[i - K]:
if i + K < N:
hands[i] = list(set('rps') - set(d1[T[i]]) - set(d1[T[i + K]]))[0]
else:
hands[i] = T[i]
else:
hands[i] = d1[T[i]]
result += d2[T[i]]
print(result)
|
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
draws = [True] * K
d = {'r': P, 's': R, 'p': S}
result = 0
for i in range(len(T)):
if draws[i % K] or T[i] != T[i - K]:
result += d[T[i]]
draws[i % K] = False
else:
draws[i % K] = True
print(result)
| 18 | 14 | 485 | 326 |
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
hands = [None] * N
d1 = {"r": "p", "s": "r", "p": "s"}
d2 = {"r": P, "s": R, "p": S}
result = 0
for i in range(len(T)):
if i >= K and d1[T[i]] == hands[i - K]:
if i + K < N:
hands[i] = list(set("rps") - set(d1[T[i]]) - set(d1[T[i + K]]))[0]
else:
hands[i] = T[i]
else:
hands[i] = d1[T[i]]
result += d2[T[i]]
print(result)
|
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
draws = [True] * K
d = {"r": P, "s": R, "p": S}
result = 0
for i in range(len(T)):
if draws[i % K] or T[i] != T[i - K]:
result += d[T[i]]
draws[i % K] = False
else:
draws[i % K] = True
print(result)
| false | 22.222222 |
[
"-hands = [None] * N",
"-d1 = {\"r\": \"p\", \"s\": \"r\", \"p\": \"s\"}",
"-d2 = {\"r\": P, \"s\": R, \"p\": S}",
"+draws = [True] * K",
"+d = {\"r\": P, \"s\": R, \"p\": S}",
"- if i >= K and d1[T[i]] == hands[i - K]:",
"- if i + K < N:",
"- hands[i] = list(set(\"rps\") - set(d1[T[i]]) - set(d1[T[i + K]]))[0]",
"- else:",
"- hands[i] = T[i]",
"+ if draws[i % K] or T[i] != T[i - K]:",
"+ result += d[T[i]]",
"+ draws[i % K] = False",
"- hands[i] = d1[T[i]]",
"- result += d2[T[i]]",
"+ draws[i % K] = True"
] | false | 0.054787 | 0.038471 | 1.424102 |
[
"s974795020",
"s873927245"
] |
u562935282
|
p03325
|
python
|
s612381376
|
s947931652
| 90 | 60 | 4,212 | 3,828 |
Accepted
|
Accepted
| 33.33 |
N = int(eval(input()))
a = tuple(map(int, input().split()))
ans = 0
for aa in a:
while aa % 2 == 0:
aa //= 2
ans += 1
print(ans)
|
def main():
def count(x):
ret = 0
while x % 2 == 0:
x //= 2
ret += 1
return ret
N = int(eval(input()))
a = list(map(int, input().split()))
ans = sum(map(count, a))
print(ans)
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
| 9 | 24 | 152 | 426 |
N = int(eval(input()))
a = tuple(map(int, input().split()))
ans = 0
for aa in a:
while aa % 2 == 0:
aa //= 2
ans += 1
print(ans)
|
def main():
def count(x):
ret = 0
while x % 2 == 0:
x //= 2
ret += 1
return ret
N = int(eval(input()))
a = list(map(int, input().split()))
ans = sum(map(count, a))
print(ans)
if __name__ == "__main__":
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
| false | 62.5 |
[
"-N = int(eval(input()))",
"-a = tuple(map(int, input().split()))",
"-ans = 0",
"-for aa in a:",
"- while aa % 2 == 0:",
"- aa //= 2",
"- ans += 1",
"-print(ans)",
"+def main():",
"+ def count(x):",
"+ ret = 0",
"+ while x % 2 == 0:",
"+ x //= 2",
"+ ret += 1",
"+ return ret",
"+",
"+ N = int(eval(input()))",
"+ a = list(map(int, input().split()))",
"+ ans = sum(map(count, a))",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()",
"+# import sys",
"+# input = sys.stdin.readline",
"+#",
"+# sys.setrecursionlimit(10 ** 7)",
"+#",
"+# (int(x)-1 for x in input().split())",
"+# rstrip()"
] | false | 0.154638 | 0.04918 | 3.144347 |
[
"s612381376",
"s947931652"
] |
u449473917
|
p03835
|
python
|
s336322953
|
s663469309
| 1,767 | 267 | 3,060 | 40,684 |
Accepted
|
Accepted
| 84.89 |
K,S=input().split()
K=int(K)
S=int(S)
ans=0
for l in range(K+1):
for m in range(K+1):
if l+m<=S and l+m+K>=S:
ans=ans+1
print(ans)
|
k,s=list(map(int,input().split()))
ans=0
for i in range(k+1):
for j in range(k+1):
z=s-(i+j)
if z>=0 and z<=k:
ans+=1
print(ans)
| 9 | 11 | 162 | 167 |
K, S = input().split()
K = int(K)
S = int(S)
ans = 0
for l in range(K + 1):
for m in range(K + 1):
if l + m <= S and l + m + K >= S:
ans = ans + 1
print(ans)
|
k, s = list(map(int, input().split()))
ans = 0
for i in range(k + 1):
for j in range(k + 1):
z = s - (i + j)
if z >= 0 and z <= k:
ans += 1
print(ans)
| false | 18.181818 |
[
"-K, S = input().split()",
"-K = int(K)",
"-S = int(S)",
"+k, s = list(map(int, input().split()))",
"-for l in range(K + 1):",
"- for m in range(K + 1):",
"- if l + m <= S and l + m + K >= S:",
"- ans = ans + 1",
"+for i in range(k + 1):",
"+ for j in range(k + 1):",
"+ z = s - (i + j)",
"+ if z >= 0 and z <= k:",
"+ ans += 1"
] | false | 0.040111 | 0.04116 | 0.974527 |
[
"s336322953",
"s663469309"
] |
u124498235
|
p03633
|
python
|
s048852116
|
s924243770
| 41 | 37 | 5,432 | 5,048 |
Accepted
|
Accepted
| 9.76 |
from fractions import gcd
def lcm(a,b):
return (a*b) // gcd(a,b)
n = int(eval(input()))
y = 1
for i in range(n):
x = int(eval(input()))
y = lcm(x,y)
print (y)
|
from fractions import gcd
n = int(eval(input()))
t = [int(eval(input())) for i in range(n)]
def lcm(x, y):
return (x*y) // gcd(x,y)
x = t[0]
for i in t[1:]:
x = lcm(i,x)
print (x)
| 9 | 11 | 157 | 181 |
from fractions import gcd
def lcm(a, b):
return (a * b) // gcd(a, b)
n = int(eval(input()))
y = 1
for i in range(n):
x = int(eval(input()))
y = lcm(x, y)
print(y)
|
from fractions import gcd
n = int(eval(input()))
t = [int(eval(input())) for i in range(n)]
def lcm(x, y):
return (x * y) // gcd(x, y)
x = t[0]
for i in t[1:]:
x = lcm(i, x)
print(x)
| false | 18.181818 |
[
"-",
"-def lcm(a, b):",
"- return (a * b) // gcd(a, b)",
"+n = int(eval(input()))",
"+t = [int(eval(input())) for i in range(n)]",
"-n = int(eval(input()))",
"-y = 1",
"-for i in range(n):",
"- x = int(eval(input()))",
"- y = lcm(x, y)",
"-print(y)",
"+def lcm(x, y):",
"+ return (x * y) // gcd(x, y)",
"+",
"+",
"+x = t[0]",
"+for i in t[1:]:",
"+ x = lcm(i, x)",
"+print(x)"
] | false | 0.043812 | 0.044888 | 0.976014 |
[
"s048852116",
"s924243770"
] |
u359372421
|
p02390
|
python
|
s272751790
|
s500590808
| 30 | 20 | 6,452 | 5,584 |
Accepted
|
Accepted
| 33.33 |
def conv(sec):
h = sec // (60 * 60)
m = (sec - h * (60 * 60)) // 60
s = sec - m * 60 - h * (60 * 60)
return ":".join([str(h), str(m), str(s)])
# inp = list(map(int, input().split()))
print((conv(int(eval(input())))))
|
x = int(eval(input()))
s = x % 60
x //= 60
m = x % 60
x //= 60
print(("{}:{}:{}".format(x, m, s)))
| 8 | 6 | 233 | 96 |
def conv(sec):
h = sec // (60 * 60)
m = (sec - h * (60 * 60)) // 60
s = sec - m * 60 - h * (60 * 60)
return ":".join([str(h), str(m), str(s)])
# inp = list(map(int, input().split()))
print((conv(int(eval(input())))))
|
x = int(eval(input()))
s = x % 60
x //= 60
m = x % 60
x //= 60
print(("{}:{}:{}".format(x, m, s)))
| false | 25 |
[
"-def conv(sec):",
"- h = sec // (60 * 60)",
"- m = (sec - h * (60 * 60)) // 60",
"- s = sec - m * 60 - h * (60 * 60)",
"- return \":\".join([str(h), str(m), str(s)])",
"-",
"-",
"-# inp = list(map(int, input().split()))",
"-print((conv(int(eval(input())))))",
"+x = int(eval(input()))",
"+s = x % 60",
"+x //= 60",
"+m = x % 60",
"+x //= 60",
"+print((\"{}:{}:{}\".format(x, m, s)))"
] | false | 0.057812 | 0.034973 | 1.653023 |
[
"s272751790",
"s500590808"
] |
u621643202
|
p03449
|
python
|
s465104232
|
s557042669
| 20 | 18 | 3,064 | 3,064 |
Accepted
|
Accepted
| 10 |
N = int(eval(input()))
A1, A2 = [input().split() for _ in range(2)]
ans = 0
sum = 0
for n in range(0, N):
for i in range(0, n + 1):
#print('i=', i)
sum += int(A1[i])
for j in range(n, N):
#print('j=', j)
sum += int(A2[j])
if ans < sum:
ans = sum
sum = 0
print(ans)
|
N = int(eval(input()))
A1, A2 = [list(map(int, input().split())) for _ in range(2)]
ans = 0
sum = 0
for n in range(0, N):
for i in range(0, n + 1):
sum += A1[i]
for j in range(n, N):
sum += A2[j]
if ans < sum:
ans = sum
sum = 0
print(ans)
| 17 | 15 | 332 | 288 |
N = int(eval(input()))
A1, A2 = [input().split() for _ in range(2)]
ans = 0
sum = 0
for n in range(0, N):
for i in range(0, n + 1):
# print('i=', i)
sum += int(A1[i])
for j in range(n, N):
# print('j=', j)
sum += int(A2[j])
if ans < sum:
ans = sum
sum = 0
print(ans)
|
N = int(eval(input()))
A1, A2 = [list(map(int, input().split())) for _ in range(2)]
ans = 0
sum = 0
for n in range(0, N):
for i in range(0, n + 1):
sum += A1[i]
for j in range(n, N):
sum += A2[j]
if ans < sum:
ans = sum
sum = 0
print(ans)
| false | 11.764706 |
[
"-A1, A2 = [input().split() for _ in range(2)]",
"+A1, A2 = [list(map(int, input().split())) for _ in range(2)]",
"- # print('i=', i)",
"- sum += int(A1[i])",
"+ sum += A1[i]",
"- # print('j=', j)",
"- sum += int(A2[j])",
"+ sum += A2[j]"
] | false | 0.046101 | 0.045113 | 1.021907 |
[
"s465104232",
"s557042669"
] |
u753803401
|
p02948
|
python
|
s193804488
|
s014176209
| 932 | 810 | 75,740 | 75,484 |
Accepted
|
Accepted
| 13.09 |
def slove():
import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().rstrip('\n').split()))
ls =[]
v = []
heapq.heapify(v)
for i in range(n):
a, b = list(map(int, input().rstrip('\n').split()))
ls.append([a, b])
ls.sort(reverse=True)
r = 0
for i in range(1, m + 1):
while True:
if len(ls) != 0:
a, b = ls.pop()
if a <= i:
heapq.heappush(v, -b)
else:
ls.append([a, b])
break
else:
break
if len(v) != 0:
r += -heapq.heappop(v)
print(r)
if __name__ == '__main__':
slove()
|
import sys
import heapq
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, m = list(map(int, input().rstrip('\n').split()))
ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
ab.sort(reverse=True)
ls = []
heapq.heapify(ls)
t = 0
for i in range(1, m + 1):
while True:
if len(ab) != 0:
if ab[-1][0] <= i:
heapq.heappush(ls, -ab.pop()[1])
else:
break
else:
break
if len(ls) != 0:
t -= heapq.heappop(ls)
print(t)
if __name__ == '__main__':
solve()
| 31 | 29 | 769 | 689 |
def slove():
import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().rstrip("\n").split()))
ls = []
v = []
heapq.heapify(v)
for i in range(n):
a, b = list(map(int, input().rstrip("\n").split()))
ls.append([a, b])
ls.sort(reverse=True)
r = 0
for i in range(1, m + 1):
while True:
if len(ls) != 0:
a, b = ls.pop()
if a <= i:
heapq.heappush(v, -b)
else:
ls.append([a, b])
break
else:
break
if len(v) != 0:
r += -heapq.heappop(v)
print(r)
if __name__ == "__main__":
slove()
|
import sys
import heapq
def solve():
input = sys.stdin.readline
mod = 10**9 + 7
n, m = list(map(int, input().rstrip("\n").split()))
ab = [list(map(int, input().rstrip("\n").split())) for _ in range(n)]
ab.sort(reverse=True)
ls = []
heapq.heapify(ls)
t = 0
for i in range(1, m + 1):
while True:
if len(ab) != 0:
if ab[-1][0] <= i:
heapq.heappush(ls, -ab.pop()[1])
else:
break
else:
break
if len(ls) != 0:
t -= heapq.heappop(ls)
print(t)
if __name__ == "__main__":
solve()
| false | 6.451613 |
[
"-def slove():",
"- import sys",
"- import heapq",
"+import sys",
"+import heapq",
"+",
"+def solve():",
"+ mod = 10**9 + 7",
"+ ab = [list(map(int, input().rstrip(\"\\n\").split())) for _ in range(n)]",
"+ ab.sort(reverse=True)",
"- v = []",
"- heapq.heapify(v)",
"- for i in range(n):",
"- a, b = list(map(int, input().rstrip(\"\\n\").split()))",
"- ls.append([a, b])",
"- ls.sort(reverse=True)",
"- r = 0",
"+ heapq.heapify(ls)",
"+ t = 0",
"- if len(ls) != 0:",
"- a, b = ls.pop()",
"- if a <= i:",
"- heapq.heappush(v, -b)",
"+ if len(ab) != 0:",
"+ if ab[-1][0] <= i:",
"+ heapq.heappush(ls, -ab.pop()[1])",
"- ls.append([a, b])",
"- if len(v) != 0:",
"- r += -heapq.heappop(v)",
"- print(r)",
"+ if len(ls) != 0:",
"+ t -= heapq.heappop(ls)",
"+ print(t)",
"- slove()",
"+ solve()"
] | false | 0.035049 | 0.037255 | 0.940773 |
[
"s193804488",
"s014176209"
] |
u094999522
|
p02585
|
python
|
s250815370
|
s605856484
| 1,650 | 522 | 68,764 | 28,036 |
Accepted
|
Accepted
| 68.36 |
#import sys
#import numpy as np
def main(n,k,p,c):
ans = -10**9
for i in range(n):
x = i
t = k
count = 0
l = True
sub = 0
ln = 0
while True:
x = p[x] - 1
if l:
count += c[x]
ln += 1
if x == i:
if t > ln:
if count > 0:
sub += (t // ln - 1) * count
t %= ln
t += ln
else:
t = 0
l = False
sub += c[x]
t -= 1
ans = max(sub, ans)
if t < 1:
break
return ans
# >>> numba compile >>>
#if sys.argv[-1]=='ONLINE_JUDGE':
# from numba.pycc import CC
# cc=CC('my_module')
# cc.export('main','i8(i8,i8,i8[:],i8[:])')(main)
# cc.compile()
# exit()
#from my_module import main
# <<< numba compile <<<
(n, k), p, c = [[*list(map(int,i.split()))] for i in open(0)]
print((main(n,k,p,c)))
|
import sys
import numpy as np
def main(n,k,p,c):
ans = -10**9
for i in range(n):
x = i
t = k
count = 0
l = True
sub = 0
ln = 0
while True:
x = p[x] - 1
if l:
count += c[x]
ln += 1
if x == i:
if t > ln:
if count > 0:
sub += (t // ln - 1) * count
t %= ln
t += ln
else:
t = 0
l = False
sub += c[x]
t -= 1
ans = max(sub, ans)
if t < 1:
break
return ans
# >>> numba compile >>>
if sys.argv[-1]=='ONLINE_JUDGE' or sys.argv[-1]=='main.py':
from numba.pycc import CC
cc=CC('my_module')
cc.export('main','i8(i8,i8,i8[:],i8[:])')(main)
cc.compile()
exit()
from my_module import main
# <<< numba compile <<<
(n, k), p, c = [np.int_(i.split()) for i in open(0)]
print((main(n,k,p,c)))
| 47 | 47 | 1,121 | 1,136 |
# import sys
# import numpy as np
def main(n, k, p, c):
ans = -(10**9)
for i in range(n):
x = i
t = k
count = 0
l = True
sub = 0
ln = 0
while True:
x = p[x] - 1
if l:
count += c[x]
ln += 1
if x == i:
if t > ln:
if count > 0:
sub += (t // ln - 1) * count
t %= ln
t += ln
else:
t = 0
l = False
sub += c[x]
t -= 1
ans = max(sub, ans)
if t < 1:
break
return ans
# >>> numba compile >>>
# if sys.argv[-1]=='ONLINE_JUDGE':
# from numba.pycc import CC
# cc=CC('my_module')
# cc.export('main','i8(i8,i8,i8[:],i8[:])')(main)
# cc.compile()
# exit()
# from my_module import main
# <<< numba compile <<<
(n, k), p, c = [[*list(map(int, i.split()))] for i in open(0)]
print((main(n, k, p, c)))
|
import sys
import numpy as np
def main(n, k, p, c):
ans = -(10**9)
for i in range(n):
x = i
t = k
count = 0
l = True
sub = 0
ln = 0
while True:
x = p[x] - 1
if l:
count += c[x]
ln += 1
if x == i:
if t > ln:
if count > 0:
sub += (t // ln - 1) * count
t %= ln
t += ln
else:
t = 0
l = False
sub += c[x]
t -= 1
ans = max(sub, ans)
if t < 1:
break
return ans
# >>> numba compile >>>
if sys.argv[-1] == "ONLINE_JUDGE" or sys.argv[-1] == "main.py":
from numba.pycc import CC
cc = CC("my_module")
cc.export("main", "i8(i8,i8,i8[:],i8[:])")(main)
cc.compile()
exit()
from my_module import main
# <<< numba compile <<<
(n, k), p, c = [np.int_(i.split()) for i in open(0)]
print((main(n, k, p, c)))
| false | 0 |
[
"-# import sys",
"-# import numpy as np",
"+import sys",
"+import numpy as np",
"+",
"+",
"-# if sys.argv[-1]=='ONLINE_JUDGE':",
"-# from numba.pycc import CC",
"-# cc=CC('my_module')",
"-# cc.export('main','i8(i8,i8,i8[:],i8[:])')(main)",
"-# cc.compile()",
"-# exit()",
"-# from my_module import main",
"+if sys.argv[-1] == \"ONLINE_JUDGE\" or sys.argv[-1] == \"main.py\":",
"+ from numba.pycc import CC",
"+",
"+ cc = CC(\"my_module\")",
"+ cc.export(\"main\", \"i8(i8,i8,i8[:],i8[:])\")(main)",
"+ cc.compile()",
"+ exit()",
"+from my_module import main",
"+",
"-(n, k), p, c = [[*list(map(int, i.split()))] for i in open(0)]",
"+(n, k), p, c = [np.int_(i.split()) for i in open(0)]"
] | false | 0.118003 | 0.505734 | 0.233331 |
[
"s250815370",
"s605856484"
] |
u735008991
|
p03835
|
python
|
s692852463
|
s459274626
| 887 | 257 | 52,760 | 40,684 |
Accepted
|
Accepted
| 71.03 |
K, S = list(map(int, input().split()))
print(([0 <= S - x - y <= K for x in range(K+1)
for y in range(K+1)].count(True)))
|
K, S = list(map(int, input().split()))
ans = 0
for x in range(K+1):
for y in range(K+1):
ans += 0 <= S - x - y <= K
print(ans)
| 3 | 6 | 123 | 138 |
K, S = list(map(int, input().split()))
print(([0 <= S - x - y <= K for x in range(K + 1) for y in range(K + 1)].count(True)))
|
K, S = list(map(int, input().split()))
ans = 0
for x in range(K + 1):
for y in range(K + 1):
ans += 0 <= S - x - y <= K
print(ans)
| false | 50 |
[
"-print(([0 <= S - x - y <= K for x in range(K + 1) for y in range(K + 1)].count(True)))",
"+ans = 0",
"+for x in range(K + 1):",
"+ for y in range(K + 1):",
"+ ans += 0 <= S - x - y <= K",
"+print(ans)"
] | false | 0.117096 | 0.044349 | 2.640352 |
[
"s692852463",
"s459274626"
] |
u694810977
|
p02837
|
python
|
s575873008
|
s739488769
| 729 | 658 | 3,188 | 3,064 |
Accepted
|
Accepted
| 9.74 |
#入力はn人のx,yに分けないといけない
n = int(eval(input()))
a = []
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
a.append(int(eval(input())))
for j in range(a[i]):
xx, yy = (int(i) for i in input().split())
x[i].append(xx)
y[i].append(yy)
testimony = [[2]*n for i in range(n)]
for i in range(n):
for j in range(a[i]):
if (y[i][j] == 1):
testimony[i][x[i][j] - 1] = 1#正直者ならtestimonyのxの位置に正直者である1を置く
elif(y[i][j] == 0):
testimony[i][x[i][j]-1] = 0#さっきの反対
ans = 0
for i in range(2**n):#2**n通りの「正直者」と「不親切な人」の全パターンを列挙
bit_list = []
for j in range(n):
if ((i >> j) & 1):
bit_list.append(1)#正直者なら
else:
bit_list.append(0)
flag = 1
#列挙した中からtestimony[k][l]と一致するのを探し、さらにその中からbit_listの最大値を求める
for k in range(n):
if(bit_list[k] == 1):
for l in range(n):
if(testimony[k][l] != 2):#2(デフォルト状態じゃないとき)
if(testimony[k][l] != bit_list[l]): #yの人の証言と食い違っていたらflagを0にする
flag = 0
break
if(flag == 1):
ans = max(sum(bit_list),ans)
print(ans)
|
n = int(eval(input()))
#2**n通りの正直者を全列挙してそれを矛盾が生じないか試していき最大値を求める 競合してる証言をピック True or False で判断する
jud = [[-1 for i in range(n)] for j in range(n)]
xy = []
ayasi = []
for i in range(n):
a = int(eval(input()))
for j in range(a):
x,y = list(map(int,input().split()))
jud[i][x-1] = y
Max = 0
for i in range(2**n):
li = []
flag = True
cnt = 0
for j in range(n):
if ((i >> j) & 1):
li.append(1)
else:
li.append(0)
for k in range(n):
if li[k] == 1:
for l in range(n):
if jud[k][l] != -1:
if jud[k][l] != li[l]:
flag = False
break
if flag:
Max = max(sum(li),Max)
print(Max)
| 42 | 32 | 1,216 | 764 |
# 入力はn人のx,yに分けないといけない
n = int(eval(input()))
a = []
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
a.append(int(eval(input())))
for j in range(a[i]):
xx, yy = (int(i) for i in input().split())
x[i].append(xx)
y[i].append(yy)
testimony = [[2] * n for i in range(n)]
for i in range(n):
for j in range(a[i]):
if y[i][j] == 1:
testimony[i][x[i][j] - 1] = 1 # 正直者ならtestimonyのxの位置に正直者である1を置く
elif y[i][j] == 0:
testimony[i][x[i][j] - 1] = 0 # さっきの反対
ans = 0
for i in range(2**n): # 2**n通りの「正直者」と「不親切な人」の全パターンを列挙
bit_list = []
for j in range(n):
if (i >> j) & 1:
bit_list.append(1) # 正直者なら
else:
bit_list.append(0)
flag = 1
# 列挙した中からtestimony[k][l]と一致するのを探し、さらにその中からbit_listの最大値を求める
for k in range(n):
if bit_list[k] == 1:
for l in range(n):
if testimony[k][l] != 2: # 2(デフォルト状態じゃないとき)
if testimony[k][l] != bit_list[l]: # yの人の証言と食い違っていたらflagを0にする
flag = 0
break
if flag == 1:
ans = max(sum(bit_list), ans)
print(ans)
|
n = int(eval(input()))
# 2**n通りの正直者を全列挙してそれを矛盾が生じないか試していき最大値を求める 競合してる証言をピック True or False で判断する
jud = [[-1 for i in range(n)] for j in range(n)]
xy = []
ayasi = []
for i in range(n):
a = int(eval(input()))
for j in range(a):
x, y = list(map(int, input().split()))
jud[i][x - 1] = y
Max = 0
for i in range(2**n):
li = []
flag = True
cnt = 0
for j in range(n):
if (i >> j) & 1:
li.append(1)
else:
li.append(0)
for k in range(n):
if li[k] == 1:
for l in range(n):
if jud[k][l] != -1:
if jud[k][l] != li[l]:
flag = False
break
if flag:
Max = max(sum(li), Max)
print(Max)
| false | 23.809524 |
[
"-# 入力はn人のx,yに分けないといけない",
"-a = []",
"-x = [[] for i in range(n)]",
"-y = [[] for i in range(n)]",
"+# 2**n通りの正直者を全列挙してそれを矛盾が生じないか試していき最大値を求める 競合してる証言をピック True or False で判断する",
"+jud = [[-1 for i in range(n)] for j in range(n)]",
"+xy = []",
"+ayasi = []",
"- a.append(int(eval(input())))",
"- for j in range(a[i]):",
"- xx, yy = (int(i) for i in input().split())",
"- x[i].append(xx)",
"- y[i].append(yy)",
"-testimony = [[2] * n for i in range(n)]",
"-for i in range(n):",
"- for j in range(a[i]):",
"- if y[i][j] == 1:",
"- testimony[i][x[i][j] - 1] = 1 # 正直者ならtestimonyのxの位置に正直者である1を置く",
"- elif y[i][j] == 0:",
"- testimony[i][x[i][j] - 1] = 0 # さっきの反対",
"-ans = 0",
"-for i in range(2**n): # 2**n通りの「正直者」と「不親切な人」の全パターンを列挙",
"- bit_list = []",
"+ a = int(eval(input()))",
"+ for j in range(a):",
"+ x, y = list(map(int, input().split()))",
"+ jud[i][x - 1] = y",
"+Max = 0",
"+for i in range(2**n):",
"+ li = []",
"+ flag = True",
"+ cnt = 0",
"- bit_list.append(1) # 正直者なら",
"+ li.append(1)",
"- bit_list.append(0)",
"- flag = 1",
"- # 列挙した中からtestimony[k][l]と一致するのを探し、さらにその中からbit_listの最大値を求める",
"+ li.append(0)",
"- if bit_list[k] == 1:",
"+ if li[k] == 1:",
"- if testimony[k][l] != 2: # 2(デフォルト状態じゃないとき)",
"- if testimony[k][l] != bit_list[l]: # yの人の証言と食い違っていたらflagを0にする",
"- flag = 0",
"+ if jud[k][l] != -1:",
"+ if jud[k][l] != li[l]:",
"+ flag = False",
"- if flag == 1:",
"- ans = max(sum(bit_list), ans)",
"-print(ans)",
"+ if flag:",
"+ Max = max(sum(li), Max)",
"+print(Max)"
] | false | 0.046798 | 0.048062 | 0.973697 |
[
"s575873008",
"s739488769"
] |
u272028993
|
p03695
|
python
|
s853385241
|
s080981140
| 11 | 10 | 2,696 | 2,568 |
Accepted
|
Accepted
| 9.09 |
n=int(input())
a=list(map(int,input().split()))
c=[0]*8
mx=0
for i in range(n):
if 1<=a[i]<400:
c[0]=1
elif 400<=a[i]<800:
c[1]=1
elif 800<=a[i]<1200:
c[2]=1
elif 1200<=a[i]<1600:
c[3]=1
elif 1600<=a[i]<2000:
c[4]=1
elif 2000<=a[i]<2400:
c[5]=1
elif 2400<=a[i]<2800:
c[6]=1
elif 2800<=a[i]<3200:
c[7]=1
else:
mx+=1
print(max(1,sum(c)),sum(c)+mx)
|
n=int(input())
a=list(map(int,input().split()))
c=[0]*8
mx=0
for i in range(n):
if a[i]/400<=7:
c[a[i]/400]=1
else:
mx+=1
print(max(1,sum(c)),sum(c)+mx)
| 24 | 10 | 478 | 187 |
n = int(input())
a = list(map(int, input().split()))
c = [0] * 8
mx = 0
for i in range(n):
if 1 <= a[i] < 400:
c[0] = 1
elif 400 <= a[i] < 800:
c[1] = 1
elif 800 <= a[i] < 1200:
c[2] = 1
elif 1200 <= a[i] < 1600:
c[3] = 1
elif 1600 <= a[i] < 2000:
c[4] = 1
elif 2000 <= a[i] < 2400:
c[5] = 1
elif 2400 <= a[i] < 2800:
c[6] = 1
elif 2800 <= a[i] < 3200:
c[7] = 1
else:
mx += 1
print(max(1, sum(c)), sum(c) + mx)
|
n = int(input())
a = list(map(int, input().split()))
c = [0] * 8
mx = 0
for i in range(n):
if a[i] / 400 <= 7:
c[a[i] / 400] = 1
else:
mx += 1
print(max(1, sum(c)), sum(c) + mx)
| false | 58.333333 |
[
"- if 1 <= a[i] < 400:",
"- c[0] = 1",
"- elif 400 <= a[i] < 800:",
"- c[1] = 1",
"- elif 800 <= a[i] < 1200:",
"- c[2] = 1",
"- elif 1200 <= a[i] < 1600:",
"- c[3] = 1",
"- elif 1600 <= a[i] < 2000:",
"- c[4] = 1",
"- elif 2000 <= a[i] < 2400:",
"- c[5] = 1",
"- elif 2400 <= a[i] < 2800:",
"- c[6] = 1",
"- elif 2800 <= a[i] < 3200:",
"- c[7] = 1",
"+ if a[i] / 400 <= 7:",
"+ c[a[i] / 400] = 1"
] | false | 0.037538 | 0.036326 | 1.03334 |
[
"s853385241",
"s080981140"
] |
u328510800
|
p03160
|
python
|
s550464225
|
s299309932
| 186 | 172 | 15,032 | 13,976 |
Accepted
|
Accepted
| 7.53 |
n = int(eval(input()))
dp = [10 ** 9 for _ in range(n + 2)] # ちょっと大きめに
dp[0] = 0
h = [int(x) for x in input().split()]
for i in range(1, n):
total_cost = dp[i-1] + abs(h[i] - h[i-1])
dp[i] = min(dp[i], total_cost)
if i > 1:
total_cost = dp[i-2] + abs(h[i] - h[i - 2])
dp[i] = min(dp[i], total_cost)
print((dp[n-1]))
|
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [10 ** 9 for _ in range(n+1)]
# スタート位置
dp[0] = 0
for i in range(n):
dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
if i > 1:
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i-2]))
print((dp[n-1]))
| 14 | 13 | 339 | 281 |
n = int(eval(input()))
dp = [10**9 for _ in range(n + 2)] # ちょっと大きめに
dp[0] = 0
h = [int(x) for x in input().split()]
for i in range(1, n):
total_cost = dp[i - 1] + abs(h[i] - h[i - 1])
dp[i] = min(dp[i], total_cost)
if i > 1:
total_cost = dp[i - 2] + abs(h[i] - h[i - 2])
dp[i] = min(dp[i], total_cost)
print((dp[n - 1]))
|
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [10**9 for _ in range(n + 1)]
# スタート位置
dp[0] = 0
for i in range(n):
dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i > 1:
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[n - 1]))
| false | 7.142857 |
[
"-dp = [10**9 for _ in range(n + 2)] # ちょっと大きめに",
"+h = list(map(int, input().split()))",
"+dp = [10**9 for _ in range(n + 1)]",
"+# スタート位置",
"-h = [int(x) for x in input().split()]",
"-for i in range(1, n):",
"- total_cost = dp[i - 1] + abs(h[i] - h[i - 1])",
"- dp[i] = min(dp[i], total_cost)",
"+for i in range(n):",
"+ dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))",
"- total_cost = dp[i - 2] + abs(h[i] - h[i - 2])",
"- dp[i] = min(dp[i], total_cost)",
"+ dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))"
] | false | 0.044018 | 0.044299 | 0.993664 |
[
"s550464225",
"s299309932"
] |
u241159583
|
p02989
|
python
|
s666485943
|
s240528946
| 75 | 66 | 14,428 | 20,728 |
Accepted
|
Accepted
| 12 |
N = int(eval(input()))
d = list(map(int, input().split()))
d.sort()
n = N // 2 -1
print((d[n+1] - d[n]))
|
n = int(eval(input()))
d = sorted(list(map(int, input().split())))
l,r = d[n//2-1], d[n//2]
print((r-l))
| 5 | 4 | 100 | 99 |
N = int(eval(input()))
d = list(map(int, input().split()))
d.sort()
n = N // 2 - 1
print((d[n + 1] - d[n]))
|
n = int(eval(input()))
d = sorted(list(map(int, input().split())))
l, r = d[n // 2 - 1], d[n // 2]
print((r - l))
| false | 20 |
[
"-N = int(eval(input()))",
"-d = list(map(int, input().split()))",
"-d.sort()",
"-n = N // 2 - 1",
"-print((d[n + 1] - d[n]))",
"+n = int(eval(input()))",
"+d = sorted(list(map(int, input().split())))",
"+l, r = d[n // 2 - 1], d[n // 2]",
"+print((r - l))"
] | false | 0.076907 | 0.048425 | 1.588157 |
[
"s666485943",
"s240528946"
] |
u102461423
|
p02822
|
python
|
s201587178
|
s703064523
| 1,422 | 1,127 | 67,464 | 84,744 |
Accepted
|
Accepted
| 20.75 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = list(map(int,read().split()))
AB = list(zip(m,m))
MOD = 10 ** 9 + 7
graph = [[] for _ in range(N+1)]
for a,b in AB:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
# (1/2)^n
x = (MOD + 1) // 2
power = [1] * (N+100)
power_inv = [1] * (N+100)
for i in range(1,N+100):
power[i] = power[i-1] * 2 % MOD
power_inv[i] = power_inv[i-1] * x % MOD
# 部分木の大きさ
answer = 0
size = [1] * (N+1)
for v in order[::-1]:
p = parent[v]
size[p] += size[v]
A = [size[w] for w in graph[v] if w != p] # 部分木のサイズ集合
if v != root:
A.append(N - 1 - sum(A))
if len(A) == 1:
continue
prod = 1
coef = 1
for x in A:
prod *= power_inv[x]
prod %= MOD
coef += (power[x] - 1)
E = 1 - prod * coef % MOD
answer += E
answer *= power_inv[1]
answer %= MOD
print(answer)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = list(map(int,read().split()))
AB = list(zip(m,m))
MOD = 10 ** 9 + 7
graph = [[] for _ in range(N+1)]
for a,b in AB:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
# (1/2)^n
x = (MOD + 1) // 2
power = [1] * (N+100)
power_inv = [1] * (N+100)
for i in range(1,N+100):
power[i] = power[i-1] * 2 % MOD
power_inv[i] = power_inv[i-1] * x % MOD
# 部分木の大きさ
answer = 0
size = [1] * (N+1)
p_size = [N-1] * (N+1)
prod = [1] * (N+1)
coef = [1] * (N+1)
for v in order[::-1]:
p = parent[v]
x = size[v]
size[p] += x
prod[p] *= power_inv[x]; prod[p] %= MOD
coef[p] += power[x] - 1
x = N - x
prod[v] *= power_inv[x]
coef[v] += power[x] - 1
E = 1 - prod[v] * coef[v] % MOD
answer += E
answer *= power_inv[1]
answer %= MOD
print(answer)
| 60 | 58 | 1,232 | 1,180 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = list(map(int, read().split()))
AB = list(zip(m, m))
MOD = 10**9 + 7
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
# (1/2)^n
x = (MOD + 1) // 2
power = [1] * (N + 100)
power_inv = [1] * (N + 100)
for i in range(1, N + 100):
power[i] = power[i - 1] * 2 % MOD
power_inv[i] = power_inv[i - 1] * x % MOD
# 部分木の大きさ
answer = 0
size = [1] * (N + 1)
for v in order[::-1]:
p = parent[v]
size[p] += size[v]
A = [size[w] for w in graph[v] if w != p] # 部分木のサイズ集合
if v != root:
A.append(N - 1 - sum(A))
if len(A) == 1:
continue
prod = 1
coef = 1
for x in A:
prod *= power_inv[x]
prod %= MOD
coef += power[x] - 1
E = 1 - prod * coef % MOD
answer += E
answer *= power_inv[1]
answer %= MOD
print(answer)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = list(map(int, read().split()))
AB = list(zip(m, m))
MOD = 10**9 + 7
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
# (1/2)^n
x = (MOD + 1) // 2
power = [1] * (N + 100)
power_inv = [1] * (N + 100)
for i in range(1, N + 100):
power[i] = power[i - 1] * 2 % MOD
power_inv[i] = power_inv[i - 1] * x % MOD
# 部分木の大きさ
answer = 0
size = [1] * (N + 1)
p_size = [N - 1] * (N + 1)
prod = [1] * (N + 1)
coef = [1] * (N + 1)
for v in order[::-1]:
p = parent[v]
x = size[v]
size[p] += x
prod[p] *= power_inv[x]
prod[p] %= MOD
coef[p] += power[x] - 1
x = N - x
prod[v] *= power_inv[x]
coef[v] += power[x] - 1
E = 1 - prod[v] * coef[v] % MOD
answer += E
answer *= power_inv[1]
answer %= MOD
print(answer)
| false | 3.333333 |
[
"+p_size = [N - 1] * (N + 1)",
"+prod = [1] * (N + 1)",
"+coef = [1] * (N + 1)",
"- size[p] += size[v]",
"- A = [size[w] for w in graph[v] if w != p] # 部分木のサイズ集合",
"- if v != root:",
"- A.append(N - 1 - sum(A))",
"- if len(A) == 1:",
"- continue",
"- prod = 1",
"- coef = 1",
"- for x in A:",
"- prod *= power_inv[x]",
"- prod %= MOD",
"- coef += power[x] - 1",
"- E = 1 - prod * coef % MOD",
"+ x = size[v]",
"+ size[p] += x",
"+ prod[p] *= power_inv[x]",
"+ prod[p] %= MOD",
"+ coef[p] += power[x] - 1",
"+ x = N - x",
"+ prod[v] *= power_inv[x]",
"+ coef[v] += power[x] - 1",
"+ E = 1 - prod[v] * coef[v] % MOD"
] | false | 0.044086 | 0.043646 | 1.010089 |
[
"s201587178",
"s703064523"
] |
u498487134
|
p02803
|
python
|
s502066516
|
s898699395
| 802 | 690 | 42,864 | 54,116 |
Accepted
|
Accepted
| 13.97 |
H,W=list(map(int,input().split()))
S=[[] for _ in range(H)]
for i in range(H):
S[i]=eval(input())
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
n=H*W
inf=10**9
d = [[inf]*n for _ in range(n)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(H):
for j in range(W):
if S[i][j]==".":
if j+1<W:
if S[i][j+1]==".":
d[i*W+j][i*W+j+1]=1
d[i*W+j+1][i*W+j]=1
if i+1<H:
if S[i+1][j]==".":
d[i*W+j][(i+1)*W+j]=1
d[(i+1)*W+j][i*W+j]=1
for i in range(n):
d[i][i] = 0 #自身のところに行くコストは0
ans=0
warshall_floyd(d)
for i in range(n):
for j in range(n):
if d[i][j]>=ans and d[i][j]<=inf-10:
ans=d[i][j]
print(ans)
|
import queue
H,W=list(map(int,input().split()))
S=[[] for _ in range(H)]
dx=[0,0,-1,1]
dy=[-1,1,0,0]
for i in range(H):
S[i]=eval(input())
def bfs(i,j):
max_d=0
q=queue.Queue()
q.put((i,j))
d=[[0]*W for _ in range(H)]
while not q.empty():
loc=q.get()
for k in range(len(dx)):
x=loc[1]+dx[k]
y=loc[0]+dy[k]
if x>=0 and x<W and y>=0 and y<H:
if S[y][x]==".":
if d[y][x]==0 and not(x==j and y==i):
q.put((y,x))
d[y][x]=d[loc[0]][loc[1]]+1
max_d=max(max_d,d[y][x])
return max_d
ans=0
for i in range(H):
for j in range(W):
if S[i][j]==".":
ans=max(bfs(i,j),ans)
print(ans)
| 44 | 36 | 979 | 816 |
H, W = list(map(int, input().split()))
S = [[] for _ in range(H)]
for i in range(H):
S[i] = eval(input())
def warshall_floyd(d):
# d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
n = H * W
inf = 10**9
d = [[inf] * n for _ in range(n)]
# d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(H):
for j in range(W):
if S[i][j] == ".":
if j + 1 < W:
if S[i][j + 1] == ".":
d[i * W + j][i * W + j + 1] = 1
d[i * W + j + 1][i * W + j] = 1
if i + 1 < H:
if S[i + 1][j] == ".":
d[i * W + j][(i + 1) * W + j] = 1
d[(i + 1) * W + j][i * W + j] = 1
for i in range(n):
d[i][i] = 0 # 自身のところに行くコストは0
ans = 0
warshall_floyd(d)
for i in range(n):
for j in range(n):
if d[i][j] >= ans and d[i][j] <= inf - 10:
ans = d[i][j]
print(ans)
|
import queue
H, W = list(map(int, input().split()))
S = [[] for _ in range(H)]
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
for i in range(H):
S[i] = eval(input())
def bfs(i, j):
max_d = 0
q = queue.Queue()
q.put((i, j))
d = [[0] * W for _ in range(H)]
while not q.empty():
loc = q.get()
for k in range(len(dx)):
x = loc[1] + dx[k]
y = loc[0] + dy[k]
if x >= 0 and x < W and y >= 0 and y < H:
if S[y][x] == ".":
if d[y][x] == 0 and not (x == j and y == i):
q.put((y, x))
d[y][x] = d[loc[0]][loc[1]] + 1
max_d = max(max_d, d[y][x])
return max_d
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] == ".":
ans = max(bfs(i, j), ans)
print(ans)
| false | 18.181818 |
[
"+import queue",
"+",
"+dx = [0, 0, -1, 1]",
"+dy = [-1, 1, 0, 0]",
"-def warshall_floyd(d):",
"- # d[i][j]: iからjへの最短距離",
"- for k in range(n):",
"- for i in range(n):",
"- for j in range(n):",
"- d[i][j] = min(d[i][j], d[i][k] + d[k][j])",
"- return d",
"+def bfs(i, j):",
"+ max_d = 0",
"+ q = queue.Queue()",
"+ q.put((i, j))",
"+ d = [[0] * W for _ in range(H)]",
"+ while not q.empty():",
"+ loc = q.get()",
"+ for k in range(len(dx)):",
"+ x = loc[1] + dx[k]",
"+ y = loc[0] + dy[k]",
"+ if x >= 0 and x < W and y >= 0 and y < H:",
"+ if S[y][x] == \".\":",
"+ if d[y][x] == 0 and not (x == j and y == i):",
"+ q.put((y, x))",
"+ d[y][x] = d[loc[0]][loc[1]] + 1",
"+ max_d = max(max_d, d[y][x])",
"+ return max_d",
"-n = H * W",
"-inf = 10**9",
"-d = [[inf] * n for _ in range(n)]",
"-# d[u][v] : 辺uvのコスト(存在しないときはinf)",
"+ans = 0",
"- if j + 1 < W:",
"- if S[i][j + 1] == \".\":",
"- d[i * W + j][i * W + j + 1] = 1",
"- d[i * W + j + 1][i * W + j] = 1",
"- if i + 1 < H:",
"- if S[i + 1][j] == \".\":",
"- d[i * W + j][(i + 1) * W + j] = 1",
"- d[(i + 1) * W + j][i * W + j] = 1",
"-for i in range(n):",
"- d[i][i] = 0 # 自身のところに行くコストは0",
"-ans = 0",
"-warshall_floyd(d)",
"-for i in range(n):",
"- for j in range(n):",
"- if d[i][j] >= ans and d[i][j] <= inf - 10:",
"- ans = d[i][j]",
"+ ans = max(bfs(i, j), ans)"
] | false | 0.038243 | 0.048885 | 0.782303 |
[
"s502066516",
"s898699395"
] |
u123756661
|
p02880
|
python
|
s816399771
|
s789528996
| 184 | 63 | 38,384 | 61,884 |
Accepted
|
Accepted
| 65.76 |
n=int(eval(input()))
for i in range(1,10):
for j in range(1,i+1):
if n==i*j:
print("Yes")
exit()
print("No")
|
n=int(eval(input()))
d=set([i*j for i in range(1,10) for j in range(1,10)])
print(("Yes" if n in d else "No"))
| 7 | 3 | 144 | 104 |
n = int(eval(input()))
for i in range(1, 10):
for j in range(1, i + 1):
if n == i * j:
print("Yes")
exit()
print("No")
|
n = int(eval(input()))
d = set([i * j for i in range(1, 10) for j in range(1, 10)])
print(("Yes" if n in d else "No"))
| false | 57.142857 |
[
"-for i in range(1, 10):",
"- for j in range(1, i + 1):",
"- if n == i * j:",
"- print(\"Yes\")",
"- exit()",
"-print(\"No\")",
"+d = set([i * j for i in range(1, 10) for j in range(1, 10)])",
"+print((\"Yes\" if n in d else \"No\"))"
] | false | 0.04579 | 0.104993 | 0.436123 |
[
"s816399771",
"s789528996"
] |
u361826811
|
p02911
|
python
|
s396001059
|
s011847019
| 92 | 65 | 12,392 | 11,624 |
Accepted
|
Accepted
| 29.35 |
"""
author : halo2halo
date : 4, Feb, 2020
"""
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, Q, *A = map(int, read().split())
point =[K-Q]*(N+1)
for i in A:
point[i] += 1
print(*['Yes' if i > 0 else 'No' for i in point[1:]], sep='\n')
|
"""
author : halo2halo
date : 4, Feb, 2020
"""
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, Q, *A = list(map(int, read().split()))
point = [K - Q] * (N + 1)
for i in A:
point[i] += 1
ans = '\n'.join('Yes' if i > 0 else 'No' for i in point[1:])
print(ans)
| 18 | 20 | 357 | 375 |
"""
author : halo2halo
date : 4, Feb, 2020
"""
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, Q, *A = map(int, read().split())
point = [K - Q] * (N + 1)
for i in A:
point[i] += 1
print(*["Yes" if i > 0 else "No" for i in point[1:]], sep="\n")
|
"""
author : halo2halo
date : 4, Feb, 2020
"""
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, Q, *A = list(map(int, read().split()))
point = [K - Q] * (N + 1)
for i in A:
point[i] += 1
ans = "\n".join("Yes" if i > 0 else "No" for i in point[1:])
print(ans)
| false | 10 |
[
"-N, K, Q, *A = map(int, read().split())",
"+N, K, Q, *A = list(map(int, read().split()))",
"-print(*[\"Yes\" if i > 0 else \"No\" for i in point[1:]], sep=\"\\n\")",
"+ans = \"\\n\".join(\"Yes\" if i > 0 else \"No\" for i in point[1:])",
"+print(ans)"
] | false | 0.038786 | 0.041789 | 0.928126 |
[
"s396001059",
"s011847019"
] |
u879870653
|
p03000
|
python
|
s477798484
|
s528735585
| 166 | 18 | 38,256 | 2,940 |
Accepted
|
Accepted
| 89.16 |
N,X = list(map(int,input().split()))
L = list(map(int,input().split()))
ans = 1
d = 0
for i in range(len(L)) :
d += L[i]
if d <= X :
ans += 1
print(ans)
|
N,X = list(map(int,input().split()))
L = list(map(int,input().split()))
ans = 1
d = 0
for i in range(N) :
d += L[i]
if d > X :
break
ans += 1
print(ans)
| 11 | 14 | 174 | 188 |
N, X = list(map(int, input().split()))
L = list(map(int, input().split()))
ans = 1
d = 0
for i in range(len(L)):
d += L[i]
if d <= X:
ans += 1
print(ans)
|
N, X = list(map(int, input().split()))
L = list(map(int, input().split()))
ans = 1
d = 0
for i in range(N):
d += L[i]
if d > X:
break
ans += 1
print(ans)
| false | 21.428571 |
[
"-for i in range(len(L)):",
"+for i in range(N):",
"- if d <= X:",
"- ans += 1",
"+ if d > X:",
"+ break",
"+ ans += 1"
] | false | 0.040051 | 0.03803 | 1.053147 |
[
"s477798484",
"s528735585"
] |
u401452016
|
p03031
|
python
|
s786699302
|
s539471220
| 40 | 32 | 3,064 | 3,316 |
Accepted
|
Accepted
| 20 |
#ABC 128C
def main():
import sys
N, M = list(map(int, sys.stdin.readline().split()))
Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
P = list(map(int, sys.stdin.readline().split()))
#print(Light)
#print(P)
ans = 0
for i in range(2**N):
cnt = [0 for _ in range(M)]
for m in range(M):
for s in Light[m][1:]:
cnt[m] += (i>>N-s)&1
cnt = list([x%2 for x in cnt])
if cnt == P:
ans +=1
print(ans)
if __name__=='__main__':
main()
|
#ABC 128C
def main():
import sys
import itertools as ite
N, M = list(map(int, sys.stdin.readline().split()))
Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
P = list(map(int, sys.stdin.readline().split()))
S = list(ite.product([0,1], repeat=N)) #スイッチの状態
ans = 0
for s_state in S:
L_result = [0 for _ in range(M)]
for m in range(M):
for s_no in Light[m][1:]:
L_result[m] += s_state[s_no-1]
L_result = list([x%2 for x in L_result])
if P == L_result:
ans +=1
print(ans)
if __name__=='__main__':
main()
| 21 | 21 | 579 | 656 |
# ABC 128C
def main():
import sys
N, M = list(map(int, sys.stdin.readline().split()))
Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
P = list(map(int, sys.stdin.readline().split()))
# print(Light)
# print(P)
ans = 0
for i in range(2**N):
cnt = [0 for _ in range(M)]
for m in range(M):
for s in Light[m][1:]:
cnt[m] += (i >> N - s) & 1
cnt = list([x % 2 for x in cnt])
if cnt == P:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
# ABC 128C
def main():
import sys
import itertools as ite
N, M = list(map(int, sys.stdin.readline().split()))
Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
P = list(map(int, sys.stdin.readline().split()))
S = list(ite.product([0, 1], repeat=N)) # スイッチの状態
ans = 0
for s_state in S:
L_result = [0 for _ in range(M)]
for m in range(M):
for s_no in Light[m][1:]:
L_result[m] += s_state[s_no - 1]
L_result = list([x % 2 for x in L_result])
if P == L_result:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"+ import itertools as ite",
"- # print(Light)",
"- # print(P)",
"+ S = list(ite.product([0, 1], repeat=N)) # スイッチの状態",
"- for i in range(2**N):",
"- cnt = [0 for _ in range(M)]",
"+ for s_state in S:",
"+ L_result = [0 for _ in range(M)]",
"- for s in Light[m][1:]:",
"- cnt[m] += (i >> N - s) & 1",
"- cnt = list([x % 2 for x in cnt])",
"- if cnt == P:",
"+ for s_no in Light[m][1:]:",
"+ L_result[m] += s_state[s_no - 1]",
"+ L_result = list([x % 2 for x in L_result])",
"+ if P == L_result:"
] | false | 0.035654 | 0.043472 | 0.82016 |
[
"s786699302",
"s539471220"
] |
u785989355
|
p03608
|
python
|
s064928904
|
s129027357
| 715 | 530 | 10,084 | 62,808 |
Accepted
|
Accepted
| 25.87 |
N,M,R = list(map(int,input().split()))
r = list(map(int,input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
a,b,c = list(map(int,input().split()))
a=a-1
b=b-1
e_list[a].append([b,c])
e_list[b].append([a,c])
#dijkstra
#you need to prepare e_list = [[orient,dist]]
import heapq
r_dis_list = []
for i in range(len(r)):
vi = r[i]-1
min_d_list = [10**27 for i in range(N)]
min_d_list[vi] = 0
prev_list = [-1 for i in range(N)]
q = []
for i in range(N):
heapq.heappush(q,[min_d_list[i],i])
while len(q)>0:
d,v = heapq.heappop(q)
for e in e_list[v]:
v1,d1=e
if min_d_list[v1]>d+d1:
min_d_list[v1]=d+d1
prev_list[v1]=v
heapq.heappush(q,[d+d1,v1])
r_dis_list.append([min_d_list[r[i]-1] for i in range(len(r))])
import itertools
min_ans = 10**27
for i in itertools.permutations(list(range(len(r)))):
ans = 0
for j in range(len(r)-1):
ans+=r_dis_list[i[j+1]][i[j]]
min_ans=min(ans,min_ans)
print(min_ans)
|
N,M,R = list(map(int,input().split()))
r = list(map(int,input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
a,b,c = list(map(int,input().split()))
e_list[a-1].append((b-1,c))
e_list[b-1].append((a-1,c))
#dijkstra
#you need to prepare e_list = [[orient,dist]]
import heapq
def dijkstra(vi):
min_d_list = [10**27 for i in range(N)]
min_d_list[vi] = 0
q = []
for i in range(N):
heapq.heappush(q,[min_d_list[i],i])
while len(q)>0:
d,v = heapq.heappop(q)
for e in e_list[v]:
v1,d1=e
if min_d_list[v1]>d+d1:
min_d_list[v1]=d+d1
heapq.heappush(q,[d+d1,v1])
return min_d_list
D = [[0]*R for i in range(R)]
for i in range(R):
min_d_list = dijkstra(r[i]-1)
for j in range(R):
D[i][j] = min_d_list[r[j]-1]
import itertools
min_ans=10**27
for v in itertools.permutations(list(range(R))):
ans = 0
for i in range(1,R):
ans+=D[v[i]][v[i-1]]
min_ans=min(min_ans,ans)
print(min_ans)
| 45 | 51 | 1,123 | 1,092 |
N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
a, b, c = list(map(int, input().split()))
a = a - 1
b = b - 1
e_list[a].append([b, c])
e_list[b].append([a, c])
# dijkstra
# you need to prepare e_list = [[orient,dist]]
import heapq
r_dis_list = []
for i in range(len(r)):
vi = r[i] - 1
min_d_list = [10**27 for i in range(N)]
min_d_list[vi] = 0
prev_list = [-1 for i in range(N)]
q = []
for i in range(N):
heapq.heappush(q, [min_d_list[i], i])
while len(q) > 0:
d, v = heapq.heappop(q)
for e in e_list[v]:
v1, d1 = e
if min_d_list[v1] > d + d1:
min_d_list[v1] = d + d1
prev_list[v1] = v
heapq.heappush(q, [d + d1, v1])
r_dis_list.append([min_d_list[r[i] - 1] for i in range(len(r))])
import itertools
min_ans = 10**27
for i in itertools.permutations(list(range(len(r)))):
ans = 0
for j in range(len(r) - 1):
ans += r_dis_list[i[j + 1]][i[j]]
min_ans = min(ans, min_ans)
print(min_ans)
|
N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
a, b, c = list(map(int, input().split()))
e_list[a - 1].append((b - 1, c))
e_list[b - 1].append((a - 1, c))
# dijkstra
# you need to prepare e_list = [[orient,dist]]
import heapq
def dijkstra(vi):
min_d_list = [10**27 for i in range(N)]
min_d_list[vi] = 0
q = []
for i in range(N):
heapq.heappush(q, [min_d_list[i], i])
while len(q) > 0:
d, v = heapq.heappop(q)
for e in e_list[v]:
v1, d1 = e
if min_d_list[v1] > d + d1:
min_d_list[v1] = d + d1
heapq.heappush(q, [d + d1, v1])
return min_d_list
D = [[0] * R for i in range(R)]
for i in range(R):
min_d_list = dijkstra(r[i] - 1)
for j in range(R):
D[i][j] = min_d_list[r[j] - 1]
import itertools
min_ans = 10**27
for v in itertools.permutations(list(range(R))):
ans = 0
for i in range(1, R):
ans += D[v[i]][v[i - 1]]
min_ans = min(min_ans, ans)
print(min_ans)
| false | 11.764706 |
[
"- a = a - 1",
"- b = b - 1",
"- e_list[a].append([b, c])",
"- e_list[b].append([a, c])",
"+ e_list[a - 1].append((b - 1, c))",
"+ e_list[b - 1].append((a - 1, c))",
"-r_dis_list = []",
"-for i in range(len(r)):",
"- vi = r[i] - 1",
"+",
"+def dijkstra(vi):",
"- prev_list = [-1 for i in range(N)]",
"- prev_list[v1] = v",
"- r_dis_list.append([min_d_list[r[i] - 1] for i in range(len(r))])",
"+ return min_d_list",
"+",
"+",
"+D = [[0] * R for i in range(R)]",
"+for i in range(R):",
"+ min_d_list = dijkstra(r[i] - 1)",
"+ for j in range(R):",
"+ D[i][j] = min_d_list[r[j] - 1]",
"-for i in itertools.permutations(list(range(len(r)))):",
"+for v in itertools.permutations(list(range(R))):",
"- for j in range(len(r) - 1):",
"- ans += r_dis_list[i[j + 1]][i[j]]",
"- min_ans = min(ans, min_ans)",
"+ for i in range(1, R):",
"+ ans += D[v[i]][v[i - 1]]",
"+ min_ans = min(min_ans, ans)"
] | false | 0.040755 | 0.038978 | 1.045587 |
[
"s064928904",
"s129027357"
] |
u279955105
|
p02397
|
python
|
s434025940
|
s422133633
| 80 | 50 | 7,628 | 7,660 |
Accepted
|
Accepted
| 37.5 |
while True:
a,b = list(map(int, input().split()))
if (a == 0) and (b == 0):
break
elif (a < b):
print((str(a) + " " + str(b)))
else :
print((str(b) + " " + str(a)))
|
while True:
a,b = list(map(int, input().split()))
if (a == 0 and b == 0):
break
else:
if (a < b):
print((str(a) + " " + str(b)))
else :
print((str(b) +" "+ str(a)))
| 8 | 12 | 177 | 191 |
while True:
a, b = list(map(int, input().split()))
if (a == 0) and (b == 0):
break
elif a < b:
print((str(a) + " " + str(b)))
else:
print((str(b) + " " + str(a)))
|
while True:
a, b = list(map(int, input().split()))
if a == 0 and b == 0:
break
else:
if a < b:
print((str(a) + " " + str(b)))
else:
print((str(b) + " " + str(a)))
| false | 33.333333 |
[
"- if (a == 0) and (b == 0):",
"+ if a == 0 and b == 0:",
"- elif a < b:",
"- print((str(a) + \" \" + str(b)))",
"- print((str(b) + \" \" + str(a)))",
"+ if a < b:",
"+ print((str(a) + \" \" + str(b)))",
"+ else:",
"+ print((str(b) + \" \" + str(a)))"
] | false | 0.043832 | 0.068086 | 0.643773 |
[
"s434025940",
"s422133633"
] |
u670180528
|
p03830
|
python
|
s132274343
|
s761506447
| 25 | 19 | 3,060 | 2,940 |
Accepted
|
Accepted
| 24 |
n=int(eval(input()));a=1;r=range
for x in[i for i in r(2,n+1)if all(i%j for j in r(2,i))]:a*=sum(n//x**i for i in r(1,11))+1
print((a%(10**9+7)))
|
n=int(eval(input()));a=1;r=range
for x in[i for i in r(2,n+1)if all(i%j for j in r(2,int(i**.5)+1))]:a*=sum(n//x**i for i in r(1,11))+1;a%=10**9+7
print(a)
| 3 | 3 | 139 | 151 |
n = int(eval(input()))
a = 1
r = range
for x in [i for i in r(2, n + 1) if all(i % j for j in r(2, i))]:
a *= sum(n // x**i for i in r(1, 11)) + 1
print((a % (10**9 + 7)))
|
n = int(eval(input()))
a = 1
r = range
for x in [i for i in r(2, n + 1) if all(i % j for j in r(2, int(i**0.5) + 1))]:
a *= sum(n // x**i for i in r(1, 11)) + 1
a %= 10**9 + 7
print(a)
| false | 0 |
[
"-for x in [i for i in r(2, n + 1) if all(i % j for j in r(2, i))]:",
"+for x in [i for i in r(2, n + 1) if all(i % j for j in r(2, int(i**0.5) + 1))]:",
"-print((a % (10**9 + 7)))",
"+ a %= 10**9 + 7",
"+print(a)"
] | false | 0.045508 | 0.045765 | 0.994379 |
[
"s132274343",
"s761506447"
] |
u284854859
|
p03765
|
python
|
s371310171
|
s753493054
| 635 | 559 | 26,052 | 27,840 |
Accepted
|
Accepted
| 11.97 |
import sys
input = sys.stdin.readline
s = list(eval(input()))
t = list(eval(input()))
snum = [(0,0)] #snum[j]-snum[i-1]:i-j文字目に含まれる(A,B)の数
for i in range(len(s)):
if s[i] == 'A':
snum.append((snum[-1][0]+1,snum[-1][1]))
else:
snum.append((snum[-1][0],snum[-1][1]+1))
tnum = [(0,0)]
for i in range(len(t)):
if t[i] == 'A':
tnum.append((tnum[-1][0]+1,tnum[-1][1]))
else:
tnum.append((tnum[-1][0],tnum[-1][1]+1))
q = int(eval(input()))
for i in range(q):
a,b,c,d = list(map(int,input().split()))
sa = snum[b][0]-snum[a-1][0]
sb = snum[b][1]-snum[a-1][1]
ta = tnum[d][0]-tnum[c-1][0]
tb = tnum[d][1]-tnum[c-1][1]
#全てbにする
b1 = sb+sa*2
b1 += max(tb-b1,0)//3*3+3
a1 = (b1-tb)*2
if abs(a1-ta)%3==0:
print('YES')
continue
#全てaにする
a2 = sa+sb*2
a2 += max(ta-a2,0)//3*3+3
b2 = (a2-ta)*2
if abs(b2-tb)%3==0:
print('YES')
continue
print('NO')
|
import sys
input = sys.stdin.readline
s = list(eval(input()))
t = list(eval(input()))
snum = [(0,0)] #snum[j]-snum[i-1]:i-j文字目に含まれる(A,B)の数
for i in range(len(s)):
if s[i] == 'A':
snum.append((snum[-1][0]+1,snum[-1][1]))
else:
snum.append((snum[-1][0],snum[-1][1]+1))
tnum = [(0,0)]
for i in range(len(t)):
if t[i] == 'A':
tnum.append((tnum[-1][0]+1,tnum[-1][1]))
else:
tnum.append((tnum[-1][0],tnum[-1][1]+1))
q = int(eval(input()))
for i in range(q):
a,b,c,d = list(map(int,input().split()))
sa = snum[b][0]-snum[a-1][0]
sb = snum[b][1]-snum[a-1][1]
ta = tnum[d][0]-tnum[c-1][0]
tb = tnum[d][1]-tnum[c-1][1]
#全てbにする
b1 = sb+sa*2
b2 = tb+ta*2
if abs(b2-b1)%3==0:
print('YES')
continue
#全てaにする
a1 = sa+sb*2
a2 = ta+tb*2
if abs(a2-a1)%3==0:
print('YES')
continue
print('NO')
| 44 | 42 | 1,010 | 944 |
import sys
input = sys.stdin.readline
s = list(eval(input()))
t = list(eval(input()))
snum = [(0, 0)] # snum[j]-snum[i-1]:i-j文字目に含まれる(A,B)の数
for i in range(len(s)):
if s[i] == "A":
snum.append((snum[-1][0] + 1, snum[-1][1]))
else:
snum.append((snum[-1][0], snum[-1][1] + 1))
tnum = [(0, 0)]
for i in range(len(t)):
if t[i] == "A":
tnum.append((tnum[-1][0] + 1, tnum[-1][1]))
else:
tnum.append((tnum[-1][0], tnum[-1][1] + 1))
q = int(eval(input()))
for i in range(q):
a, b, c, d = list(map(int, input().split()))
sa = snum[b][0] - snum[a - 1][0]
sb = snum[b][1] - snum[a - 1][1]
ta = tnum[d][0] - tnum[c - 1][0]
tb = tnum[d][1] - tnum[c - 1][1]
# 全てbにする
b1 = sb + sa * 2
b1 += max(tb - b1, 0) // 3 * 3 + 3
a1 = (b1 - tb) * 2
if abs(a1 - ta) % 3 == 0:
print("YES")
continue
# 全てaにする
a2 = sa + sb * 2
a2 += max(ta - a2, 0) // 3 * 3 + 3
b2 = (a2 - ta) * 2
if abs(b2 - tb) % 3 == 0:
print("YES")
continue
print("NO")
|
import sys
input = sys.stdin.readline
s = list(eval(input()))
t = list(eval(input()))
snum = [(0, 0)] # snum[j]-snum[i-1]:i-j文字目に含まれる(A,B)の数
for i in range(len(s)):
if s[i] == "A":
snum.append((snum[-1][0] + 1, snum[-1][1]))
else:
snum.append((snum[-1][0], snum[-1][1] + 1))
tnum = [(0, 0)]
for i in range(len(t)):
if t[i] == "A":
tnum.append((tnum[-1][0] + 1, tnum[-1][1]))
else:
tnum.append((tnum[-1][0], tnum[-1][1] + 1))
q = int(eval(input()))
for i in range(q):
a, b, c, d = list(map(int, input().split()))
sa = snum[b][0] - snum[a - 1][0]
sb = snum[b][1] - snum[a - 1][1]
ta = tnum[d][0] - tnum[c - 1][0]
tb = tnum[d][1] - tnum[c - 1][1]
# 全てbにする
b1 = sb + sa * 2
b2 = tb + ta * 2
if abs(b2 - b1) % 3 == 0:
print("YES")
continue
# 全てaにする
a1 = sa + sb * 2
a2 = ta + tb * 2
if abs(a2 - a1) % 3 == 0:
print("YES")
continue
print("NO")
| false | 4.545455 |
[
"- b1 += max(tb - b1, 0) // 3 * 3 + 3",
"- a1 = (b1 - tb) * 2",
"- if abs(a1 - ta) % 3 == 0:",
"+ b2 = tb + ta * 2",
"+ if abs(b2 - b1) % 3 == 0:",
"- a2 = sa + sb * 2",
"- a2 += max(ta - a2, 0) // 3 * 3 + 3",
"- b2 = (a2 - ta) * 2",
"- if abs(b2 - tb) % 3 == 0:",
"+ a1 = sa + sb * 2",
"+ a2 = ta + tb * 2",
"+ if abs(a2 - a1) % 3 == 0:"
] | false | 0.037156 | 0.03719 | 0.999078 |
[
"s371310171",
"s753493054"
] |
u078932560
|
p03162
|
python
|
s663596561
|
s717007222
| 600 | 429 | 22,900 | 3,060 |
Accepted
|
Accepted
| 28.5 |
N = int(eval(input()))
dp = [[0] * 3 for _ in range(N)]
dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split()))
for i in range(1,N):
abc = list(map(int, input().split()))
for j,k,l in ((0,1,2), (1,0,2), (2, 0, 1)):
dp[i][j] = abc[j] + max(dp[i-1][k], dp[i-1][l])
print((max(dp[N-1])))
|
N = int(eval(input()))
x, y, z = list(map(int, input().split()))
for _ in range(N-1):
a, b, c = list(map(int, input().split()))
x, y, z = a + max(y, z), b + max(x, z), c + max(x, y)
print((max(x,y,z)))
| 10 | 8 | 302 | 206 |
N = int(eval(input()))
dp = [[0] * 3 for _ in range(N)]
dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split()))
for i in range(1, N):
abc = list(map(int, input().split()))
for j, k, l in ((0, 1, 2), (1, 0, 2), (2, 0, 1)):
dp[i][j] = abc[j] + max(dp[i - 1][k], dp[i - 1][l])
print((max(dp[N - 1])))
|
N = int(eval(input()))
x, y, z = list(map(int, input().split()))
for _ in range(N - 1):
a, b, c = list(map(int, input().split()))
x, y, z = a + max(y, z), b + max(x, z), c + max(x, y)
print((max(x, y, z)))
| false | 20 |
[
"-dp = [[0] * 3 for _ in range(N)]",
"-dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split()))",
"-for i in range(1, N):",
"- abc = list(map(int, input().split()))",
"- for j, k, l in ((0, 1, 2), (1, 0, 2), (2, 0, 1)):",
"- dp[i][j] = abc[j] + max(dp[i - 1][k], dp[i - 1][l])",
"-print((max(dp[N - 1])))",
"+x, y, z = list(map(int, input().split()))",
"+for _ in range(N - 1):",
"+ a, b, c = list(map(int, input().split()))",
"+ x, y, z = a + max(y, z), b + max(x, z), c + max(x, y)",
"+print((max(x, y, z)))"
] | false | 0.036652 | 0.036401 | 1.006905 |
[
"s663596561",
"s717007222"
] |
u961945062
|
p02994
|
python
|
s350049653
|
s281772026
| 31 | 28 | 9,084 | 9,072 |
Accepted
|
Accepted
| 9.68 |
N, L = list(map(int, input().split()))
ans = 0
min = L
for i in range(1, N+1):
a = L+i-1
ans += a
if abs(a) < abs(min):
min = a
ans -= min
print(ans)
|
N, L = list(map(int, input().split()))
v = [L+i for i in range(N)]
ans = sum(v) - min(v, key=abs)
print(ans)
| 12 | 4 | 176 | 106 |
N, L = list(map(int, input().split()))
ans = 0
min = L
for i in range(1, N + 1):
a = L + i - 1
ans += a
if abs(a) < abs(min):
min = a
ans -= min
print(ans)
|
N, L = list(map(int, input().split()))
v = [L + i for i in range(N)]
ans = sum(v) - min(v, key=abs)
print(ans)
| false | 66.666667 |
[
"-ans = 0",
"-min = L",
"-for i in range(1, N + 1):",
"- a = L + i - 1",
"- ans += a",
"- if abs(a) < abs(min):",
"- min = a",
"-ans -= min",
"+v = [L + i for i in range(N)]",
"+ans = sum(v) - min(v, key=abs)"
] | false | 0.049306 | 0.046989 | 1.049315 |
[
"s350049653",
"s281772026"
] |
u186838327
|
p03715
|
python
|
s578025808
|
s740211253
| 263 | 113 | 43,100 | 73,788 |
Accepted
|
Accepted
| 57.03 |
h, w = list(map(int, input().split()))
if h%3 == 0 or w%3 == 0:
print((0))
exit()
#print(h, w)
min_ = float('inf')
for i in range(1, h):
s1 = w*i
s2 = (h-i)*(w//2)
s3 = (h-i)*(w-w//2)
d = max([s1, s2, s3]) - min([s1, s2, s3])
#print(i, s1, s2, s3, d)
min_ = min(min_, d)
s2 = ((h-i)//2)*w
s3 = ((h-i) - (h-i)//2)*w
d = max([s1, s2, s3]) - min([s1, s2, s3])
#print(i, s1, s2, s3, d)
min_ = min(min_, d)
#print('-')
for i in range(1, w):
s1 = h*i
s2 = (w-i)*(h//2)
s3 = (w-i)*(h-h//2)
d = max([s1, s2, s3]) - min([s1, s2, s3])
#print(i, s1, s2, s3, d)
min_ = min(min_, d)
s2 = ((w-i)//2)*h
s3 = ((w-i) - (w-i)//2)*h
d = max([s1, s2, s3]) - min([s1, s2, s3])
#print(i, s1, s2, s3, d)
min_ = min(min_, d)
print(min_)
|
h, w = list(map(int, input().split()))
ans = 10**18
for i in range(1, h):
S1 = i*w
# tate
if h-i >= 2:
p = (h-i)//2
q = h-(h-i)//2-i
S2 = p*w
S3 = q*w
M = max([S1, S2, S3])
m = min([S1, S2, S3])
ans = min(ans, M-m)
#if i == 1:
#print(S1, S2, S3)
# yoko
S2 = (h-i)*(w//2)
S3 = (h-i)*(w-w//2)
M = max([S1, S2, S3])
m = min([S1, S2, S3])
ans = min(ans, M-m)
for i in range(1, w):
S1 = h*i
# yoko
if w-i >= 2:
p = (w-i)//2
q = w-(w-i)//2-i
S2 = h*p
S3 = h*q
M = max([S1, S2, S3])
m = min([S1, S2, S3])
ans = min(ans, M-m)
# tate
S2 = (h//2)*(w-i)
S3 = (h-h//2)*(w-i)
M = max([S1, S2, S3])
m = min([S1, S2, S3])
ans = min(ans, M-m)
print(ans)
| 39 | 40 | 845 | 876 |
h, w = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
print((0))
exit()
# print(h, w)
min_ = float("inf")
for i in range(1, h):
s1 = w * i
s2 = (h - i) * (w // 2)
s3 = (h - i) * (w - w // 2)
d = max([s1, s2, s3]) - min([s1, s2, s3])
# print(i, s1, s2, s3, d)
min_ = min(min_, d)
s2 = ((h - i) // 2) * w
s3 = ((h - i) - (h - i) // 2) * w
d = max([s1, s2, s3]) - min([s1, s2, s3])
# print(i, s1, s2, s3, d)
min_ = min(min_, d)
# print('-')
for i in range(1, w):
s1 = h * i
s2 = (w - i) * (h // 2)
s3 = (w - i) * (h - h // 2)
d = max([s1, s2, s3]) - min([s1, s2, s3])
# print(i, s1, s2, s3, d)
min_ = min(min_, d)
s2 = ((w - i) // 2) * h
s3 = ((w - i) - (w - i) // 2) * h
d = max([s1, s2, s3]) - min([s1, s2, s3])
# print(i, s1, s2, s3, d)
min_ = min(min_, d)
print(min_)
|
h, w = list(map(int, input().split()))
ans = 10**18
for i in range(1, h):
S1 = i * w
# tate
if h - i >= 2:
p = (h - i) // 2
q = h - (h - i) // 2 - i
S2 = p * w
S3 = q * w
M = max([S1, S2, S3])
m = min([S1, S2, S3])
ans = min(ans, M - m)
# if i == 1:
# print(S1, S2, S3)
# yoko
S2 = (h - i) * (w // 2)
S3 = (h - i) * (w - w // 2)
M = max([S1, S2, S3])
m = min([S1, S2, S3])
ans = min(ans, M - m)
for i in range(1, w):
S1 = h * i
# yoko
if w - i >= 2:
p = (w - i) // 2
q = w - (w - i) // 2 - i
S2 = h * p
S3 = h * q
M = max([S1, S2, S3])
m = min([S1, S2, S3])
ans = min(ans, M - m)
# tate
S2 = (h // 2) * (w - i)
S3 = (h - h // 2) * (w - i)
M = max([S1, S2, S3])
m = min([S1, S2, S3])
ans = min(ans, M - m)
print(ans)
| false | 2.5 |
[
"-if h % 3 == 0 or w % 3 == 0:",
"- print((0))",
"- exit()",
"-# print(h, w)",
"-min_ = float(\"inf\")",
"+ans = 10**18",
"- s1 = w * i",
"- s2 = (h - i) * (w // 2)",
"- s3 = (h - i) * (w - w // 2)",
"- d = max([s1, s2, s3]) - min([s1, s2, s3])",
"- # print(i, s1, s2, s3, d)",
"- min_ = min(min_, d)",
"- s2 = ((h - i) // 2) * w",
"- s3 = ((h - i) - (h - i) // 2) * w",
"- d = max([s1, s2, s3]) - min([s1, s2, s3])",
"- # print(i, s1, s2, s3, d)",
"- min_ = min(min_, d)",
"-# print('-')",
"+ S1 = i * w",
"+ # tate",
"+ if h - i >= 2:",
"+ p = (h - i) // 2",
"+ q = h - (h - i) // 2 - i",
"+ S2 = p * w",
"+ S3 = q * w",
"+ M = max([S1, S2, S3])",
"+ m = min([S1, S2, S3])",
"+ ans = min(ans, M - m)",
"+ # if i == 1:",
"+ # print(S1, S2, S3)",
"+ # yoko",
"+ S2 = (h - i) * (w // 2)",
"+ S3 = (h - i) * (w - w // 2)",
"+ M = max([S1, S2, S3])",
"+ m = min([S1, S2, S3])",
"+ ans = min(ans, M - m)",
"- s1 = h * i",
"- s2 = (w - i) * (h // 2)",
"- s3 = (w - i) * (h - h // 2)",
"- d = max([s1, s2, s3]) - min([s1, s2, s3])",
"- # print(i, s1, s2, s3, d)",
"- min_ = min(min_, d)",
"- s2 = ((w - i) // 2) * h",
"- s3 = ((w - i) - (w - i) // 2) * h",
"- d = max([s1, s2, s3]) - min([s1, s2, s3])",
"- # print(i, s1, s2, s3, d)",
"- min_ = min(min_, d)",
"-print(min_)",
"+ S1 = h * i",
"+ # yoko",
"+ if w - i >= 2:",
"+ p = (w - i) // 2",
"+ q = w - (w - i) // 2 - i",
"+ S2 = h * p",
"+ S3 = h * q",
"+ M = max([S1, S2, S3])",
"+ m = min([S1, S2, S3])",
"+ ans = min(ans, M - m)",
"+ # tate",
"+ S2 = (h // 2) * (w - i)",
"+ S3 = (h - h // 2) * (w - i)",
"+ M = max([S1, S2, S3])",
"+ m = min([S1, S2, S3])",
"+ ans = min(ans, M - m)",
"+print(ans)"
] | false | 0.088093 | 0.10191 | 0.864414 |
[
"s578025808",
"s740211253"
] |
u062147869
|
p03223
|
python
|
s092601875
|
s819260723
| 689 | 521 | 59,224 | 52,952 |
Accepted
|
Accepted
| 24.38 |
from collections import deque
N=int(eval(input()))
A=[]
for i in range(N):
s=int(eval(input()))
A.append(s)
A.sort()
H=deque()
H.append(A[0])
s=1
t=N-1
i=0
while t-s!=-1:
x=A[s]
y=A[t]
a=abs(H[0]-x)
b=abs(H[-1]-x)
c=abs(H[0]-y)
d=abs(H[-1]-y)
e=max(a,b,c,d)
if a==e:
H.appendleft(x)
s+=1
elif b==e:
H.append(x)
s+=1
elif c==e:
H.appendleft(y)
t-=1
else:
H.append(y)
t-=1
ans=0
for i in range(N-1):
ans+=abs(H[i+1]-H[i])
print(ans)
|
import sys
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
B=sorted(A)
if N%2==0:
C=B[:(N//2)]
D=B[(N//2):]
print((2*sum(D)-2*sum(C)+C[-1]-D[0]))
sys.exit()
C=B[:(N//2)]
D=B[((N//2)+1):]
s=B[(N//2)]
print((max(2*sum(D)-2*sum(C)+C[-1]-s,2*sum(D)-2*sum(C)+s-D[0])))
| 36 | 13 | 573 | 289 |
from collections import deque
N = int(eval(input()))
A = []
for i in range(N):
s = int(eval(input()))
A.append(s)
A.sort()
H = deque()
H.append(A[0])
s = 1
t = N - 1
i = 0
while t - s != -1:
x = A[s]
y = A[t]
a = abs(H[0] - x)
b = abs(H[-1] - x)
c = abs(H[0] - y)
d = abs(H[-1] - y)
e = max(a, b, c, d)
if a == e:
H.appendleft(x)
s += 1
elif b == e:
H.append(x)
s += 1
elif c == e:
H.appendleft(y)
t -= 1
else:
H.append(y)
t -= 1
ans = 0
for i in range(N - 1):
ans += abs(H[i + 1] - H[i])
print(ans)
|
import sys
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = sorted(A)
if N % 2 == 0:
C = B[: (N // 2)]
D = B[(N // 2) :]
print((2 * sum(D) - 2 * sum(C) + C[-1] - D[0]))
sys.exit()
C = B[: (N // 2)]
D = B[((N // 2) + 1) :]
s = B[(N // 2)]
print((max(2 * sum(D) - 2 * sum(C) + C[-1] - s, 2 * sum(D) - 2 * sum(C) + s - D[0])))
| false | 63.888889 |
[
"-from collections import deque",
"+import sys",
"-A = []",
"-for i in range(N):",
"- s = int(eval(input()))",
"- A.append(s)",
"-A.sort()",
"-H = deque()",
"-H.append(A[0])",
"-s = 1",
"-t = N - 1",
"-i = 0",
"-while t - s != -1:",
"- x = A[s]",
"- y = A[t]",
"- a = abs(H[0] - x)",
"- b = abs(H[-1] - x)",
"- c = abs(H[0] - y)",
"- d = abs(H[-1] - y)",
"- e = max(a, b, c, d)",
"- if a == e:",
"- H.appendleft(x)",
"- s += 1",
"- elif b == e:",
"- H.append(x)",
"- s += 1",
"- elif c == e:",
"- H.appendleft(y)",
"- t -= 1",
"- else:",
"- H.append(y)",
"- t -= 1",
"-ans = 0",
"-for i in range(N - 1):",
"- ans += abs(H[i + 1] - H[i])",
"-print(ans)",
"+A = [int(eval(input())) for i in range(N)]",
"+B = sorted(A)",
"+if N % 2 == 0:",
"+ C = B[: (N // 2)]",
"+ D = B[(N // 2) :]",
"+ print((2 * sum(D) - 2 * sum(C) + C[-1] - D[0]))",
"+ sys.exit()",
"+C = B[: (N // 2)]",
"+D = B[((N // 2) + 1) :]",
"+s = B[(N // 2)]",
"+print((max(2 * sum(D) - 2 * sum(C) + C[-1] - s, 2 * sum(D) - 2 * sum(C) + s - D[0])))"
] | false | 0.03941 | 0.041219 | 0.956105 |
[
"s092601875",
"s819260723"
] |
u755116850
|
p03739
|
python
|
s746234668
|
s779724462
| 110 | 91 | 20,440 | 19,980 |
Accepted
|
Accepted
| 17.27 |
n = int(eval(input()))
a = list(map(int, input().split(" ")))
res1 = 0
sum = 0
# sei, hu, sei, hu....
# guu, ki, guu, ki
for i in range(n):
sum += a[i]
if sum <= 0 and i%2 == 0:
res1 += abs(sum) + 1
sum = 1
elif sum >= 0 and i%2 == 1:
res1 += abs(sum) + 1
sum = -1
# hutuunitoku
res2 = 0
sum = 0
# hu, sei, hu, sei....
# guu, ki, guu, ki
for i in range(n):
sum += a[i]
if sum <= 0 and i%2 == 1:
res2 += abs(sum) + 1
sum = 1
elif sum >= 0 and i%2 == 0:
res2 += abs(sum) + 1
sum = -1
# hutuunitoku
print((min(res1, res2)))
|
n = int(eval(input()))
a = list(map(int, input().split(" ")))
def solve(s1, s2):
"if start == true, assume the first of the sum is positive."
res = 0
sum = 0
for i in range(n):
sum += a[i]
if sum <= 0 and i % 2 == s1:
res += abs(sum) + 1
sum = 1
elif sum >= 0 and i % 2 == s2:
res += abs(sum) + 1
sum = -1
return res
print((min(solve(0, 1), solve(1, 0))))
| 36 | 21 | 651 | 465 |
n = int(eval(input()))
a = list(map(int, input().split(" ")))
res1 = 0
sum = 0
# sei, hu, sei, hu....
# guu, ki, guu, ki
for i in range(n):
sum += a[i]
if sum <= 0 and i % 2 == 0:
res1 += abs(sum) + 1
sum = 1
elif sum >= 0 and i % 2 == 1:
res1 += abs(sum) + 1
sum = -1
# hutuunitoku
res2 = 0
sum = 0
# hu, sei, hu, sei....
# guu, ki, guu, ki
for i in range(n):
sum += a[i]
if sum <= 0 and i % 2 == 1:
res2 += abs(sum) + 1
sum = 1
elif sum >= 0 and i % 2 == 0:
res2 += abs(sum) + 1
sum = -1
# hutuunitoku
print((min(res1, res2)))
|
n = int(eval(input()))
a = list(map(int, input().split(" ")))
def solve(s1, s2):
"if start == true, assume the first of the sum is positive."
res = 0
sum = 0
for i in range(n):
sum += a[i]
if sum <= 0 and i % 2 == s1:
res += abs(sum) + 1
sum = 1
elif sum >= 0 and i % 2 == s2:
res += abs(sum) + 1
sum = -1
return res
print((min(solve(0, 1), solve(1, 0))))
| false | 41.666667 |
[
"-res1 = 0",
"-sum = 0",
"-# sei, hu, sei, hu....",
"-# guu, ki, guu, ki",
"-for i in range(n):",
"- sum += a[i]",
"- if sum <= 0 and i % 2 == 0:",
"- res1 += abs(sum) + 1",
"- sum = 1",
"- elif sum >= 0 and i % 2 == 1:",
"- res1 += abs(sum) + 1",
"- sum = -1",
"- # hutuunitoku",
"-res2 = 0",
"-sum = 0",
"-# hu, sei, hu, sei....",
"-# guu, ki, guu, ki",
"-for i in range(n):",
"- sum += a[i]",
"- if sum <= 0 and i % 2 == 1:",
"- res2 += abs(sum) + 1",
"- sum = 1",
"- elif sum >= 0 and i % 2 == 0:",
"- res2 += abs(sum) + 1",
"- sum = -1",
"- # hutuunitoku",
"-print((min(res1, res2)))",
"+",
"+",
"+def solve(s1, s2):",
"+ \"if start == true, assume the first of the sum is positive.\"",
"+ res = 0",
"+ sum = 0",
"+ for i in range(n):",
"+ sum += a[i]",
"+ if sum <= 0 and i % 2 == s1:",
"+ res += abs(sum) + 1",
"+ sum = 1",
"+ elif sum >= 0 and i % 2 == s2:",
"+ res += abs(sum) + 1",
"+ sum = -1",
"+ return res",
"+",
"+",
"+print((min(solve(0, 1), solve(1, 0))))"
] | false | 0.056615 | 0.078978 | 0.716836 |
[
"s746234668",
"s779724462"
] |
u588341295
|
p02868
|
python
|
s756646139
|
s279482592
| 1,010 | 530 | 83,036 | 68,000 |
Accepted
|
Accepted
| 47.52 |
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353
class SegTree:
"""
セグメント木
1.update: i番目の値をxに更新する
2.query: 区間[l, r)の値を得る
"""
def __init__(self, n, func, intv, A=[]):
"""
:param n: 要素数(0-indexed)
:param func: 値の操作に使う関数(min, max, add, gcdなど)
:param intv: 要素の初期値(単位元)
:param A: 初期化に使うリスト(オプション)
"""
self.n = n
self.func = func
self.intv = intv
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [self.intv] * (n2 << 1)
# 初期化の値が決まっている場合
if A:
# 1段目(最下段)の初期化
for i in range(n):
self.tree[n2+i] = A[i]
# 2段目以降の初期化
for i in range(n2-1, -1, -1):
self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 1:
self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
i >>= 1
def query(self, a, b):
"""
[a, b)の値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
l = a + self.n2
r = b + self.n2
s = self.intv
while l < r:
if r & 1:
r -= 1
s = self.func(s, self.tree[r])
if l & 1:
s = self.func(s, self.tree[l])
l += 1
l >>= 1
r >>= 1
return s
def get(self, i):
""" 一点取得 """
return self.tree[i+self.n2]
def all(self):
""" 全区間[0, n)の取得 """
return self.tree[1]
N, M = MAP()
LRC = []
for i in range(M):
l, r, c = MAP()
l -= 1
r -= 1
LRC.append((l, r, c))
LRC.sort()
st = SegTree(N, min, INF)
st.update(0, 0)
for l, r, c in LRC:
mn = st.query(l, r+1)
st.update(r, min(st.get(r), mn+c))
ans = st.get(N-1)
if ans != INF:
print((st.get(N-1)))
else:
print((-1))
|
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353
def dijkstra(N: int, nodes: list, src: int) -> list:
""" ダイクストラ高速化版(頂点数, 隣接リスト(0-indexed), 始点) """
from heapq import heappush, heappop
# 頂点[ある始点からの最短距離]
res = [INF] * N
# スタート位置
que = [src]
res[src] = 0
# キューが空になるまで
while len(que) != 0:
# 距離*N + 現在のノード
cur = heappop(que)
# 距離とノードに分ける
dist = cur // N
cur %= N
# 出発ノードcurの到着ノードでループ
for nxt, cost in nodes[cur]:
# 今回の経路のが短い時
if dist + cost < res[nxt]:
res[nxt] = dist + cost
# 距離*N+ノード番号 の形でキューに詰める
heappush(que, (dist+cost)*N+nxt)
# ノードsrcからの最短距離リストを返却
return res
N, M = MAP()
nodes = [[] for i in range(N)]
# 1つ手前の頂点に戻るコスト0の辺を張る
for i in range(N-1):
nodes[i+1].append((i, 0))
for i in range(M):
l, r, c = MAP()
l -= 1
r -= 1
# 一番遠くまで行く辺を張る
nodes[l].append((r, c))
res = dijkstra(N, nodes, 0)
if res[N-1] != INF:
print((res[N-1]))
else:
print((-1))
| 111 | 64 | 2,845 | 1,740 |
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 998244353
class SegTree:
"""
セグメント木
1.update: i番目の値をxに更新する
2.query: 区間[l, r)の値を得る
"""
def __init__(self, n, func, intv, A=[]):
"""
:param n: 要素数(0-indexed)
:param func: 値の操作に使う関数(min, max, add, gcdなど)
:param intv: 要素の初期値(単位元)
:param A: 初期化に使うリスト(オプション)
"""
self.n = n
self.func = func
self.intv = intv
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [self.intv] * (n2 << 1)
# 初期化の値が決まっている場合
if A:
# 1段目(最下段)の初期化
for i in range(n):
self.tree[n2 + i] = A[i]
# 2段目以降の初期化
for i in range(n2 - 1, -1, -1):
self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 1:
self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
i >>= 1
def query(self, a, b):
"""
[a, b)の値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
l = a + self.n2
r = b + self.n2
s = self.intv
while l < r:
if r & 1:
r -= 1
s = self.func(s, self.tree[r])
if l & 1:
s = self.func(s, self.tree[l])
l += 1
l >>= 1
r >>= 1
return s
def get(self, i):
"""一点取得"""
return self.tree[i + self.n2]
def all(self):
"""全区間[0, n)の取得"""
return self.tree[1]
N, M = MAP()
LRC = []
for i in range(M):
l, r, c = MAP()
l -= 1
r -= 1
LRC.append((l, r, c))
LRC.sort()
st = SegTree(N, min, INF)
st.update(0, 0)
for l, r, c in LRC:
mn = st.query(l, r + 1)
st.update(r, min(st.get(r), mn + c))
ans = st.get(N - 1)
if ans != INF:
print((st.get(N - 1)))
else:
print((-1))
|
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 998244353
def dijkstra(N: int, nodes: list, src: int) -> list:
"""ダイクストラ高速化版(頂点数, 隣接リスト(0-indexed), 始点)"""
from heapq import heappush, heappop
# 頂点[ある始点からの最短距離]
res = [INF] * N
# スタート位置
que = [src]
res[src] = 0
# キューが空になるまで
while len(que) != 0:
# 距離*N + 現在のノード
cur = heappop(que)
# 距離とノードに分ける
dist = cur // N
cur %= N
# 出発ノードcurの到着ノードでループ
for nxt, cost in nodes[cur]:
# 今回の経路のが短い時
if dist + cost < res[nxt]:
res[nxt] = dist + cost
# 距離*N+ノード番号 の形でキューに詰める
heappush(que, (dist + cost) * N + nxt)
# ノードsrcからの最短距離リストを返却
return res
N, M = MAP()
nodes = [[] for i in range(N)]
# 1つ手前の頂点に戻るコスト0の辺を張る
for i in range(N - 1):
nodes[i + 1].append((i, 0))
for i in range(M):
l, r, c = MAP()
l -= 1
r -= 1
# 一番遠くまで行く辺を張る
nodes[l].append((r, c))
res = dijkstra(N, nodes, 0)
if res[N - 1] != INF:
print((res[N - 1]))
else:
print((-1))
| false | 42.342342 |
[
"-class SegTree:",
"- \"\"\"",
"- セグメント木",
"- 1.update: i番目の値をxに更新する",
"- 2.query: 区間[l, r)の値を得る",
"- \"\"\"",
"+def dijkstra(N: int, nodes: list, src: int) -> list:",
"+ \"\"\"ダイクストラ高速化版(頂点数, 隣接リスト(0-indexed), 始点)\"\"\"",
"+ from heapq import heappush, heappop",
"- def __init__(self, n, func, intv, A=[]):",
"- \"\"\"",
"- :param n: 要素数(0-indexed)",
"- :param func: 値の操作に使う関数(min, max, add, gcdなど)",
"- :param intv: 要素の初期値(単位元)",
"- :param A: 初期化に使うリスト(オプション)",
"- \"\"\"",
"- self.n = n",
"- self.func = func",
"- self.intv = intv",
"- # nより大きい2の冪数",
"- n2 = 1",
"- while n2 < n:",
"- n2 <<= 1",
"- self.n2 = n2",
"- self.tree = [self.intv] * (n2 << 1)",
"- # 初期化の値が決まっている場合",
"- if A:",
"- # 1段目(最下段)の初期化",
"- for i in range(n):",
"- self.tree[n2 + i] = A[i]",
"- # 2段目以降の初期化",
"- for i in range(n2 - 1, -1, -1):",
"- self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])",
"-",
"- def update(self, i, x):",
"- \"\"\"",
"- i番目の値をxに更新",
"- :param i: index(0-indexed)",
"- :param x: update value",
"- \"\"\"",
"- i += self.n2",
"- self.tree[i] = x",
"- while i > 1:",
"- self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])",
"- i >>= 1",
"-",
"- def query(self, a, b):",
"- \"\"\"",
"- [a, b)の値を得る",
"- :param a: index(0-indexed)",
"- :param b: index(0-indexed)",
"- \"\"\"",
"- l = a + self.n2",
"- r = b + self.n2",
"- s = self.intv",
"- while l < r:",
"- if r & 1:",
"- r -= 1",
"- s = self.func(s, self.tree[r])",
"- if l & 1:",
"- s = self.func(s, self.tree[l])",
"- l += 1",
"- l >>= 1",
"- r >>= 1",
"- return s",
"-",
"- def get(self, i):",
"- \"\"\"一点取得\"\"\"",
"- return self.tree[i + self.n2]",
"-",
"- def all(self):",
"- \"\"\"全区間[0, n)の取得\"\"\"",
"- return self.tree[1]",
"+ # 頂点[ある始点からの最短距離]",
"+ res = [INF] * N",
"+ # スタート位置",
"+ que = [src]",
"+ res[src] = 0",
"+ # キューが空になるまで",
"+ while len(que) != 0:",
"+ # 距離*N + 現在のノード",
"+ cur = heappop(que)",
"+ # 距離とノードに分ける",
"+ dist = cur // N",
"+ cur %= N",
"+ # 出発ノードcurの到着ノードでループ",
"+ for nxt, cost in nodes[cur]:",
"+ # 今回の経路のが短い時",
"+ if dist + cost < res[nxt]:",
"+ res[nxt] = dist + cost",
"+ # 距離*N+ノード番号 の形でキューに詰める",
"+ heappush(que, (dist + cost) * N + nxt)",
"+ # ノードsrcからの最短距離リストを返却",
"+ return res",
"-LRC = []",
"+nodes = [[] for i in range(N)]",
"+# 1つ手前の頂点に戻るコスト0の辺を張る",
"+for i in range(N - 1):",
"+ nodes[i + 1].append((i, 0))",
"- LRC.append((l, r, c))",
"-LRC.sort()",
"-st = SegTree(N, min, INF)",
"-st.update(0, 0)",
"-for l, r, c in LRC:",
"- mn = st.query(l, r + 1)",
"- st.update(r, min(st.get(r), mn + c))",
"-ans = st.get(N - 1)",
"-if ans != INF:",
"- print((st.get(N - 1)))",
"+ # 一番遠くまで行く辺を張る",
"+ nodes[l].append((r, c))",
"+res = dijkstra(N, nodes, 0)",
"+if res[N - 1] != INF:",
"+ print((res[N - 1]))"
] | false | 0.045971 | 0.045852 | 1.002606 |
[
"s756646139",
"s279482592"
] |
u562935282
|
p03141
|
python
|
s246371542
|
s667868643
| 453 | 394 | 21,376 | 21,308 |
Accepted
|
Accepted
| 13.02 |
N = int(eval(input()))
e = [tuple(map(int, input().split())) for _ in range(N)]
e.sort(key=lambda x: x[0] + x[1], reverse=True)
ans = 0
for i in range(N):
if i % 2 == 0:
ans += e[i][0]
else:
ans -= e[i][1]
print(ans)
|
n = int(eval(input()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: sum(x), reverse=True)
s = sum(a for a, _ in ab)
s -= sum(sum(dish) for dish in ab[1::2])
print(s)
| 11 | 6 | 245 | 200 |
N = int(eval(input()))
e = [tuple(map(int, input().split())) for _ in range(N)]
e.sort(key=lambda x: x[0] + x[1], reverse=True)
ans = 0
for i in range(N):
if i % 2 == 0:
ans += e[i][0]
else:
ans -= e[i][1]
print(ans)
|
n = int(eval(input()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: sum(x), reverse=True)
s = sum(a for a, _ in ab)
s -= sum(sum(dish) for dish in ab[1::2])
print(s)
| false | 45.454545 |
[
"-N = int(eval(input()))",
"-e = [tuple(map(int, input().split())) for _ in range(N)]",
"-e.sort(key=lambda x: x[0] + x[1], reverse=True)",
"-ans = 0",
"-for i in range(N):",
"- if i % 2 == 0:",
"- ans += e[i][0]",
"- else:",
"- ans -= e[i][1]",
"-print(ans)",
"+n = int(eval(input()))",
"+ab = [tuple(map(int, input().split())) for _ in range(n)]",
"+ab.sort(key=lambda x: sum(x), reverse=True)",
"+s = sum(a for a, _ in ab)",
"+s -= sum(sum(dish) for dish in ab[1::2])",
"+print(s)"
] | false | 0.042186 | 0.040699 | 1.036531 |
[
"s246371542",
"s667868643"
] |
u854962015
|
p02820
|
python
|
s015063897
|
s226829930
| 162 | 70 | 10,580 | 9,968 |
Accepted
|
Accepted
| 56.79 |
N,K=list(map(int,input().split()))
R,S,P=list(map(int,input().split()))
L=eval(input())
T=[]
for i in range(N):
T.append(L[i])
for i in range(K,N):
if T[i]==T[i-K]:
T[i]="0"
T=str(T)
p=0
for i in T:
if i=="r":
p+=P
elif i=="s":
p+=R
elif i=="p":
p+=S
print(p)
|
N,K=list(map(int,input().split()))
R,S,P=list(map(int,input().split()))
L=eval(input())
T=[]
for i in range(N):
T.append(L[i])
for i in range(K,N):
if T[i]==T[i-K]:
T[i]="0"
p=0
for i in T:
if i=="r":
p+=P
elif i=="s":
p+=R
elif i=="p":
p+=S
print(p)
| 19 | 18 | 311 | 301 |
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
L = eval(input())
T = []
for i in range(N):
T.append(L[i])
for i in range(K, N):
if T[i] == T[i - K]:
T[i] = "0"
T = str(T)
p = 0
for i in T:
if i == "r":
p += P
elif i == "s":
p += R
elif i == "p":
p += S
print(p)
|
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
L = eval(input())
T = []
for i in range(N):
T.append(L[i])
for i in range(K, N):
if T[i] == T[i - K]:
T[i] = "0"
p = 0
for i in T:
if i == "r":
p += P
elif i == "s":
p += R
elif i == "p":
p += S
print(p)
| false | 5.263158 |
[
"-T = str(T)"
] | false | 0.048045 | 0.047578 | 1.00982 |
[
"s015063897",
"s226829930"
] |
u733814820
|
p03103
|
python
|
s196952748
|
s706071772
| 467 | 407 | 20,072 | 20,072 |
Accepted
|
Accepted
| 12.85 |
def resolve():
n, m = list(map(int, input().split()))
l = []
for i in range(n):
a, b = list(map(int, input().split()))
l.append([a, b])
l.sort()
ans = 0
for ab in l:
if ab[1] < m:
m -= ab[1]
ans += ab[0] * ab[1]
else:
ans += ab[0] * m
m = 0
break
print(ans)
return
if __name__ == "__main__":
resolve()
|
def resolve():
n, m = list(map(int, input().split()))
arr = []
for i in range(n):
a, b = list(map(int, input().split()))
arr.append([a, b])
arr.sort()
ans = 0
for ab in arr:
if ab[1] >= m:
ans += m * ab[0]
break
else:
ans += ab[0] * ab[1]
m -= ab[1]
print(ans)
return
if __name__ == "__main__":
resolve()
| 21 | 21 | 375 | 373 |
def resolve():
n, m = list(map(int, input().split()))
l = []
for i in range(n):
a, b = list(map(int, input().split()))
l.append([a, b])
l.sort()
ans = 0
for ab in l:
if ab[1] < m:
m -= ab[1]
ans += ab[0] * ab[1]
else:
ans += ab[0] * m
m = 0
break
print(ans)
return
if __name__ == "__main__":
resolve()
|
def resolve():
n, m = list(map(int, input().split()))
arr = []
for i in range(n):
a, b = list(map(int, input().split()))
arr.append([a, b])
arr.sort()
ans = 0
for ab in arr:
if ab[1] >= m:
ans += m * ab[0]
break
else:
ans += ab[0] * ab[1]
m -= ab[1]
print(ans)
return
if __name__ == "__main__":
resolve()
| false | 0 |
[
"- l = []",
"+ arr = []",
"- l.append([a, b])",
"- l.sort()",
"+ arr.append([a, b])",
"+ arr.sort()",
"- for ab in l:",
"- if ab[1] < m:",
"+ for ab in arr:",
"+ if ab[1] >= m:",
"+ ans += m * ab[0]",
"+ break",
"+ else:",
"+ ans += ab[0] * ab[1]",
"- ans += ab[0] * ab[1]",
"- else:",
"- ans += ab[0] * m",
"- m = 0",
"- break"
] | false | 0.040555 | 0.040465 | 1.002233 |
[
"s196952748",
"s706071772"
] |
u827202523
|
p02917
|
python
|
s671481679
|
s832329475
| 172 | 70 | 38,256 | 65,588 |
Accepted
|
Accepted
| 59.3 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
return int(eval(input()))
def getList():
return list(map(int, input().split()))
import math
n = getN()
INF = 100000000000
nums = [INF] + getList() + [INF]
ans = 0
for i, j in zip(nums, nums[1:]):
ans += min(i, j)
print(ans)
|
import sys
from collections import defaultdict, deque
import math
# import copy
# from bisect import bisect_left, bisect_right
# import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 10**9 + 7
def divide(k):
return pow(k, MOD-2, MOD)
def make_nck(n):
ret = [1]
for i in range(1, n+1):
ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)
# print(ret)
return ret
def make_nigojyo(n):
ret = [1]
for i in range(1, n+1):
ret.append((ret[-1] * 25) % MOD)
# print(ret)
return ret
def solve():
n = getN()
a = getList()
ans = 0
for i, j in zip(a, a[1:]):
ans += min(i, j)
ans += a[0] + a[-1]
print(ans)
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve()
| 19 | 64 | 362 | 1,102 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
return int(eval(input()))
def getList():
return list(map(int, input().split()))
import math
n = getN()
INF = 100000000000
nums = [INF] + getList() + [INF]
ans = 0
for i, j in zip(nums, nums[1:]):
ans += min(i, j)
print(ans)
|
import sys
from collections import defaultdict, deque
import math
# import copy
# from bisect import bisect_left, bisect_right
# import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10**20
MOD = 10**9 + 7
def divide(k):
return pow(k, MOD - 2, MOD)
def make_nck(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)
# print(ret)
return ret
def make_nigojyo(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * 25) % MOD)
# print(ret)
return ret
def solve():
n = getN()
a = getList()
ans = 0
for i, j in zip(a, a[1:]):
ans += min(i, j)
ans += a[0] + a[-1]
print(ans)
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve()
| false | 70.3125 |
[
"+from collections import defaultdict, deque",
"+import math",
"+# import copy",
"+# from bisect import bisect_left, bisect_right",
"+# import heapq",
"+# sys.setrecursionlimit(1000000)",
"+# input aliases",
"-sys.setrecursionlimit(1000000)",
"-from collections import deque",
"+getS = lambda: input().strip()",
"+getN = lambda: int(eval(input()))",
"+getList = lambda: list(map(int, input().split()))",
"+getZList = lambda: [int(x) - 1 for x in input().split()]",
"+INF = 10**20",
"+MOD = 10**9 + 7",
"-def getN():",
"- return int(eval(input()))",
"+def divide(k):",
"+ return pow(k, MOD - 2, MOD)",
"-def getList():",
"- return list(map(int, input().split()))",
"+def make_nck(n):",
"+ ret = [1]",
"+ for i in range(1, n + 1):",
"+ ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)",
"+ # print(ret)",
"+ return ret",
"-import math",
"+def make_nigojyo(n):",
"+ ret = [1]",
"+ for i in range(1, n + 1):",
"+ ret.append((ret[-1] * 25) % MOD)",
"+ # print(ret)",
"+ return ret",
"-n = getN()",
"-INF = 100000000000",
"-nums = [INF] + getList() + [INF]",
"-ans = 0",
"-for i, j in zip(nums, nums[1:]):",
"- ans += min(i, j)",
"-print(ans)",
"+",
"+def solve():",
"+ n = getN()",
"+ a = getList()",
"+ ans = 0",
"+ for i, j in zip(a, a[1:]):",
"+ ans += min(i, j)",
"+ ans += a[0] + a[-1]",
"+ print(ans)",
"+",
"+",
"+def main():",
"+ n = getN()",
"+ for _ in range(n):",
"+ solve()",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ # main()",
"+ solve()"
] | false | 0.034728 | 0.034617 | 1.003184 |
[
"s671481679",
"s832329475"
] |
u293523199
|
p04031
|
python
|
s364306197
|
s963345499
| 25 | 22 | 3,064 | 3,060 |
Accepted
|
Accepted
| 12 |
N = int(eval(input()))
A = list(map(int, input().split()))
total_costs = {}
if( len(set(A)) == 1 ):
print((0))
else:
for i in range(-100, 101):
cost = 0
for a in A:
cost += (a - i)**2
total_costs[i] = cost
print((min(total_costs.values())))
|
N = int(eval(input()))
A = list(map(int, input().split()))
total_costs = {}
if( len(set(A)) == 1 ):
print((0))
else:
for i in range(-100, 101):
cost = 0
for a in A:
cost += (a - i)*(a - i)
total_costs[i] = cost
print((min(total_costs.values())))
| 13 | 13 | 291 | 296 |
N = int(eval(input()))
A = list(map(int, input().split()))
total_costs = {}
if len(set(A)) == 1:
print((0))
else:
for i in range(-100, 101):
cost = 0
for a in A:
cost += (a - i) ** 2
total_costs[i] = cost
print((min(total_costs.values())))
|
N = int(eval(input()))
A = list(map(int, input().split()))
total_costs = {}
if len(set(A)) == 1:
print((0))
else:
for i in range(-100, 101):
cost = 0
for a in A:
cost += (a - i) * (a - i)
total_costs[i] = cost
print((min(total_costs.values())))
| false | 0 |
[
"- cost += (a - i) ** 2",
"+ cost += (a - i) * (a - i)"
] | false | 0.041754 | 0.038058 | 1.097112 |
[
"s364306197",
"s963345499"
] |
u215315599
|
p03160
|
python
|
s946163119
|
s785487062
| 852 | 229 | 23,076 | 52,856 |
Accepted
|
Accepted
| 73.12 |
import numpy as np
n = int(eval(input()))
h = [int(i) for i in input().split()]
dp = [1000000000]*n
dp[0]=0
dp[1]=np.abs(h[1]-h[0])
for i in range(1,n-1):
dp[i+1] = min(dp[i+1],dp[i]+np.abs(h[i]-h[i+1]))
dp[i+1] = min(dp[i+1],dp[i-1]+np.abs(h[i-1]-h[i+1]))
print((dp[n-1]))
|
def cost(a,b):
return abs(a-b)
INF = 10**9
N = int(eval(input()))
H = list(map(int,input().split()))
#dp[i][0]:V_iに行かない
#dp[i][1]:V_iに行く
dp = [ INF for __ in range(N)]
dp[0] = 0
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
print((dp[N-1]))
| 10 | 14 | 286 | 315 |
import numpy as np
n = int(eval(input()))
h = [int(i) for i in input().split()]
dp = [1000000000] * n
dp[0] = 0
dp[1] = np.abs(h[1] - h[0])
for i in range(1, n - 1):
dp[i + 1] = min(dp[i + 1], dp[i] + np.abs(h[i] - h[i + 1]))
dp[i + 1] = min(dp[i + 1], dp[i - 1] + np.abs(h[i - 1] - h[i + 1]))
print((dp[n - 1]))
|
def cost(a, b):
return abs(a - b)
INF = 10**9
N = int(eval(input()))
H = list(map(int, input().split()))
# dp[i][0]:V_iに行かない
# dp[i][1]:V_iに行く
dp = [INF for __ in range(N)]
dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(2, N):
dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))
print((dp[N - 1]))
| false | 28.571429 |
[
"-import numpy as np",
"+def cost(a, b):",
"+ return abs(a - b)",
"-n = int(eval(input()))",
"-h = [int(i) for i in input().split()]",
"-dp = [1000000000] * n",
"+",
"+INF = 10**9",
"+N = int(eval(input()))",
"+H = list(map(int, input().split()))",
"+# dp[i][0]:V_iに行かない",
"+# dp[i][1]:V_iに行く",
"+dp = [INF for __ in range(N)]",
"-dp[1] = np.abs(h[1] - h[0])",
"-for i in range(1, n - 1):",
"- dp[i + 1] = min(dp[i + 1], dp[i] + np.abs(h[i] - h[i + 1]))",
"- dp[i + 1] = min(dp[i + 1], dp[i - 1] + np.abs(h[i - 1] - h[i + 1]))",
"-print((dp[n - 1]))",
"+dp[1] = abs(H[1] - H[0])",
"+for i in range(2, N):",
"+ dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))",
"+print((dp[N - 1]))"
] | false | 0.578304 | 0.043449 | 13.309922 |
[
"s946163119",
"s785487062"
] |
u193264896
|
p02972
|
python
|
s205769550
|
s301869680
| 195 | 175 | 17,696 | 17,192 |
Accepted
|
Accepted
| 10.26 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def main():
N = int(readline())
A = [None] + list(map(int, readline().split()))
ans = []
choosen = [0] * (N+1)
for n in range(N,0,-1):
x = sum(choosen[n::n])
if x %2 == A[n]:
continue
choosen[n] += 1
ans.append(str(n))
print((len(ans)))
print((' '.join(ans)))
if __name__ == '__main__':
main()
|
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
A = [0] + list(map(int, readline().split()))
B = [0] * (N+1)
ans = []
for i in range(N,0,-1):
x = sum(B[i::i])
if x%2==A[i]:
continue
else:
B[i] = 1
ans.append(str(i))
print((len(ans)))
print((' '.join(ans)))
if __name__ == '__main__':
main()
| 27 | 26 | 542 | 508 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
def main():
N = int(readline())
A = [None] + list(map(int, readline().split()))
ans = []
choosen = [0] * (N + 1)
for n in range(N, 0, -1):
x = sum(choosen[n::n])
if x % 2 == A[n]:
continue
choosen[n] += 1
ans.append(str(n))
print((len(ans)))
print((" ".join(ans)))
if __name__ == "__main__":
main()
|
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
def main():
N = int(readline())
A = [0] + list(map(int, readline().split()))
B = [0] * (N + 1)
ans = []
for i in range(N, 0, -1):
x = sum(B[i::i])
if x % 2 == A[i]:
continue
else:
B[i] = 1
ans.append(str(i))
print((len(ans)))
print((" ".join(ans)))
if __name__ == "__main__":
main()
| false | 3.703704 |
[
"-read = sys.stdin.buffer.read",
"-readlines = sys.stdin.buffer.readlines",
"- A = [None] + list(map(int, readline().split()))",
"+ A = [0] + list(map(int, readline().split()))",
"+ B = [0] * (N + 1)",
"- choosen = [0] * (N + 1)",
"- for n in range(N, 0, -1):",
"- x = sum(choosen[n::n])",
"- if x % 2 == A[n]:",
"+ for i in range(N, 0, -1):",
"+ x = sum(B[i::i])",
"+ if x % 2 == A[i]:",
"- choosen[n] += 1",
"- ans.append(str(n))",
"+ else:",
"+ B[i] = 1",
"+ ans.append(str(i))"
] | false | 0.04256 | 0.040268 | 1.056918 |
[
"s205769550",
"s301869680"
] |
u411203878
|
p03424
|
python
|
s401867272
|
s018475660
| 165 | 71 | 38,256 | 61,596 |
Accepted
|
Accepted
| 56.97 |
n=int(eval(input()))
t = input().split()
count = []
memo = 0
for i in t:
if i in count:
continue
count.append(i)
memo += 1
if memo == 3:
print('Three')
else:
print('Four')
|
n = int(eval(input()))
s = list(map(str,input().split()))
if "Y" in s:
print("Four")
else:
print("Three")
| 14 | 8 | 207 | 116 |
n = int(eval(input()))
t = input().split()
count = []
memo = 0
for i in t:
if i in count:
continue
count.append(i)
memo += 1
if memo == 3:
print("Three")
else:
print("Four")
|
n = int(eval(input()))
s = list(map(str, input().split()))
if "Y" in s:
print("Four")
else:
print("Three")
| false | 42.857143 |
[
"-t = input().split()",
"-count = []",
"-memo = 0",
"-for i in t:",
"- if i in count:",
"- continue",
"- count.append(i)",
"- memo += 1",
"-if memo == 3:",
"+s = list(map(str, input().split()))",
"+if \"Y\" in s:",
"+ print(\"Four\")",
"+else:",
"-else:",
"- print(\"Four\")"
] | false | 0.056798 | 0.036639 | 1.550215 |
[
"s401867272",
"s018475660"
] |
u606045429
|
p02775
|
python
|
s589513841
|
s802414782
| 788 | 577 | 5,492 | 5,492 |
Accepted
|
Accepted
| 26.78 |
S = list(map(int, eval(input())))
a, b = 0, 1
for s in S:
a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)
print(a)
|
def main():
S = list(map(int, eval(input())))
a, b = 0, 1
for s in S:
a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)
print(a)
main()
| 7 | 11 | 186 | 231 |
S = list(map(int, eval(input())))
a, b = 0, 1
for s in S:
a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (
s + 1
) < b + 10 - (s + 1) else b + 10 - (s + 1)
print(a)
|
def main():
S = list(map(int, eval(input())))
a, b = 0, 1
for s in S:
a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (
s + 1
) < b + 10 - (s + 1) else b + 10 - (s + 1)
print(a)
main()
| false | 36.363636 |
[
"-S = list(map(int, eval(input())))",
"-a, b = 0, 1",
"-for s in S:",
"- a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (",
"- s + 1",
"- ) < b + 10 - (s + 1) else b + 10 - (s + 1)",
"-print(a)",
"+def main():",
"+ S = list(map(int, eval(input())))",
"+ a, b = 0, 1",
"+ for s in S:",
"+ a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (",
"+ s + 1",
"+ ) < b + 10 - (s + 1) else b + 10 - (s + 1)",
"+ print(a)",
"+",
"+",
"+main()"
] | false | 0.03422 | 0.045426 | 0.753321 |
[
"s589513841",
"s802414782"
] |
u108650331
|
p02695
|
python
|
s043964846
|
s972481944
| 668 | 313 | 23,320 | 9,104 |
Accepted
|
Accepted
| 53.14 |
#!/usr/bin/env python3
# スペース区切りの整数の入力
from collections import deque
def calc(seq):
score = 0
for a, b, c, d in data:
if seq[b-1] - seq[a-1] == c:
score += d
return score
# スペース区切りの整数の入力
N, M, Q = list(map(int, input().split()))
#配列の入力
data = [list(map(int, input().split())) for _ in range(Q)]
ans = -1
que = deque()
for i in range(1, M+1):
que.append([i])
while que:
seq = que.popleft()
if len(seq) == N:
score = calc(seq)
ans = max(ans, score)
else:
for i in range(seq[-1], M+1):
seq_next = seq + [i]
que.append(seq_next)
print(ans)
|
#!/usr/bin/env python3
# スペース区切りの整数の入力
def dfs(seq):
ans = 0
if len(seq) == N:
score_ret = 0
for a, b, c, d in data:
if seq[b-1] - seq[a-1] == c:
score_ret += d
return score_ret
else:
for i in range(seq[-1], M+1):
seq_next = seq + (i,)
score = dfs(seq_next)
ans = max(ans, score)
return ans
# スペース区切りの整数の入力
N, M, Q = list(map(int, input().split()))
#配列の入力
data = [list(map(int, input().split())) for _ in range(Q)]
ans = -1
score = dfs((1,))
ans = max(ans, score)
print(ans)
| 37 | 28 | 672 | 616 |
#!/usr/bin/env python3
# スペース区切りの整数の入力
from collections import deque
def calc(seq):
score = 0
for a, b, c, d in data:
if seq[b - 1] - seq[a - 1] == c:
score += d
return score
# スペース区切りの整数の入力
N, M, Q = list(map(int, input().split()))
# 配列の入力
data = [list(map(int, input().split())) for _ in range(Q)]
ans = -1
que = deque()
for i in range(1, M + 1):
que.append([i])
while que:
seq = que.popleft()
if len(seq) == N:
score = calc(seq)
ans = max(ans, score)
else:
for i in range(seq[-1], M + 1):
seq_next = seq + [i]
que.append(seq_next)
print(ans)
|
#!/usr/bin/env python3
# スペース区切りの整数の入力
def dfs(seq):
ans = 0
if len(seq) == N:
score_ret = 0
for a, b, c, d in data:
if seq[b - 1] - seq[a - 1] == c:
score_ret += d
return score_ret
else:
for i in range(seq[-1], M + 1):
seq_next = seq + (i,)
score = dfs(seq_next)
ans = max(ans, score)
return ans
# スペース区切りの整数の入力
N, M, Q = list(map(int, input().split()))
# 配列の入力
data = [list(map(int, input().split())) for _ in range(Q)]
ans = -1
score = dfs((1,))
ans = max(ans, score)
print(ans)
| false | 24.324324 |
[
"-from collections import deque",
"-",
"-",
"-def calc(seq):",
"- score = 0",
"- for a, b, c, d in data:",
"- if seq[b - 1] - seq[a - 1] == c:",
"- score += d",
"- return score",
"+def dfs(seq):",
"+ ans = 0",
"+ if len(seq) == N:",
"+ score_ret = 0",
"+ for a, b, c, d in data:",
"+ if seq[b - 1] - seq[a - 1] == c:",
"+ score_ret += d",
"+ return score_ret",
"+ else:",
"+ for i in range(seq[-1], M + 1):",
"+ seq_next = seq + (i,)",
"+ score = dfs(seq_next)",
"+ ans = max(ans, score)",
"+ return ans",
"-que = deque()",
"-for i in range(1, M + 1):",
"- que.append([i])",
"-while que:",
"- seq = que.popleft()",
"- if len(seq) == N:",
"- score = calc(seq)",
"- ans = max(ans, score)",
"- else:",
"- for i in range(seq[-1], M + 1):",
"- seq_next = seq + [i]",
"- que.append(seq_next)",
"+score = dfs((1,))",
"+ans = max(ans, score)"
] | false | 0.102315 | 0.119329 | 0.857416 |
[
"s043964846",
"s972481944"
] |
u875541136
|
p02755
|
python
|
s455822971
|
s007707531
| 202 | 177 | 38,384 | 38,384 |
Accepted
|
Accepted
| 12.38 |
isFound = False
li = list(map(int,input().split()))
min = int(li[0] / 0.08)
max = int((li[0] + 1) / 0.08) - 1
for i in range(min, max):
if((int(i * 0.1) == li[1]) and (int(i * 0.08) == li[0])):
print(i)
isFound = True
break
if(not(isFound)):
print((-1))
|
import math
A, B = list(map(int, input().split()))
minV = math.ceil(A / 0.08)
maxV = int((A + 1) / 0.08)
for i in range(minV, maxV):
if int(i * 0.1) == B:
print(i)
exit()
print((-1))
| 11 | 9 | 293 | 202 |
isFound = False
li = list(map(int, input().split()))
min = int(li[0] / 0.08)
max = int((li[0] + 1) / 0.08) - 1
for i in range(min, max):
if (int(i * 0.1) == li[1]) and (int(i * 0.08) == li[0]):
print(i)
isFound = True
break
if not (isFound):
print((-1))
|
import math
A, B = list(map(int, input().split()))
minV = math.ceil(A / 0.08)
maxV = int((A + 1) / 0.08)
for i in range(minV, maxV):
if int(i * 0.1) == B:
print(i)
exit()
print((-1))
| false | 18.181818 |
[
"-isFound = False",
"-li = list(map(int, input().split()))",
"-min = int(li[0] / 0.08)",
"-max = int((li[0] + 1) / 0.08) - 1",
"-for i in range(min, max):",
"- if (int(i * 0.1) == li[1]) and (int(i * 0.08) == li[0]):",
"+import math",
"+",
"+A, B = list(map(int, input().split()))",
"+minV = math.ceil(A / 0.08)",
"+maxV = int((A + 1) / 0.08)",
"+for i in range(minV, maxV):",
"+ if int(i * 0.1) == B:",
"- isFound = True",
"- break",
"-if not (isFound):",
"- print((-1))",
"+ exit()",
"+print((-1))"
] | false | 0.036342 | 0.037695 | 0.964094 |
[
"s455822971",
"s007707531"
] |
u652057333
|
p02780
|
python
|
s095691067
|
s443758806
| 268 | 189 | 24,808 | 24,548 |
Accepted
|
Accepted
| 29.48 |
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
e = []
for v in p:
if v % 2 == 0:
e.append(((v+1)*(v//2)) / v)
else:
e.append(((v+1)*(v//2) + (v+1) // 2) / v)
e_sum = [0]
for i in range(len(e)):
e_sum.append(e_sum[i] + e[i])
ans = 0
for i in range(k, len(e_sum)):
ans = max(ans, e_sum[i] - e_sum[i-k])
print(ans)
|
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p = [(x+1) / 2 for x in p]
# 累積和
def cumsum(a):
r = [0]
for v in a:
r.append(r[-1] + v)
return r
cs = cumsum(p)
ans = 0
for i in range(k, n+1):
ans = max(ans, cs[i] - cs[i-k])
print(ans)
| 21 | 18 | 392 | 300 |
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
e = []
for v in p:
if v % 2 == 0:
e.append(((v + 1) * (v // 2)) / v)
else:
e.append(((v + 1) * (v // 2) + (v + 1) // 2) / v)
e_sum = [0]
for i in range(len(e)):
e_sum.append(e_sum[i] + e[i])
ans = 0
for i in range(k, len(e_sum)):
ans = max(ans, e_sum[i] - e_sum[i - k])
print(ans)
|
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p = [(x + 1) / 2 for x in p]
# 累積和
def cumsum(a):
r = [0]
for v in a:
r.append(r[-1] + v)
return r
cs = cumsum(p)
ans = 0
for i in range(k, n + 1):
ans = max(ans, cs[i] - cs[i - k])
print(ans)
| false | 14.285714 |
[
"-e = []",
"-for v in p:",
"- if v % 2 == 0:",
"- e.append(((v + 1) * (v // 2)) / v)",
"- else:",
"- e.append(((v + 1) * (v // 2) + (v + 1) // 2) / v)",
"-e_sum = [0]",
"-for i in range(len(e)):",
"- e_sum.append(e_sum[i] + e[i])",
"+p = [(x + 1) / 2 for x in p]",
"+# 累積和",
"+def cumsum(a):",
"+ r = [0]",
"+ for v in a:",
"+ r.append(r[-1] + v)",
"+ return r",
"+",
"+",
"+cs = cumsum(p)",
"-for i in range(k, len(e_sum)):",
"- ans = max(ans, e_sum[i] - e_sum[i - k])",
"+for i in range(k, n + 1):",
"+ ans = max(ans, cs[i] - cs[i - k])"
] | false | 0.035241 | 0.035309 | 0.998081 |
[
"s095691067",
"s443758806"
] |
u262525101
|
p02755
|
python
|
s288901194
|
s008313568
| 21 | 18 | 3,064 | 3,060 |
Accepted
|
Accepted
| 14.29 |
import math
A ,B = list(map(int,input().split()))
def problem_koganemaru(A,B):
for price in range(10000):
if math.floor(price*0.08) == A and math.floor(price*0.1) == B:
return price
return -1
print((problem_koganemaru(A,B)))
|
import math
A,B = list(map(int,input().split()))
def problem_gksn(A, B):
x_min = math.ceil(A / (0.08))
x_max = math.floor((A+1)/0.08)
y_min = math.ceil(B / (0.10))
y_max = math.floor((B+1) / (0.10))
# print(x_min,x_max,y_min,y_max)
if max(x_min, y_min) < min(x_max, y_max):
return max(x_min, y_min)
else:
return -1
print((problem_gksn(A,B)))
# {[ } ]
| 10 | 14 | 251 | 383 |
import math
A, B = list(map(int, input().split()))
def problem_koganemaru(A, B):
for price in range(10000):
if math.floor(price * 0.08) == A and math.floor(price * 0.1) == B:
return price
return -1
print((problem_koganemaru(A, B)))
|
import math
A, B = list(map(int, input().split()))
def problem_gksn(A, B):
x_min = math.ceil(A / (0.08))
x_max = math.floor((A + 1) / 0.08)
y_min = math.ceil(B / (0.10))
y_max = math.floor((B + 1) / (0.10))
# print(x_min,x_max,y_min,y_max)
if max(x_min, y_min) < min(x_max, y_max):
return max(x_min, y_min)
else:
return -1
print((problem_gksn(A, B)))
# {[ } ]
| false | 28.571429 |
[
"-def problem_koganemaru(A, B):",
"- for price in range(10000):",
"- if math.floor(price * 0.08) == A and math.floor(price * 0.1) == B:",
"- return price",
"- return -1",
"+def problem_gksn(A, B):",
"+ x_min = math.ceil(A / (0.08))",
"+ x_max = math.floor((A + 1) / 0.08)",
"+ y_min = math.ceil(B / (0.10))",
"+ y_max = math.floor((B + 1) / (0.10))",
"+ # print(x_min,x_max,y_min,y_max)",
"+ if max(x_min, y_min) < min(x_max, y_max):",
"+ return max(x_min, y_min)",
"+ else:",
"+ return -1",
"-print((problem_koganemaru(A, B)))",
"+print((problem_gksn(A, B)))",
"+# {[ } ]"
] | false | 0.045971 | 0.048389 | 0.950016 |
[
"s288901194",
"s008313568"
] |
u219417113
|
p03160
|
python
|
s666434331
|
s330762501
| 160 | 127 | 13,928 | 13,980 |
Accepted
|
Accepted
| 20.62 |
inf = 10**9 + 7
n = int(eval(input()))
nodes = list(map(int, input().split()))
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
dp[i] = min(dp[i], dp[i-1]+abs(nodes[i]-nodes[i-1]))
if i > 1:
dp[i] = min(dp[i], dp[i-2]+abs(nodes[i]-nodes[i-2]))
print((dp[n-1]))
|
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * N
dp[1] = abs(h[1]-h[0])
for i in range(2, N):
dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
print((dp[N-1]))
| 14 | 10 | 284 | 210 |
inf = 10**9 + 7
n = int(eval(input()))
nodes = list(map(int, input().split()))
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
dp[i] = min(dp[i], dp[i - 1] + abs(nodes[i] - nodes[i - 1]))
if i > 1:
dp[i] = min(dp[i], dp[i - 2] + abs(nodes[i] - nodes[i - 2]))
print((dp[n - 1]))
|
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * N
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[N - 1]))
| false | 28.571429 |
[
"-inf = 10**9 + 7",
"-n = int(eval(input()))",
"-nodes = list(map(int, input().split()))",
"-dp = [inf] * n",
"-dp[0] = 0",
"-for i in range(1, n):",
"- dp[i] = min(dp[i], dp[i - 1] + abs(nodes[i] - nodes[i - 1]))",
"- if i > 1:",
"- dp[i] = min(dp[i], dp[i - 2] + abs(nodes[i] - nodes[i - 2]))",
"-print((dp[n - 1]))",
"+N = int(eval(input()))",
"+h = list(map(int, input().split()))",
"+dp = [0] * N",
"+dp[1] = abs(h[1] - h[0])",
"+for i in range(2, N):",
"+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))",
"+print((dp[N - 1]))"
] | false | 0.04166 | 0.034344 | 1.213011 |
[
"s666434331",
"s330762501"
] |
u853185302
|
p03012
|
python
|
s520538943
|
s114150852
| 20 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 15 |
N = int(eval(input()))
W = list(map(int,input().split()))
min_w = 10000000
for i in range(N):
T1 = W[:i]
T2 = W[i:]
if min_w > abs(sum(T1)-sum(T2)):
min_w = abs(sum(T1)-sum(T2))
print(min_w)
|
N = int(eval(input()))
W = list(map(int,input().split()))
ans = [abs(sum(W[:i])-sum(W[i:])) for i in range(N)]
print((min(ans)))
| 9 | 4 | 202 | 123 |
N = int(eval(input()))
W = list(map(int, input().split()))
min_w = 10000000
for i in range(N):
T1 = W[:i]
T2 = W[i:]
if min_w > abs(sum(T1) - sum(T2)):
min_w = abs(sum(T1) - sum(T2))
print(min_w)
|
N = int(eval(input()))
W = list(map(int, input().split()))
ans = [abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]
print((min(ans)))
| false | 55.555556 |
[
"-min_w = 10000000",
"-for i in range(N):",
"- T1 = W[:i]",
"- T2 = W[i:]",
"- if min_w > abs(sum(T1) - sum(T2)):",
"- min_w = abs(sum(T1) - sum(T2))",
"-print(min_w)",
"+ans = [abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]",
"+print((min(ans)))"
] | false | 0.048751 | 0.048977 | 0.995384 |
[
"s520538943",
"s114150852"
] |
u387774811
|
p02936
|
python
|
s780822467
|
s137852357
| 1,113 | 889 | 55,728 | 93,972 |
Accepted
|
Accepted
| 20.13 |
import sys
input = sys.stdin.readline
N,Q=list(map(int,input().split()))
ans=[0]*N
ki=[[] for _ in range(N)]
for i in range(N-1):
a,b=list(map(int,input().split()))
ki[a-1].append(b-1)
ki[b-1].append(a-1)
for i in range(Q):
p,q=list(map(int,input().split()))
ans[p-1]+=q
# dfs
stack = [0]
visited = ["False"] * N
while stack:
ne = stack.pop()
if visited[ne] == "False":
visited[ne] = "True"
for j in ki[ne]:
if visited[j] == "False":
ans[j]+=ans[ne]
stack.append(j)
print((*ans))
|
import sys
input = sys.stdin.readline
N,Q=list(map(int,input().split()))
ans=[0]*N
ki=[[] for _ in range(N)]
for i in range(N-1):
a,b=list(map(int,input().split()))
ki[a-1].append(b-1)
ki[b-1].append(a-1)
for i in range(Q):
p,q=list(map(int,input().split()))
ans[p-1]+=q
# dfs
from collections import deque
stack =deque([0])
visited = ["False"] * N
while stack:
ne = stack.popleft()
if visited[ne] == "False":
visited[ne] = "True"
for j in ki[ne]:
if visited[j] == "False":
ans[j]+=ans[ne]
stack.append(j)
print((*ans))
| 24 | 25 | 504 | 546 |
import sys
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
ans = [0] * N
ki = [[] for _ in range(N)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
ki[a - 1].append(b - 1)
ki[b - 1].append(a - 1)
for i in range(Q):
p, q = list(map(int, input().split()))
ans[p - 1] += q
# dfs
stack = [0]
visited = ["False"] * N
while stack:
ne = stack.pop()
if visited[ne] == "False":
visited[ne] = "True"
for j in ki[ne]:
if visited[j] == "False":
ans[j] += ans[ne]
stack.append(j)
print((*ans))
|
import sys
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
ans = [0] * N
ki = [[] for _ in range(N)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
ki[a - 1].append(b - 1)
ki[b - 1].append(a - 1)
for i in range(Q):
p, q = list(map(int, input().split()))
ans[p - 1] += q
# dfs
from collections import deque
stack = deque([0])
visited = ["False"] * N
while stack:
ne = stack.popleft()
if visited[ne] == "False":
visited[ne] = "True"
for j in ki[ne]:
if visited[j] == "False":
ans[j] += ans[ne]
stack.append(j)
print((*ans))
| false | 4 |
[
"-stack = [0]",
"+from collections import deque",
"+",
"+stack = deque([0])",
"- ne = stack.pop()",
"+ ne = stack.popleft()"
] | false | 0.04801 | 0.045016 | 1.066512 |
[
"s780822467",
"s137852357"
] |
u057109575
|
p02850
|
python
|
s551964215
|
s309141802
| 707 | 328 | 83,160 | 113,260 |
Accepted
|
Accepted
| 53.61 |
from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N)]
for n, (i, j) in enumerate(X):
tree[i - 1].append((n, j - 1))
q = deque()
q.append((0, 0))
ans = [0] * (N - 1)
while len(q) > 0:
# u: node number, c: color
u, c = q.popleft()
cnt = 1
for i, (n, v) in enumerate(tree[u]):
if cnt == c:
cnt += 1
ans[n] = cnt
q.append((v, cnt))
cnt += 1
print(max(ans))
print(*ans, sep="\n")
|
from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(X):
tree[a].append((b, i))
tree[b].append((a, i))
visited = [False] * (N + 1)
visited[1] = True
color = [0] * (N - 1)
stack = deque()
stack.append((1, 0))
while stack:
u, c = stack.popleft()
tmp = 0
for v, i in tree[u]:
if visited[v]:
continue
tmp += 1
if tmp == c:
tmp += 1
visited[v] = True
color[i] = tmp
stack.append((v, tmp))
print(max(color))
print(*color, sep="\n")
| 27 | 32 | 566 | 694 |
from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N)]
for n, (i, j) in enumerate(X):
tree[i - 1].append((n, j - 1))
q = deque()
q.append((0, 0))
ans = [0] * (N - 1)
while len(q) > 0:
# u: node number, c: color
u, c = q.popleft()
cnt = 1
for i, (n, v) in enumerate(tree[u]):
if cnt == c:
cnt += 1
ans[n] = cnt
q.append((v, cnt))
cnt += 1
print(max(ans))
print(*ans, sep="\n")
|
from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(X):
tree[a].append((b, i))
tree[b].append((a, i))
visited = [False] * (N + 1)
visited[1] = True
color = [0] * (N - 1)
stack = deque()
stack.append((1, 0))
while stack:
u, c = stack.popleft()
tmp = 0
for v, i in tree[u]:
if visited[v]:
continue
tmp += 1
if tmp == c:
tmp += 1
visited[v] = True
color[i] = tmp
stack.append((v, tmp))
print(max(color))
print(*color, sep="\n")
| false | 15.625 |
[
"-tree = [[] for _ in range(N)]",
"-for n, (i, j) in enumerate(X):",
"- tree[i - 1].append((n, j - 1))",
"-q = deque()",
"-q.append((0, 0))",
"-ans = [0] * (N - 1)",
"-while len(q) > 0:",
"- # u: node number, c: color",
"- u, c = q.popleft()",
"- cnt = 1",
"- for i, (n, v) in enumerate(tree[u]):",
"- if cnt == c:",
"- cnt += 1",
"- ans[n] = cnt",
"- q.append((v, cnt))",
"- cnt += 1",
"-print(max(ans))",
"-print(*ans, sep=\"\\n\")",
"+tree = [[] for _ in range(N + 1)]",
"+for i, (a, b) in enumerate(X):",
"+ tree[a].append((b, i))",
"+ tree[b].append((a, i))",
"+visited = [False] * (N + 1)",
"+visited[1] = True",
"+color = [0] * (N - 1)",
"+stack = deque()",
"+stack.append((1, 0))",
"+while stack:",
"+ u, c = stack.popleft()",
"+ tmp = 0",
"+ for v, i in tree[u]:",
"+ if visited[v]:",
"+ continue",
"+ tmp += 1",
"+ if tmp == c:",
"+ tmp += 1",
"+ visited[v] = True",
"+ color[i] = tmp",
"+ stack.append((v, tmp))",
"+print(max(color))",
"+print(*color, sep=\"\\n\")"
] | false | 0.082035 | 0.035603 | 2.30415 |
[
"s551964215",
"s309141802"
] |
u760794812
|
p03946
|
python
|
s218985589
|
s400659346
| 192 | 107 | 24,228 | 15,020 |
Accepted
|
Accepted
| 44.27 |
N,T = list(map(int,input().split()))
List = list(map(int,input().split()))
dic = {}
min = List[0]
for i in range(N):
if List[i]<min:
min = List[i]
if List[i]-min not in dic:
dic[List[i]-min] = 1
else:
dic[List[i]-min] += 1
dic2 = sorted(list(dic.items()), reverse=True)
Answer = dic2[0][1]
print(Answer)
|
n, t = list(map(int, input().split()))
*a, = list(map(int, input().split()))
purchase = a[0]
profit = []
for i in range(len(a)):
profit.append(a[i] - purchase)
if a[i] < purchase:
purchase = a[i]
profit.sort()
Answer = profit.count(profit[-1])
print(Answer)
| 14 | 11 | 322 | 263 |
N, T = list(map(int, input().split()))
List = list(map(int, input().split()))
dic = {}
min = List[0]
for i in range(N):
if List[i] < min:
min = List[i]
if List[i] - min not in dic:
dic[List[i] - min] = 1
else:
dic[List[i] - min] += 1
dic2 = sorted(list(dic.items()), reverse=True)
Answer = dic2[0][1]
print(Answer)
|
n, t = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
purchase = a[0]
profit = []
for i in range(len(a)):
profit.append(a[i] - purchase)
if a[i] < purchase:
purchase = a[i]
profit.sort()
Answer = profit.count(profit[-1])
print(Answer)
| false | 21.428571 |
[
"-N, T = list(map(int, input().split()))",
"-List = list(map(int, input().split()))",
"-dic = {}",
"-min = List[0]",
"-for i in range(N):",
"- if List[i] < min:",
"- min = List[i]",
"- if List[i] - min not in dic:",
"- dic[List[i] - min] = 1",
"- else:",
"- dic[List[i] - min] += 1",
"-dic2 = sorted(list(dic.items()), reverse=True)",
"-Answer = dic2[0][1]",
"+n, t = list(map(int, input().split()))",
"+(*a,) = list(map(int, input().split()))",
"+purchase = a[0]",
"+profit = []",
"+for i in range(len(a)):",
"+ profit.append(a[i] - purchase)",
"+ if a[i] < purchase:",
"+ purchase = a[i]",
"+profit.sort()",
"+Answer = profit.count(profit[-1])"
] | false | 0.052994 | 0.07863 | 0.673969 |
[
"s218985589",
"s400659346"
] |
u945181840
|
p03137
|
python
|
s965575617
|
s457651013
| 1,086 | 113 | 13,968 | 13,960 |
Accepted
|
Accepted
| 89.59 |
N, M = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)
ans = 0
if N >= M:
print(ans)
else:
for i in range(M - 1):
d[i] = abs(X[i + 1] - X[i])
d.sort(reverse=True)
b = d[:N - 1]
for i in range(M - 1):
if d[i] in b:
b.remove(d[i])
else:
ans += d[i]
print(ans)
|
N, M = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)
if N >= M:
print((0))
else:
for i in range(M - 1):
d[i] = abs(X[i + 1] - X[i])
d.sort(reverse=True)
print((sum(d[N - 1:])))
| 18 | 11 | 387 | 249 |
N, M = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)
ans = 0
if N >= M:
print(ans)
else:
for i in range(M - 1):
d[i] = abs(X[i + 1] - X[i])
d.sort(reverse=True)
b = d[: N - 1]
for i in range(M - 1):
if d[i] in b:
b.remove(d[i])
else:
ans += d[i]
print(ans)
|
N, M = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)
if N >= M:
print((0))
else:
for i in range(M - 1):
d[i] = abs(X[i + 1] - X[i])
d.sort(reverse=True)
print((sum(d[N - 1 :])))
| false | 38.888889 |
[
"-ans = 0",
"- print(ans)",
"+ print((0))",
"- b = d[: N - 1]",
"- for i in range(M - 1):",
"- if d[i] in b:",
"- b.remove(d[i])",
"- else:",
"- ans += d[i]",
"- print(ans)",
"+ print((sum(d[N - 1 :])))"
] | false | 0.127078 | 0.113126 | 1.123334 |
[
"s965575617",
"s457651013"
] |
u072717685
|
p02683
|
python
|
s167590537
|
s985099430
| 105 | 72 | 10,036 | 9,152 |
Accepted
|
Accepted
| 31.43 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import product
def main():
n, m, x = list(map(int, input().split()))
books = []
for _ in range(n):
book = tuple(map(int, input().split()))
books.append(book)
pro = product((1, 0),repeat=n)
costs = []
for proe in pro:
cost = 0
algo = [0] * m
for i1, proee in enumerate(proe):
if proee:
cost += books[i1][0]
for al in range(1, m + 1):
algo[al-1] += books[i1][al]
if all([i >= x for i in algo]):
costs.append(cost)
if not costs:
print((-1))
else:
print((min(costs)))
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import product
def main():
n, m, x = list(map(int, input().split()))
books = []
for _ in range(n):
book = tuple(map(int, input().split()))
books.append(book)
pro = product((1, 0),repeat=n)
costs = []
for proe in pro:
cost = 0
algo = [0] * m
for i1, proee in enumerate(proe):
if proee:
cost += books[i1][0]
for al in range(1, m + 1):
algo[al-1] += books[i1][al]
if all([i >= x for i in algo]):
costs.append(cost)
if not costs:
print((-1))
else:
print((min(costs)))
if __name__ == '__main__':
main()
| 30 | 30 | 782 | 775 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import product
def main():
n, m, x = list(map(int, input().split()))
books = []
for _ in range(n):
book = tuple(map(int, input().split()))
books.append(book)
pro = product((1, 0), repeat=n)
costs = []
for proe in pro:
cost = 0
algo = [0] * m
for i1, proee in enumerate(proe):
if proee:
cost += books[i1][0]
for al in range(1, m + 1):
algo[al - 1] += books[i1][al]
if all([i >= x for i in algo]):
costs.append(cost)
if not costs:
print((-1))
else:
print((min(costs)))
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import product
def main():
n, m, x = list(map(int, input().split()))
books = []
for _ in range(n):
book = tuple(map(int, input().split()))
books.append(book)
pro = product((1, 0), repeat=n)
costs = []
for proe in pro:
cost = 0
algo = [0] * m
for i1, proee in enumerate(proe):
if proee:
cost += books[i1][0]
for al in range(1, m + 1):
algo[al - 1] += books[i1][al]
if all([i >= x for i in algo]):
costs.append(cost)
if not costs:
print((-1))
else:
print((min(costs)))
if __name__ == "__main__":
main()
| false | 0 |
[
"- if all([i >= x for i in algo]):",
"- costs.append(cost)",
"+ if all([i >= x for i in algo]):",
"+ costs.append(cost)"
] | false | 0.050198 | 0.00715 | 7.021094 |
[
"s167590537",
"s985099430"
] |
u604774382
|
p02392
|
python
|
s672902931
|
s152482423
| 30 | 20 | 6,720 | 4,196 |
Accepted
|
Accepted
| 33.33 |
#coding:utf-8
import sys
abc=sys.stdin.readline()
a,b,c=abc.split( ' ' )
a=int( a )
b=int( b )
c=int( c )
if a < b and b < c:
print( "Yes" )
else:
print( "No" )
|
import sys
nums = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if nums[0] < nums[1] and nums[1] < nums[2]:
print( "Yes" )
else:
print( "No" )
| 12 | 7 | 175 | 165 |
# coding:utf-8
import sys
abc = sys.stdin.readline()
a, b, c = abc.split(" ")
a = int(a)
b = int(b)
c = int(c)
if a < b and b < c:
print("Yes")
else:
print("No")
|
import sys
nums = [int(val) for val in sys.stdin.readline().split(" ")]
if nums[0] < nums[1] and nums[1] < nums[2]:
print("Yes")
else:
print("No")
| false | 41.666667 |
[
"-# coding:utf-8",
"-abc = sys.stdin.readline()",
"-a, b, c = abc.split(\" \")",
"-a = int(a)",
"-b = int(b)",
"-c = int(c)",
"-if a < b and b < c:",
"+nums = [int(val) for val in sys.stdin.readline().split(\" \")]",
"+if nums[0] < nums[1] and nums[1] < nums[2]:"
] | false | 0.092472 | 0.07469 | 1.23808 |
[
"s672902931",
"s152482423"
] |
u546959066
|
p03241
|
python
|
s502579905
|
s982927645
| 1,736 | 21 | 2,940 | 3,060 |
Accepted
|
Accepted
| 98.79 |
N, M = list(map(int, input().split(" ")))
def solv(N, M):
d = M//N
for i in range(d+1)[::-1]:
if M%i == 0:
return i
print((solv(N, M)))
|
n, m = list(map(int, input().split(" ")))
ds = [x for x in range(1, int(m**.5)+1) if m%x==0]
ds = ds + [m//x for x in ds]
ds = [x for x in ds if x<=m//n]
print((max(ds)))
| 7 | 6 | 167 | 174 |
N, M = list(map(int, input().split(" ")))
def solv(N, M):
d = M // N
for i in range(d + 1)[::-1]:
if M % i == 0:
return i
print((solv(N, M)))
|
n, m = list(map(int, input().split(" ")))
ds = [x for x in range(1, int(m**0.5) + 1) if m % x == 0]
ds = ds + [m // x for x in ds]
ds = [x for x in ds if x <= m // n]
print((max(ds)))
| false | 14.285714 |
[
"-N, M = list(map(int, input().split(\" \")))",
"-",
"-",
"-def solv(N, M):",
"- d = M // N",
"- for i in range(d + 1)[::-1]:",
"- if M % i == 0:",
"- return i",
"-",
"-",
"-print((solv(N, M)))",
"+n, m = list(map(int, input().split(\" \")))",
"+ds = [x for x in range(1, int(m**0.5) + 1) if m % x == 0]",
"+ds = ds + [m // x for x in ds]",
"+ds = [x for x in ds if x <= m // n]",
"+print((max(ds)))"
] | false | 0.06678 | 0.049494 | 1.34924 |
[
"s502579905",
"s982927645"
] |
u072717685
|
p02615
|
python
|
s778794312
|
s227969284
| 148 | 135 | 97,440 | 31,720 |
Accepted
|
Accepted
| 8.78 |
import sys
read = sys.stdin.read
def main():
n, *a = list(map(int, read().split()))
a.sort(reverse=True)
r = a[0]
end = int((n - 2) // 2)
r += sum(a[1:end+1]) * 2
if n % 2 == 1:
r += a[end+1]
print(r)
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import deque
def main():
n, *a = list(map(int, read().split()))
a.sort(reverse=True)
a = deque(a)
circle_joined = deque()
next_score = a.popleft()
r = 0
flag = False
while a:
circle_joined.append(a.popleft())
if flag:
next_score = circle_joined.popleft()
r += next_score
flag = False
else:
r += next_score
flag = True
print(r)
if __name__ == '__main__':
main()
| 14 | 26 | 283 | 617 |
import sys
read = sys.stdin.read
def main():
n, *a = list(map(int, read().split()))
a.sort(reverse=True)
r = a[0]
end = int((n - 2) // 2)
r += sum(a[1 : end + 1]) * 2
if n % 2 == 1:
r += a[end + 1]
print(r)
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import deque
def main():
n, *a = list(map(int, read().split()))
a.sort(reverse=True)
a = deque(a)
circle_joined = deque()
next_score = a.popleft()
r = 0
flag = False
while a:
circle_joined.append(a.popleft())
if flag:
next_score = circle_joined.popleft()
r += next_score
flag = False
else:
r += next_score
flag = True
print(r)
if __name__ == "__main__":
main()
| false | 46.153846 |
[
"+readline = sys.stdin.readline",
"+readlines = sys.stdin.readlines",
"+from collections import deque",
"- r = a[0]",
"- end = int((n - 2) // 2)",
"- r += sum(a[1 : end + 1]) * 2",
"- if n % 2 == 1:",
"- r += a[end + 1]",
"+ a = deque(a)",
"+ circle_joined = deque()",
"+ next_score = a.popleft()",
"+ r = 0",
"+ flag = False",
"+ while a:",
"+ circle_joined.append(a.popleft())",
"+ if flag:",
"+ next_score = circle_joined.popleft()",
"+ r += next_score",
"+ flag = False",
"+ else:",
"+ r += next_score",
"+ flag = True"
] | false | 0.04692 | 0.089983 | 0.521425 |
[
"s778794312",
"s227969284"
] |
u969080040
|
p02717
|
python
|
s780276749
|
s447889558
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
hello,y,z=input().split()
hello=int(hello)
y=int(y)
z=int(z)
print((z,hello,y))
|
X,Y,Z=list(map(int,input().split()))
print((Z,X,Y))
| 5 | 2 | 81 | 44 |
hello, y, z = input().split()
hello = int(hello)
y = int(y)
z = int(z)
print((z, hello, y))
|
X, Y, Z = list(map(int, input().split()))
print((Z, X, Y))
| false | 60 |
[
"-hello, y, z = input().split()",
"-hello = int(hello)",
"-y = int(y)",
"-z = int(z)",
"-print((z, hello, y))",
"+X, Y, Z = list(map(int, input().split()))",
"+print((Z, X, Y))"
] | false | 0.071176 | 0.050074 | 1.421405 |
[
"s780276749",
"s447889558"
] |
u597374218
|
p03262
|
python
|
s729237066
|
s007954262
| 165 | 91 | 16,284 | 16,272 |
Accepted
|
Accepted
| 44.85 |
from fractions import gcd
n,d=list(map(int,input().split()))
x=sorted(list(map(int,input().split()))+[d])
r=x[1]-x[0]
print((min(gcd(x[i+1]-x[i],r) for i in range(n))))
|
from functools import reduce
from fractions import gcd
N,X=list(map(int,input().split()))
x=[abs(X-int(i)) for i in input().split()]
print((reduce(gcd,x)))
| 5 | 5 | 164 | 151 |
from fractions import gcd
n, d = list(map(int, input().split()))
x = sorted(list(map(int, input().split())) + [d])
r = x[1] - x[0]
print((min(gcd(x[i + 1] - x[i], r) for i in range(n))))
|
from functools import reduce
from fractions import gcd
N, X = list(map(int, input().split()))
x = [abs(X - int(i)) for i in input().split()]
print((reduce(gcd, x)))
| false | 0 |
[
"+from functools import reduce",
"-n, d = list(map(int, input().split()))",
"-x = sorted(list(map(int, input().split())) + [d])",
"-r = x[1] - x[0]",
"-print((min(gcd(x[i + 1] - x[i], r) for i in range(n))))",
"+N, X = list(map(int, input().split()))",
"+x = [abs(X - int(i)) for i in input().split()]",
"+print((reduce(gcd, x)))"
] | false | 0.086617 | 0.044091 | 1.964499 |
[
"s729237066",
"s007954262"
] |
u597374218
|
p03146
|
python
|
s339441408
|
s660142207
| 32 | 17 | 10,868 | 2,940 |
Accepted
|
Accepted
| 46.88 |
S=int(eval(input()))
l=[0]*1000000
l[0]=0
l[1]=S
for i in range(2,1000000):
if l[i-1]%2==0:
l[i]=l[i-1]//2
else:
l[i]=3*l[i-1]+1
for j in range(1,i-1):
if l[i]==l[j]:
print(i)
exit()
|
S=int(eval(input()))
l=[]
while (S not in l):
l.append(S)
if S%2==0:S//=2
else:S=3*S+1
print((len(l)+1))
| 13 | 7 | 247 | 114 |
S = int(eval(input()))
l = [0] * 1000000
l[0] = 0
l[1] = S
for i in range(2, 1000000):
if l[i - 1] % 2 == 0:
l[i] = l[i - 1] // 2
else:
l[i] = 3 * l[i - 1] + 1
for j in range(1, i - 1):
if l[i] == l[j]:
print(i)
exit()
|
S = int(eval(input()))
l = []
while S not in l:
l.append(S)
if S % 2 == 0:
S //= 2
else:
S = 3 * S + 1
print((len(l) + 1))
| false | 46.153846 |
[
"-l = [0] * 1000000",
"-l[0] = 0",
"-l[1] = S",
"-for i in range(2, 1000000):",
"- if l[i - 1] % 2 == 0:",
"- l[i] = l[i - 1] // 2",
"+l = []",
"+while S not in l:",
"+ l.append(S)",
"+ if S % 2 == 0:",
"+ S //= 2",
"- l[i] = 3 * l[i - 1] + 1",
"- for j in range(1, i - 1):",
"- if l[i] == l[j]:",
"- print(i)",
"- exit()",
"+ S = 3 * S + 1",
"+print((len(l) + 1))"
] | false | 0.130482 | 0.046125 | 2.828888 |
[
"s339441408",
"s660142207"
] |
u312025627
|
p03201
|
python
|
s236071264
|
s006122262
| 687 | 353 | 56,624 | 107,028 |
Accepted
|
Accepted
| 48.62 |
def main():
from collections import Counter
import sys
input = sys.stdin.buffer.readline
_ = int(eval(input()))
A = [int(i) for i in input().split()]
ans = 0
A.sort(reverse=True)
c = Counter(A)
for b in A:
if c[b] == 0:
continue
a = (2 ** b.bit_length()) - b
if a == b:
cur = c[b]//2
else:
cur = min(c[a], c[b])
ans += cur
c[b] -= cur
c[a] -= cur
# print(a, b, c, ans)
print(ans)
if __name__ == '__main__':
main()
|
def main():
from collections import Counter
import sys
input = sys.stdin.buffer.readline
_ = int(eval(input()))
A = [int(i) for i in input().split()]
ans = 0
c = Counter(A)
B = sorted(list(c.keys()), reverse=True)
for b in B:
if c[b] == 0:
continue
a = (2 ** b.bit_length()) - b
if a == b:
cur = c[b]//2
else:
cur = min(c[a], c[b])
ans += cur
# c[b] -= cur
c[a] -= cur
print(ans)
if __name__ == '__main__':
main()
| 30 | 29 | 587 | 572 |
def main():
from collections import Counter
import sys
input = sys.stdin.buffer.readline
_ = int(eval(input()))
A = [int(i) for i in input().split()]
ans = 0
A.sort(reverse=True)
c = Counter(A)
for b in A:
if c[b] == 0:
continue
a = (2 ** b.bit_length()) - b
if a == b:
cur = c[b] // 2
else:
cur = min(c[a], c[b])
ans += cur
c[b] -= cur
c[a] -= cur
# print(a, b, c, ans)
print(ans)
if __name__ == "__main__":
main()
|
def main():
from collections import Counter
import sys
input = sys.stdin.buffer.readline
_ = int(eval(input()))
A = [int(i) for i in input().split()]
ans = 0
c = Counter(A)
B = sorted(list(c.keys()), reverse=True)
for b in B:
if c[b] == 0:
continue
a = (2 ** b.bit_length()) - b
if a == b:
cur = c[b] // 2
else:
cur = min(c[a], c[b])
ans += cur
# c[b] -= cur
c[a] -= cur
print(ans)
if __name__ == "__main__":
main()
| false | 3.333333 |
[
"- A.sort(reverse=True)",
"- for b in A:",
"+ B = sorted(list(c.keys()), reverse=True)",
"+ for b in B:",
"- c[b] -= cur",
"+ # c[b] -= cur",
"- # print(a, b, c, ans)"
] | false | 0.052877 | 0.050502 | 1.047018 |
[
"s236071264",
"s006122262"
] |
u923270446
|
p02536
|
python
|
s323639818
|
s456958199
| 425 | 335 | 48,184 | 13,628 |
Accepted
|
Accepted
| 21.18 |
import sys
sys.setrecursionlimit(2 * (10 ** 6))
n, m = list(map(int, input().split()))
edges = [[] for i in range(n)]
visit = [False for i in range(n)]
def dfs(v):
visit[v] = True
for i in edges[v]:
if not visit[i]:
dfs(i)
for i in range(m):
a, b = list(map(int, input().split()))
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
cnt = 0
for i in range(n):
if not visit[i]:
dfs(i)
cnt += 1
print((cnt - 1))
|
class UnionFind():
def __init__(self, n):
self.n = n
self.par = list(range(self.n))
self.rank = [1] * n
self.cnt = n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
p = self.find(x)
q = self.find(y)
if p == q:
return None
if p > q:
p, q = q, p
self.rank[p] += self.rank[q]
self.par[q] = p
self.cnt -= 1
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return self.rank[x]
def count(self):
return self.cnt
n, m = list(map(int, input().split()))
UF = UnionFind(n)
for _ in range(m):
a, b = list(map(int, input().split()))
UF.unite(a - 1, b - 1)
print((UF.count() - 1))
| 20 | 34 | 476 | 919 |
import sys
sys.setrecursionlimit(2 * (10**6))
n, m = list(map(int, input().split()))
edges = [[] for i in range(n)]
visit = [False for i in range(n)]
def dfs(v):
visit[v] = True
for i in edges[v]:
if not visit[i]:
dfs(i)
for i in range(m):
a, b = list(map(int, input().split()))
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
cnt = 0
for i in range(n):
if not visit[i]:
dfs(i)
cnt += 1
print((cnt - 1))
|
class UnionFind:
def __init__(self, n):
self.n = n
self.par = list(range(self.n))
self.rank = [1] * n
self.cnt = n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
p = self.find(x)
q = self.find(y)
if p == q:
return None
if p > q:
p, q = q, p
self.rank[p] += self.rank[q]
self.par[q] = p
self.cnt -= 1
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return self.rank[x]
def count(self):
return self.cnt
n, m = list(map(int, input().split()))
UF = UnionFind(n)
for _ in range(m):
a, b = list(map(int, input().split()))
UF.unite(a - 1, b - 1)
print((UF.count() - 1))
| false | 41.176471 |
[
"-import sys",
"+class UnionFind:",
"+ def __init__(self, n):",
"+ self.n = n",
"+ self.par = list(range(self.n))",
"+ self.rank = [1] * n",
"+ self.cnt = n",
"-sys.setrecursionlimit(2 * (10**6))",
"-n, m = list(map(int, input().split()))",
"-edges = [[] for i in range(n)]",
"-visit = [False for i in range(n)]",
"+ def find(self, x):",
"+ if self.par[x] == x:",
"+ return x",
"+ else:",
"+ self.par[x] = self.find(self.par[x])",
"+ return self.par[x]",
"+",
"+ def unite(self, x, y):",
"+ p = self.find(x)",
"+ q = self.find(y)",
"+ if p == q:",
"+ return None",
"+ if p > q:",
"+ p, q = q, p",
"+ self.rank[p] += self.rank[q]",
"+ self.par[q] = p",
"+ self.cnt -= 1",
"+",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ def size(self, x):",
"+ return self.rank[x]",
"+",
"+ def count(self):",
"+ return self.cnt",
"-def dfs(v):",
"- visit[v] = True",
"- for i in edges[v]:",
"- if not visit[i]:",
"- dfs(i)",
"-",
"-",
"-for i in range(m):",
"+n, m = list(map(int, input().split()))",
"+UF = UnionFind(n)",
"+for _ in range(m):",
"- edges[a - 1].append(b - 1)",
"- edges[b - 1].append(a - 1)",
"-cnt = 0",
"-for i in range(n):",
"- if not visit[i]:",
"- dfs(i)",
"- cnt += 1",
"-print((cnt - 1))",
"+ UF.unite(a - 1, b - 1)",
"+print((UF.count() - 1))"
] | false | 0.040212 | 0.040621 | 0.989929 |
[
"s323639818",
"s456958199"
] |
u467736898
|
p02905
|
python
|
s928694955
|
s843400033
| 1,829 | 1,685 | 87,988 | 80,496 |
Accepted
|
Accepted
| 7.87 |
def main():
mod = 998244353
max_A = 10**6
N = int(eval(input()))
A = list(map(int, input().split()))
is_prime = [False, True, False, False, False, True] * (max_A//6+1)
del is_prime[max_A+1:]
is_prime[1:4] = False, True, True
for i in range(5, int(max_A**0.5)+1):
if is_prime[i]:
is_prime[i*i::i] = [False] * (max_A//i-i+1)
primes = [p for p, is_p in enumerate(is_prime) if is_p] # max_A 以下の素数のリスト
g = [0] * (max_A+1)
for a in A:
g[a] += a
for p in primes:
# 倍数集合の高速ゼータ変換みたいなやつ O((max_A)loglog(max_A))
# 参考: http://noshi91.hatenablog.com/entry/2018/12/27/121649
# 大量に約数列挙みたいなことをするときはこれで高速化できる場合が多そう?(みんぷろ 2018 本戦 A - Uncommon など)
for k in range(max_A//p, 0, -1):
g[k] += g[k*p]
g = [v * v % mod for v in g]
for p in primes:
for k, g_kp in enumerate(g[p::p], 1):
g[k] -= g_kp
modinv = [0, 1]
for i in range(2, max_A+1):
modinv.append(mod - mod//i * modinv[mod%i] % mod)
ans = sum((gg * minv % mod for gg, minv in zip(g, modinv)))
ans %= mod
ans -= sum(A)
ans *= modinv[2]
ans %= mod
print(ans)
main()
|
# 解説 AC
# 参考1: https://twitter.com/rickytheta/status/1175412019006074880
# 参考2: https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-09-21agc-038
def make_prime_checker(n):
is_prime = [False, True, False, False, False, True] * (n//6+1)
del is_prime[n+1:]
is_prime[1:4] = False, True, True
for i in range(5, int(n**0.5)+1):
if is_prime[i]:
is_prime[i*i::i] = [False] * (n//i-i+1)
return is_prime
def make_modinv_list(n, mod=10**9+7):
# 0 から n までの mod 逆元のリストを返す O(n)
modinv = [0, 1]
for i in range(2, n+1):
modinv.append(mod - mod//i * modinv[mod%i] % mod)
return modinv
def main():
mod = 998244353
max_A = 10**6
N = int(eval(input()))
A = list(map(int, input().split()))
# nまでの自然数が素数かどうかを表すリストを返す O(nloglogn)
primes = [p for p, is_prime in enumerate(make_prime_checker(max_A)) if is_prime] # max_A 以下の素数のリスト
g = [0] * (max_A+1)
for a in A:
g[a] += a
for p in primes:
# 倍数集合の高速ゼータ変換みたいなやつ O((max_A)loglog(max_A))
# 参考: http://noshi91.hatenablog.com/entry/2018/12/27/121649
# 大量に約数列挙みたいなことをするときはこれで高速化できる場合が多そう?(みんぷろ 2018 本戦 A - Uncommon など)
for k in range(max_A//p, 0, -1):
g[k] += g[k*p]
# この時点で g[d] = Σ_{d|a} a (A の要素のうち d の倍数であるものの総和)
g = [v * v % mod for v in g]
# この時点で
# g[d] = (Σ_{d|a} a)(Σ_{d|b} b)
# = Σ_{(d|a)∧(d|b)} ab
# = Σ_{d | gcd(a,b)} ab
# この式変形天才すぎないか?(これを使った一連の操作を gcd 畳み込み というらしい?)
for p in primes:
# 倍数集合の高速メビウス変換みたいなやつ O((max_A)loglog(max_A))
# for k in range(1, max_A//p+1):
# g[k] -= g[k*p] # 包除原理ヤバい
for k, g_kp in enumerate(g[p::p], 1): # 高速化(ゼータ変換の方は途中で g が変化するので高速化できない)
g[k] -= g_kp # 包除原理ヤバい
# この時点で g[d] = Σ_{gcd(a,b)=d} ab
modinv_list = make_modinv_list(max_A, mod)
ans = sum((gg * minv % mod for gg, minv in zip(g, modinv_list)))
ans %= mod
# この時点で
# ans = Σ_d ( Σ_{gcd(a,b)=d} ab/d )
# = Σ_d ( Σ_{gcd(a,b)=d} lcm(a,b) )
# = Σ_a Σ_b lcm(a,b)
ans -= sum(A)
ans *= modinv_list[2]
ans %= mod
# この時点で ans = Σ_{i<j} lcm(a,b)
print(ans)
main()
| 38 | 81 | 1,223 | 2,355 |
def main():
mod = 998244353
max_A = 10**6
N = int(eval(input()))
A = list(map(int, input().split()))
is_prime = [False, True, False, False, False, True] * (max_A // 6 + 1)
del is_prime[max_A + 1 :]
is_prime[1:4] = False, True, True
for i in range(5, int(max_A**0.5) + 1):
if is_prime[i]:
is_prime[i * i :: i] = [False] * (max_A // i - i + 1)
primes = [p for p, is_p in enumerate(is_prime) if is_p] # max_A 以下の素数のリスト
g = [0] * (max_A + 1)
for a in A:
g[a] += a
for p in primes:
# 倍数集合の高速ゼータ変換みたいなやつ O((max_A)loglog(max_A))
# 参考: http://noshi91.hatenablog.com/entry/2018/12/27/121649
# 大量に約数列挙みたいなことをするときはこれで高速化できる場合が多そう?(みんぷろ 2018 本戦 A - Uncommon など)
for k in range(max_A // p, 0, -1):
g[k] += g[k * p]
g = [v * v % mod for v in g]
for p in primes:
for k, g_kp in enumerate(g[p::p], 1):
g[k] -= g_kp
modinv = [0, 1]
for i in range(2, max_A + 1):
modinv.append(mod - mod // i * modinv[mod % i] % mod)
ans = sum((gg * minv % mod for gg, minv in zip(g, modinv)))
ans %= mod
ans -= sum(A)
ans *= modinv[2]
ans %= mod
print(ans)
main()
|
# 解説 AC
# 参考1: https://twitter.com/rickytheta/status/1175412019006074880
# 参考2: https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-09-21agc-038
def make_prime_checker(n):
is_prime = [False, True, False, False, False, True] * (n // 6 + 1)
del is_prime[n + 1 :]
is_prime[1:4] = False, True, True
for i in range(5, int(n**0.5) + 1):
if is_prime[i]:
is_prime[i * i :: i] = [False] * (n // i - i + 1)
return is_prime
def make_modinv_list(n, mod=10**9 + 7):
# 0 から n までの mod 逆元のリストを返す O(n)
modinv = [0, 1]
for i in range(2, n + 1):
modinv.append(mod - mod // i * modinv[mod % i] % mod)
return modinv
def main():
mod = 998244353
max_A = 10**6
N = int(eval(input()))
A = list(map(int, input().split()))
# nまでの自然数が素数かどうかを表すリストを返す O(nloglogn)
primes = [
p for p, is_prime in enumerate(make_prime_checker(max_A)) if is_prime
] # max_A 以下の素数のリスト
g = [0] * (max_A + 1)
for a in A:
g[a] += a
for p in primes:
# 倍数集合の高速ゼータ変換みたいなやつ O((max_A)loglog(max_A))
# 参考: http://noshi91.hatenablog.com/entry/2018/12/27/121649
# 大量に約数列挙みたいなことをするときはこれで高速化できる場合が多そう?(みんぷろ 2018 本戦 A - Uncommon など)
for k in range(max_A // p, 0, -1):
g[k] += g[k * p]
# この時点で g[d] = Σ_{d|a} a (A の要素のうち d の倍数であるものの総和)
g = [v * v % mod for v in g]
# この時点で
# g[d] = (Σ_{d|a} a)(Σ_{d|b} b)
# = Σ_{(d|a)∧(d|b)} ab
# = Σ_{d | gcd(a,b)} ab
# この式変形天才すぎないか?(これを使った一連の操作を gcd 畳み込み というらしい?)
for p in primes:
# 倍数集合の高速メビウス変換みたいなやつ O((max_A)loglog(max_A))
# for k in range(1, max_A//p+1):
# g[k] -= g[k*p] # 包除原理ヤバい
for k, g_kp in enumerate(g[p::p], 1): # 高速化(ゼータ変換の方は途中で g が変化するので高速化できない)
g[k] -= g_kp # 包除原理ヤバい
# この時点で g[d] = Σ_{gcd(a,b)=d} ab
modinv_list = make_modinv_list(max_A, mod)
ans = sum((gg * minv % mod for gg, minv in zip(g, modinv_list)))
ans %= mod
# この時点で
# ans = Σ_d ( Σ_{gcd(a,b)=d} ab/d )
# = Σ_d ( Σ_{gcd(a,b)=d} lcm(a,b) )
# = Σ_a Σ_b lcm(a,b)
ans -= sum(A)
ans *= modinv_list[2]
ans %= mod
# この時点で ans = Σ_{i<j} lcm(a,b)
print(ans)
main()
| false | 53.08642 |
[
"+# 解説 AC",
"+# 参考1: https://twitter.com/rickytheta/status/1175412019006074880",
"+# 参考2: https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-09-21agc-038",
"+def make_prime_checker(n):",
"+ is_prime = [False, True, False, False, False, True] * (n // 6 + 1)",
"+ del is_prime[n + 1 :]",
"+ is_prime[1:4] = False, True, True",
"+ for i in range(5, int(n**0.5) + 1):",
"+ if is_prime[i]:",
"+ is_prime[i * i :: i] = [False] * (n // i - i + 1)",
"+ return is_prime",
"+",
"+",
"+def make_modinv_list(n, mod=10**9 + 7):",
"+ # 0 から n までの mod 逆元のリストを返す O(n)",
"+ modinv = [0, 1]",
"+ for i in range(2, n + 1):",
"+ modinv.append(mod - mod // i * modinv[mod % i] % mod)",
"+ return modinv",
"+",
"+",
"- is_prime = [False, True, False, False, False, True] * (max_A // 6 + 1)",
"- del is_prime[max_A + 1 :]",
"- is_prime[1:4] = False, True, True",
"- for i in range(5, int(max_A**0.5) + 1):",
"- if is_prime[i]:",
"- is_prime[i * i :: i] = [False] * (max_A // i - i + 1)",
"- primes = [p for p, is_p in enumerate(is_prime) if is_p] # max_A 以下の素数のリスト",
"+ # nまでの自然数が素数かどうかを表すリストを返す O(nloglogn)",
"+ primes = [",
"+ p for p, is_prime in enumerate(make_prime_checker(max_A)) if is_prime",
"+ ] # max_A 以下の素数のリスト",
"+ # この時点で g[d] = Σ_{d|a} a (A の要素のうち d の倍数であるものの総和)",
"+ # この時点で",
"+ # g[d] = (Σ_{d|a} a)(Σ_{d|b} b)",
"+ # = Σ_{(d|a)∧(d|b)} ab",
"+ # = Σ_{d | gcd(a,b)} ab",
"+ # この式変形天才すぎないか?(これを使った一連の操作を gcd 畳み込み というらしい?)",
"- for k, g_kp in enumerate(g[p::p], 1):",
"- g[k] -= g_kp",
"- modinv = [0, 1]",
"- for i in range(2, max_A + 1):",
"- modinv.append(mod - mod // i * modinv[mod % i] % mod)",
"- ans = sum((gg * minv % mod for gg, minv in zip(g, modinv)))",
"+ # 倍数集合の高速メビウス変換みたいなやつ O((max_A)loglog(max_A))",
"+ # for k in range(1, max_A//p+1):",
"+ # g[k] -= g[k*p] # 包除原理ヤバい",
"+ for k, g_kp in enumerate(g[p::p], 1): # 高速化(ゼータ変換の方は途中で g が変化するので高速化できない)",
"+ g[k] -= g_kp # 包除原理ヤバい",
"+ # この時点で g[d] = Σ_{gcd(a,b)=d} ab",
"+ modinv_list = make_modinv_list(max_A, mod)",
"+ ans = sum((gg * minv % mod for gg, minv in zip(g, modinv_list)))",
"+ # この時点で",
"+ # ans = Σ_d ( Σ_{gcd(a,b)=d} ab/d )",
"+ # = Σ_d ( Σ_{gcd(a,b)=d} lcm(a,b) )",
"+ # = Σ_a Σ_b lcm(a,b)",
"- ans *= modinv[2]",
"+ ans *= modinv_list[2]",
"+ # この時点で ans = Σ_{i<j} lcm(a,b)"
] | false | 2.357339 | 2.298982 | 1.025384 |
[
"s928694955",
"s843400033"
] |
u738898077
|
p03074
|
python
|
s703100137
|
s152302919
| 100 | 82 | 5,152 | 13,012 |
Accepted
|
Accepted
| 18 |
n,k = list(map(int,input().split()))
s = list(map(int,eval(input())))
s_list = list()
num = s[0]
temp_streak = 0
# temp_max = 0
# temp_sum = 0
[s_list.append(0) for i in range(1+s[0])]
for i in s:
if i == num:
temp_streak += 1
else:
s_list.append(temp_streak)
temp_streak = 1
num = i
s_list.append(temp_streak)
[s_list.append(0) for i in range(1+s[-1])]
# odd = len(s_list)%2
num_i = len(s_list) // 2
# print(s_list)
temp_max = sum(s_list[0:min(k*2+1,len(s_list) + 1)])
temp_sum = temp_max
temp_max_debug = temp_max
# print(temp_max)
for i in range(1,max(num_i+1-k,1)):
temp_sum = temp_sum - s_list[i*2-2] - s_list[i*2-1] + s_list[i*2+k*2-1] + s_list[i*2+k*2]
temp_max = max(temp_max,temp_sum)
# temp_max_debug = max(temp_max_debug,sum(s_list[i*2:i*2+k*2+1]))
print(temp_max)
# print(temp_max_debug)
#print(s_list)
|
n,k = list(map(int,input().split()))
s = eval(input())
ms = 0
ps = 0
temp = [0]
if s[0] == "0":
temp.append(0)
for i in s:
# print(i,ps,ms)
if i == "0":
ms += 1
if ps:
temp.append(ps)
ps = 0
else:
ps += 1
if ms:
temp.append(ms)
ms = 0
if ms:
temp.append(ms)
else:
temp.append(ps)
# print(temp)
temp.append(0)
for i in range(len(temp)-1):
temp[i+1] += temp[i]
# print(temp)
ans = 0
if len(temp)-(2*k+1) <= 0:
ans = temp[-1]
else:
for i in range(0,len(temp)-(2*k+1),2):
ans = max(ans,temp[i+2*k+1]-temp[i])
print(ans)
| 36 | 35 | 895 | 661 |
n, k = list(map(int, input().split()))
s = list(map(int, eval(input())))
s_list = list()
num = s[0]
temp_streak = 0
# temp_max = 0
# temp_sum = 0
[s_list.append(0) for i in range(1 + s[0])]
for i in s:
if i == num:
temp_streak += 1
else:
s_list.append(temp_streak)
temp_streak = 1
num = i
s_list.append(temp_streak)
[s_list.append(0) for i in range(1 + s[-1])]
# odd = len(s_list)%2
num_i = len(s_list) // 2
# print(s_list)
temp_max = sum(s_list[0 : min(k * 2 + 1, len(s_list) + 1)])
temp_sum = temp_max
temp_max_debug = temp_max
# print(temp_max)
for i in range(1, max(num_i + 1 - k, 1)):
temp_sum = (
temp_sum
- s_list[i * 2 - 2]
- s_list[i * 2 - 1]
+ s_list[i * 2 + k * 2 - 1]
+ s_list[i * 2 + k * 2]
)
temp_max = max(temp_max, temp_sum)
# temp_max_debug = max(temp_max_debug,sum(s_list[i*2:i*2+k*2+1]))
print(temp_max)
# print(temp_max_debug)
# print(s_list)
|
n, k = list(map(int, input().split()))
s = eval(input())
ms = 0
ps = 0
temp = [0]
if s[0] == "0":
temp.append(0)
for i in s:
# print(i,ps,ms)
if i == "0":
ms += 1
if ps:
temp.append(ps)
ps = 0
else:
ps += 1
if ms:
temp.append(ms)
ms = 0
if ms:
temp.append(ms)
else:
temp.append(ps)
# print(temp)
temp.append(0)
for i in range(len(temp) - 1):
temp[i + 1] += temp[i]
# print(temp)
ans = 0
if len(temp) - (2 * k + 1) <= 0:
ans = temp[-1]
else:
for i in range(0, len(temp) - (2 * k + 1), 2):
ans = max(ans, temp[i + 2 * k + 1] - temp[i])
print(ans)
| false | 2.777778 |
[
"-s = list(map(int, eval(input())))",
"-s_list = list()",
"-num = s[0]",
"-temp_streak = 0",
"-# temp_max = 0",
"-# temp_sum = 0",
"-[s_list.append(0) for i in range(1 + s[0])]",
"+s = eval(input())",
"+ms = 0",
"+ps = 0",
"+temp = [0]",
"+if s[0] == \"0\":",
"+ temp.append(0)",
"- if i == num:",
"- temp_streak += 1",
"+ # print(i,ps,ms)",
"+ if i == \"0\":",
"+ ms += 1",
"+ if ps:",
"+ temp.append(ps)",
"+ ps = 0",
"- s_list.append(temp_streak)",
"- temp_streak = 1",
"- num = i",
"-s_list.append(temp_streak)",
"-[s_list.append(0) for i in range(1 + s[-1])]",
"-# odd = len(s_list)%2",
"-num_i = len(s_list) // 2",
"-# print(s_list)",
"-temp_max = sum(s_list[0 : min(k * 2 + 1, len(s_list) + 1)])",
"-temp_sum = temp_max",
"-temp_max_debug = temp_max",
"-# print(temp_max)",
"-for i in range(1, max(num_i + 1 - k, 1)):",
"- temp_sum = (",
"- temp_sum",
"- - s_list[i * 2 - 2]",
"- - s_list[i * 2 - 1]",
"- + s_list[i * 2 + k * 2 - 1]",
"- + s_list[i * 2 + k * 2]",
"- )",
"- temp_max = max(temp_max, temp_sum)",
"- # temp_max_debug = max(temp_max_debug,sum(s_list[i*2:i*2+k*2+1]))",
"-print(temp_max)",
"-# print(temp_max_debug)",
"-# print(s_list)",
"+ ps += 1",
"+ if ms:",
"+ temp.append(ms)",
"+ ms = 0",
"+if ms:",
"+ temp.append(ms)",
"+else:",
"+ temp.append(ps)",
"+# print(temp)",
"+temp.append(0)",
"+for i in range(len(temp) - 1):",
"+ temp[i + 1] += temp[i]",
"+# print(temp)",
"+ans = 0",
"+if len(temp) - (2 * k + 1) <= 0:",
"+ ans = temp[-1]",
"+else:",
"+ for i in range(0, len(temp) - (2 * k + 1), 2):",
"+ ans = max(ans, temp[i + 2 * k + 1] - temp[i])",
"+print(ans)"
] | false | 0.034262 | 0.033497 | 1.022842 |
[
"s703100137",
"s152302919"
] |
u086566114
|
p02412
|
python
|
s729015938
|
s565257967
| 160 | 130 | 6,304 | 6,368 |
Accepted
|
Accepted
| 18.75 |
def get_num(n, x):
ans = 0
for n3 in range(min(n, x), (x + 2) / 3, -1):
for n2 in range(n3 - 1, 1, -1):
for n1 in range(n2 - 1, 0, -1):
s = n1 + n2 + n3
if s == x:
ans += 1
break
return ans
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
if x == 0:
print((0))
else:
print((get_num(n, x)))
|
def get_num(n, x):
ans = 0
for n3 in range(min(n, x), (x + 2) / 3, -1):
for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):
for n1 in range(n2 - 1, 0, -1):
s = n1 + n2 + n3
if s == x:
ans += 1
break
return ans
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
if x == 0:
print((0))
else:
print((get_num(n, x)))
| 20 | 20 | 487 | 506 |
def get_num(n, x):
ans = 0
for n3 in range(min(n, x), (x + 2) / 3, -1):
for n2 in range(n3 - 1, 1, -1):
for n1 in range(n2 - 1, 0, -1):
s = n1 + n2 + n3
if s == x:
ans += 1
break
return ans
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
if x == 0:
print((0))
else:
print((get_num(n, x)))
|
def get_num(n, x):
ans = 0
for n3 in range(min(n, x), (x + 2) / 3, -1):
for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):
for n1 in range(n2 - 1, 0, -1):
s = n1 + n2 + n3
if s == x:
ans += 1
break
return ans
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
if x == 0:
print((0))
else:
print((get_num(n, x)))
| false | 0 |
[
"- for n2 in range(n3 - 1, 1, -1):",
"+ for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):"
] | false | 0.102994 | 0.065681 | 1.568101 |
[
"s729015938",
"s565257967"
] |
u254871849
|
p02934
|
python
|
s756118149
|
s816992509
| 32 | 17 | 3,828 | 2,940 |
Accepted
|
Accepted
| 46.88 |
# 2019-11-17 10:52:21(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np
def sum_inverses(a, b):
return a + 1 / b
def main():
n, *a = list(map(int, sys.stdin.read().split()))
ans = 1 / reduce(sum_inverses, a, 0)
print(ans)
if __name__ == "__main__":
main()
|
import sys
n, *A = list(map(int, sys.stdin.read().split()))
def main():
prod = 1
for a in A:
prod *= a
numerator = prod
denominator = 0
for a in A:
denominator += prod // a
return numerator / denominator
if __name__ == '__main__':
ans = main()
print(ans)
| 26 | 19 | 615 | 327 |
# 2019-11-17 10:52:21(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np
def sum_inverses(a, b):
return a + 1 / b
def main():
n, *a = list(map(int, sys.stdin.read().split()))
ans = 1 / reduce(sum_inverses, a, 0)
print(ans)
if __name__ == "__main__":
main()
|
import sys
n, *A = list(map(int, sys.stdin.read().split()))
def main():
prod = 1
for a in A:
prod *= a
numerator = prod
denominator = 0
for a in A:
denominator += prod // a
return numerator / denominator
if __name__ == "__main__":
ans = main()
print(ans)
| false | 26.923077 |
[
"-# 2019-11-17 10:52:21(JST)",
"-# import collections",
"-# import math",
"-# from string import ascii_lowercase, ascii_uppercase, digits",
"-# from bisect import bisect_left as bi_l, bisect_right as bi_r",
"-# import itertools",
"-from functools import reduce",
"-",
"-# import operator as op",
"-# import re",
"-# import heapq",
"-# import array",
"-# from scipy.misc import comb # (default: exact=False)",
"-# import numpy as np",
"-def sum_inverses(a, b):",
"- return a + 1 / b",
"+n, *A = list(map(int, sys.stdin.read().split()))",
"- n, *a = list(map(int, sys.stdin.read().split()))",
"- ans = 1 / reduce(sum_inverses, a, 0)",
"- print(ans)",
"+ prod = 1",
"+ for a in A:",
"+ prod *= a",
"+ numerator = prod",
"+ denominator = 0",
"+ for a in A:",
"+ denominator += prod // a",
"+ return numerator / denominator",
"- main()",
"+ ans = main()",
"+ print(ans)"
] | false | 0.036157 | 0.036664 | 0.986176 |
[
"s756118149",
"s816992509"
] |
u102461423
|
p03718
|
python
|
s961575139
|
s836807314
| 312 | 57 | 4,724 | 7,540 |
Accepted
|
Accepted
| 81.73 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict
H,W = list(map(int,readline().split()))
A = [line.rstrip().decode('utf-8') for line in readlines()]
source = 0
sink = H+W+1
graph = [defaultdict(int) for _ in range(H+W+2)]
INF = 10 ** 18
for h in range(1,H+1):
for w,ox in enumerate(A[h-1],1):
if ox == 'x':
continue
elif ox == 'o':
graph[h][H+w] = 1
graph[H+w][h] = 1
elif ox == 'S':
graph[source][h] = INF
graph[h][source] = INF
graph[source][H+w] = INF
graph[H+w][source] = INF
elif ox == 'T':
graph[sink][h] = INF
graph[h][sink] = INF
graph[sink][H+w] = INF
graph[H+w][sink] = INF
class Dinic():
def __init__(self,graph,V,source,sink):
self.graph = graph
self.sink = sink
self.source = source
self.V = V
# self.compress()
self.N = len(V)
def compress(self):
self.N = len(self.V)
v_to_i = {x:i for i,x in enumerate(self.V)}
self.sink = v_to_i[self.sink]
self.source = v_to_i[self.source]
g = [dict() for _ in range(self.N)]
for v,e in list(self.graph.items()):
vn = v_to_i[v]
g[vn] = {v_to_i[w]:c for w,c in list(e.items())}
self.graph = g
def bfs(self):
level = [0]*self.N
q = [self.source]
level[self.source] = 1
d = 1
while q:
if level[self.sink]:
break
qq = []
d += 1
for v in q:
for w,cap in list(self.graph[v].items()):
if cap == 0:
continue
if level[w]:
continue
level[w] = d
qq.append(w)
q = qq
self.level = level
def dfs(self,v,f):
if v == self.sink:
return f
for w,cap in self.itr[v]:
if cap == 0 or self.level[w] != self.level[v] + 1:
continue
d = self.dfs(w,min(f,cap))
if d:
self.graph[v][w] -= d
self.graph[w][v] += d
return d
return 0
def max_flow(self):
INF = 10**18
flow = 0
while True:
self.bfs()
if self.level[self.sink] == 0:
break
self.itr = [iter(list(e.items())) for e in self.graph]
while True:
f = self.dfs(self.source,INF)
if f == 0:
break
flow += f
return flow
answer = Dinic(graph=graph,V=list(range(H+W+2)),source=0,sink=H+W+1).max_flow()
if answer >= INF:
answer = -1
print(answer)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
H,W = list(map(int,readline().split()))
A = [line.rstrip().decode('utf-8') for line in readlines()]
class Dinic:
def __init__(self, N, source, sink):
self.N = N
self.G = [[] for _ in range(N)]
self.source = source
self.sink = sink
def add_edge(self, fr, to, cap):
n1 = len(self.G[fr])
n2 = len(self.G[to])
self.G[fr].append([to, cap, n2])
self.G[to].append([fr, 0, n1]) # 逆辺を cap 0 で追加
def bfs(self):
level = [0] * self.N
G = self.G; source = self.source; sink = self.sink
q = deque([source])
level[source] = 1
pop = q.popleft; append = q.append
while q:
v = pop()
lv = level[v] + 1
for to, cap, rev in G[v]:
if not cap:
continue
if level[to]:
continue
level[to] = lv
if to == sink:
self.level = level
return
append(to)
self.level = level
def dfs(self,v,f):
if v == self.sink:
return f
G = self.G
prog = self.progress
level = self.level
lv = level[v]
E = G[v]
for i in range(prog[v],len(E)):
to, cap, rev = E[i]
prog[v] = i
if not cap:
continue
if level[to] <= lv:
continue
x = f if f < cap else cap
ff = self.dfs(to, x)
if ff:
E[i][1] -= ff
G[to][rev][1] += ff
return ff
return 0
def max_flow(self):
INF = 10**18
flow = 0
while True:
self.bfs()
if not self.level[self.sink]:
return flow
self.progress = [0] * self.N
while True:
f = self.dfs(self.source, INF)
if not f:
break
flow += f
return flow
source = 0
sink = H+W+1
dinic = Dinic(H+W+2, source, sink)
add = dinic.add_edge
INF = 10 ** 18
for h in range(1,H+1):
for w,ox in enumerate(A[h-1],1):
if ox == 'x':
continue
elif ox == 'o':
add(h,H+w,1)
add(H+w,h,1)
elif ox == 'S':
add(source,h,INF)
add(h,source,INF)
add(source,H+w,INF)
add(H+w,source,INF)
elif ox == 'T':
add(sink,h,INF)
add(h,sink,INF)
add(sink,H+w,INF)
add(H+w,sink,INF)
f = dinic.max_flow()
answer = f if f < INF else -1
print(answer)
| 108 | 110 | 3,016 | 2,942 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict
H, W = list(map(int, readline().split()))
A = [line.rstrip().decode("utf-8") for line in readlines()]
source = 0
sink = H + W + 1
graph = [defaultdict(int) for _ in range(H + W + 2)]
INF = 10**18
for h in range(1, H + 1):
for w, ox in enumerate(A[h - 1], 1):
if ox == "x":
continue
elif ox == "o":
graph[h][H + w] = 1
graph[H + w][h] = 1
elif ox == "S":
graph[source][h] = INF
graph[h][source] = INF
graph[source][H + w] = INF
graph[H + w][source] = INF
elif ox == "T":
graph[sink][h] = INF
graph[h][sink] = INF
graph[sink][H + w] = INF
graph[H + w][sink] = INF
class Dinic:
def __init__(self, graph, V, source, sink):
self.graph = graph
self.sink = sink
self.source = source
self.V = V
# self.compress()
self.N = len(V)
def compress(self):
self.N = len(self.V)
v_to_i = {x: i for i, x in enumerate(self.V)}
self.sink = v_to_i[self.sink]
self.source = v_to_i[self.source]
g = [dict() for _ in range(self.N)]
for v, e in list(self.graph.items()):
vn = v_to_i[v]
g[vn] = {v_to_i[w]: c for w, c in list(e.items())}
self.graph = g
def bfs(self):
level = [0] * self.N
q = [self.source]
level[self.source] = 1
d = 1
while q:
if level[self.sink]:
break
qq = []
d += 1
for v in q:
for w, cap in list(self.graph[v].items()):
if cap == 0:
continue
if level[w]:
continue
level[w] = d
qq.append(w)
q = qq
self.level = level
def dfs(self, v, f):
if v == self.sink:
return f
for w, cap in self.itr[v]:
if cap == 0 or self.level[w] != self.level[v] + 1:
continue
d = self.dfs(w, min(f, cap))
if d:
self.graph[v][w] -= d
self.graph[w][v] += d
return d
return 0
def max_flow(self):
INF = 10**18
flow = 0
while True:
self.bfs()
if self.level[self.sink] == 0:
break
self.itr = [iter(list(e.items())) for e in self.graph]
while True:
f = self.dfs(self.source, INF)
if f == 0:
break
flow += f
return flow
answer = Dinic(
graph=graph, V=list(range(H + W + 2)), source=0, sink=H + W + 1
).max_flow()
if answer >= INF:
answer = -1
print(answer)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
H, W = list(map(int, readline().split()))
A = [line.rstrip().decode("utf-8") for line in readlines()]
class Dinic:
def __init__(self, N, source, sink):
self.N = N
self.G = [[] for _ in range(N)]
self.source = source
self.sink = sink
def add_edge(self, fr, to, cap):
n1 = len(self.G[fr])
n2 = len(self.G[to])
self.G[fr].append([to, cap, n2])
self.G[to].append([fr, 0, n1]) # 逆辺を cap 0 で追加
def bfs(self):
level = [0] * self.N
G = self.G
source = self.source
sink = self.sink
q = deque([source])
level[source] = 1
pop = q.popleft
append = q.append
while q:
v = pop()
lv = level[v] + 1
for to, cap, rev in G[v]:
if not cap:
continue
if level[to]:
continue
level[to] = lv
if to == sink:
self.level = level
return
append(to)
self.level = level
def dfs(self, v, f):
if v == self.sink:
return f
G = self.G
prog = self.progress
level = self.level
lv = level[v]
E = G[v]
for i in range(prog[v], len(E)):
to, cap, rev = E[i]
prog[v] = i
if not cap:
continue
if level[to] <= lv:
continue
x = f if f < cap else cap
ff = self.dfs(to, x)
if ff:
E[i][1] -= ff
G[to][rev][1] += ff
return ff
return 0
def max_flow(self):
INF = 10**18
flow = 0
while True:
self.bfs()
if not self.level[self.sink]:
return flow
self.progress = [0] * self.N
while True:
f = self.dfs(self.source, INF)
if not f:
break
flow += f
return flow
source = 0
sink = H + W + 1
dinic = Dinic(H + W + 2, source, sink)
add = dinic.add_edge
INF = 10**18
for h in range(1, H + 1):
for w, ox in enumerate(A[h - 1], 1):
if ox == "x":
continue
elif ox == "o":
add(h, H + w, 1)
add(H + w, h, 1)
elif ox == "S":
add(source, h, INF)
add(h, source, INF)
add(source, H + w, INF)
add(H + w, source, INF)
elif ox == "T":
add(sink, h, INF)
add(h, sink, INF)
add(sink, H + w, INF)
add(H + w, sink, INF)
f = dinic.max_flow()
answer = f if f < INF else -1
print(answer)
| false | 1.818182 |
[
"-from collections import defaultdict",
"+from collections import deque",
"-source = 0",
"-sink = H + W + 1",
"-graph = [defaultdict(int) for _ in range(H + W + 2)]",
"-INF = 10**18",
"-for h in range(1, H + 1):",
"- for w, ox in enumerate(A[h - 1], 1):",
"- if ox == \"x\":",
"- continue",
"- elif ox == \"o\":",
"- graph[h][H + w] = 1",
"- graph[H + w][h] = 1",
"- elif ox == \"S\":",
"- graph[source][h] = INF",
"- graph[h][source] = INF",
"- graph[source][H + w] = INF",
"- graph[H + w][source] = INF",
"- elif ox == \"T\":",
"- graph[sink][h] = INF",
"- graph[h][sink] = INF",
"- graph[sink][H + w] = INF",
"- graph[H + w][sink] = INF",
"- def __init__(self, graph, V, source, sink):",
"- self.graph = graph",
"+ def __init__(self, N, source, sink):",
"+ self.N = N",
"+ self.G = [[] for _ in range(N)]",
"+ self.source = source",
"- self.source = source",
"- self.V = V",
"- # self.compress()",
"- self.N = len(V)",
"- def compress(self):",
"- self.N = len(self.V)",
"- v_to_i = {x: i for i, x in enumerate(self.V)}",
"- self.sink = v_to_i[self.sink]",
"- self.source = v_to_i[self.source]",
"- g = [dict() for _ in range(self.N)]",
"- for v, e in list(self.graph.items()):",
"- vn = v_to_i[v]",
"- g[vn] = {v_to_i[w]: c for w, c in list(e.items())}",
"- self.graph = g",
"+ def add_edge(self, fr, to, cap):",
"+ n1 = len(self.G[fr])",
"+ n2 = len(self.G[to])",
"+ self.G[fr].append([to, cap, n2])",
"+ self.G[to].append([fr, 0, n1]) # 逆辺を cap 0 で追加",
"- q = [self.source]",
"- level[self.source] = 1",
"- d = 1",
"+ G = self.G",
"+ source = self.source",
"+ sink = self.sink",
"+ q = deque([source])",
"+ level[source] = 1",
"+ pop = q.popleft",
"+ append = q.append",
"- if level[self.sink]:",
"- break",
"- qq = []",
"- d += 1",
"- for v in q:",
"- for w, cap in list(self.graph[v].items()):",
"- if cap == 0:",
"- continue",
"- if level[w]:",
"- continue",
"- level[w] = d",
"- qq.append(w)",
"- q = qq",
"+ v = pop()",
"+ lv = level[v] + 1",
"+ for to, cap, rev in G[v]:",
"+ if not cap:",
"+ continue",
"+ if level[to]:",
"+ continue",
"+ level[to] = lv",
"+ if to == sink:",
"+ self.level = level",
"+ return",
"+ append(to)",
"- for w, cap in self.itr[v]:",
"- if cap == 0 or self.level[w] != self.level[v] + 1:",
"+ G = self.G",
"+ prog = self.progress",
"+ level = self.level",
"+ lv = level[v]",
"+ E = G[v]",
"+ for i in range(prog[v], len(E)):",
"+ to, cap, rev = E[i]",
"+ prog[v] = i",
"+ if not cap:",
"- d = self.dfs(w, min(f, cap))",
"- if d:",
"- self.graph[v][w] -= d",
"- self.graph[w][v] += d",
"- return d",
"+ if level[to] <= lv:",
"+ continue",
"+ x = f if f < cap else cap",
"+ ff = self.dfs(to, x)",
"+ if ff:",
"+ E[i][1] -= ff",
"+ G[to][rev][1] += ff",
"+ return ff",
"- if self.level[self.sink] == 0:",
"- break",
"- self.itr = [iter(list(e.items())) for e in self.graph]",
"+ if not self.level[self.sink]:",
"+ return flow",
"+ self.progress = [0] * self.N",
"- if f == 0:",
"+ if not f:",
"-answer = Dinic(",
"- graph=graph, V=list(range(H + W + 2)), source=0, sink=H + W + 1",
"-).max_flow()",
"-if answer >= INF:",
"- answer = -1",
"+source = 0",
"+sink = H + W + 1",
"+dinic = Dinic(H + W + 2, source, sink)",
"+add = dinic.add_edge",
"+INF = 10**18",
"+for h in range(1, H + 1):",
"+ for w, ox in enumerate(A[h - 1], 1):",
"+ if ox == \"x\":",
"+ continue",
"+ elif ox == \"o\":",
"+ add(h, H + w, 1)",
"+ add(H + w, h, 1)",
"+ elif ox == \"S\":",
"+ add(source, h, INF)",
"+ add(h, source, INF)",
"+ add(source, H + w, INF)",
"+ add(H + w, source, INF)",
"+ elif ox == \"T\":",
"+ add(sink, h, INF)",
"+ add(h, sink, INF)",
"+ add(sink, H + w, INF)",
"+ add(H + w, sink, INF)",
"+f = dinic.max_flow()",
"+answer = f if f < INF else -1"
] | false | 0.039268 | 0.09201 | 0.426778 |
[
"s961575139",
"s836807314"
] |
u222668979
|
p03497
|
python
|
s287628736
|
s211832613
| 172 | 157 | 38,964 | 39,804 |
Accepted
|
Accepted
| 8.72 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ball = {}
for i in a:
if i in list(ball.keys()):
ball[i] += 1
else:
ball[i] = 1
ball = sorted(list(ball.items()), key=lambda x: -x[1])
ans = 0
if len(ball) > k:
for i in range(k):
ans += ball[i][1]
ans = n - ans
print(ans)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ball = {}
for i in a:
if i in ball:
ball[i] += 1
else:
ball[i] = 1
ball = sorted(list(ball.items()), key=lambda x: -x[1])
ans = 0
if len(ball) > k:
for i in range(k):
ans += ball[i][1]
ans = n - ans
print(ans)
| 18 | 18 | 340 | 333 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ball = {}
for i in a:
if i in list(ball.keys()):
ball[i] += 1
else:
ball[i] = 1
ball = sorted(list(ball.items()), key=lambda x: -x[1])
ans = 0
if len(ball) > k:
for i in range(k):
ans += ball[i][1]
ans = n - ans
print(ans)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ball = {}
for i in a:
if i in ball:
ball[i] += 1
else:
ball[i] = 1
ball = sorted(list(ball.items()), key=lambda x: -x[1])
ans = 0
if len(ball) > k:
for i in range(k):
ans += ball[i][1]
ans = n - ans
print(ans)
| false | 0 |
[
"- if i in list(ball.keys()):",
"+ if i in ball:"
] | false | 0.043682 | 0.054637 | 0.799507 |
[
"s287628736",
"s211832613"
] |
u604839890
|
p02837
|
python
|
s756669910
|
s555834853
| 678 | 191 | 9,224 | 9,256 |
Accepted
|
Accepted
| 71.83 |
n = int(eval(input()))
a, xy = [], []
for _ in range(n):
a_t = int(eval(input()))
xy_t = [list(map(int, input().split())) for _ in range(a_t)]
a.append(a_t)
xy.append(xy_t)
ans = 0
for i in range(2**n):
flag = True
for j in range(n):
if (i >> j) & 1:
for k in xy[j]:
if (i >> (k[0]-1)) & 1 != k[1]:
flag = False
if flag:
ans = max(ans, bin(i).count('1'))
print(ans)
|
n = int(eval(input()))
a, xy = [], []
for _ in range(n):
a_t = int(eval(input()))
xy_t = [list(map(int, input().split())) for _ in range(a_t)]
a.append(a_t)
xy.append(xy_t)
ans = 0
for i in range(2**n):
flag = True
for j in range(n):
if (i >> j) & 1:
for k in xy[j]:
if (i >> (k[0]-1)) & 1 != k[1]:
flag = False
break
if flag:
ans = max(ans, bin(i).count('1'))
print(ans)
| 19 | 20 | 464 | 491 |
n = int(eval(input()))
a, xy = [], []
for _ in range(n):
a_t = int(eval(input()))
xy_t = [list(map(int, input().split())) for _ in range(a_t)]
a.append(a_t)
xy.append(xy_t)
ans = 0
for i in range(2**n):
flag = True
for j in range(n):
if (i >> j) & 1:
for k in xy[j]:
if (i >> (k[0] - 1)) & 1 != k[1]:
flag = False
if flag:
ans = max(ans, bin(i).count("1"))
print(ans)
|
n = int(eval(input()))
a, xy = [], []
for _ in range(n):
a_t = int(eval(input()))
xy_t = [list(map(int, input().split())) for _ in range(a_t)]
a.append(a_t)
xy.append(xy_t)
ans = 0
for i in range(2**n):
flag = True
for j in range(n):
if (i >> j) & 1:
for k in xy[j]:
if (i >> (k[0] - 1)) & 1 != k[1]:
flag = False
break
if flag:
ans = max(ans, bin(i).count("1"))
print(ans)
| false | 5 |
[
"+ break"
] | false | 0.04089 | 0.116139 | 0.35208 |
[
"s756669910",
"s555834853"
] |
u620084012
|
p02854
|
python
|
s207543896
|
s385648625
| 276 | 113 | 88,272 | 104,980 |
Accepted
|
Accepted
| 59.06 |
N = int(eval(input()))
A = list(map(int,input().split()))
S = sum(A)
l = S//2
ans = S
s = 0
for k in range(N):
s += A[k]
ans = min(ans,abs(l-s)+abs(S-s-l))
print(ans)
|
N = int(eval(input()))
A = list(map(int,input().split()))
S = sum(A)
T = 0
ans = float("inf")
for e in A:
T += e
ans = min(ans,abs(T-(S-T)))
print(ans)
| 10 | 9 | 178 | 162 |
N = int(eval(input()))
A = list(map(int, input().split()))
S = sum(A)
l = S // 2
ans = S
s = 0
for k in range(N):
s += A[k]
ans = min(ans, abs(l - s) + abs(S - s - l))
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
S = sum(A)
T = 0
ans = float("inf")
for e in A:
T += e
ans = min(ans, abs(T - (S - T)))
print(ans)
| false | 10 |
[
"-l = S // 2",
"-ans = S",
"-s = 0",
"-for k in range(N):",
"- s += A[k]",
"- ans = min(ans, abs(l - s) + abs(S - s - l))",
"+T = 0",
"+ans = float(\"inf\")",
"+for e in A:",
"+ T += e",
"+ ans = min(ans, abs(T - (S - T)))"
] | false | 0.035893 | 0.036412 | 0.985743 |
[
"s207543896",
"s385648625"
] |
u729133443
|
p02811
|
python
|
s178971182
|
s210705584
| 175 | 19 | 38,384 | 3,188 |
Accepted
|
Accepted
| 89.14 |
print(('YNeos'[eval(input().replace(' ','*500<'))::2]))
|
import re;print((re.search('[12].*1',eval(input()))and'No'or'Yes'))
| 1 | 1 | 53 | 59 |
print(("YNeos"[eval(input().replace(" ", "*500<")) :: 2]))
|
import re
print((re.search("[12].*1", eval(input())) and "No" or "Yes"))
| false | 0 |
[
"-print((\"YNeos\"[eval(input().replace(\" \", \"*500<\")) :: 2]))",
"+import re",
"+",
"+print((re.search(\"[12].*1\", eval(input())) and \"No\" or \"Yes\"))"
] | false | 0.150027 | 0.04394 | 3.414344 |
[
"s178971182",
"s210705584"
] |
u600402037
|
p03032
|
python
|
s681113066
|
s813991316
| 35 | 32 | 4,884 | 3,064 |
Accepted
|
Accepted
| 8.57 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
V = lr()
scores = [0]
limit = min(N, K)
for i in range(limit+1): # iは左から取り出す個数
for j in range(limit-i+1): # jは右から取り出す個数
stone = V[:i] + V[N-j:]
stone.sort()
result = sum(stone)
scores.append(result)
for k in range(min(len(stone), K-(i+j))): # kは戻す個数
if stone[k] > 0:
break
result -= stone[k]
scores.append(result)
answer = max(scores)
print(answer)
# 07
|
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
V = lr()
answer = 0
limit = min(N, K)
for i in range(limit+1): # iは左から取り出す個数
for j in range(limit-i+1): # jは右から取り出す個数
stone = V[:i] + V[N-j:]
stone.sort()
result = sum(stone)
if result > answer:
answer = result
for k in range(min(len(stone), K-(i+j))): # kは戻す個数
if stone[k] > 0:
break
result -= stone[k]
if result > answer:
answer = result
print(answer)
# 07
| 26 | 27 | 625 | 659 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
V = lr()
scores = [0]
limit = min(N, K)
for i in range(limit + 1): # iは左から取り出す個数
for j in range(limit - i + 1): # jは右から取り出す個数
stone = V[:i] + V[N - j :]
stone.sort()
result = sum(stone)
scores.append(result)
for k in range(min(len(stone), K - (i + j))): # kは戻す個数
if stone[k] > 0:
break
result -= stone[k]
scores.append(result)
answer = max(scores)
print(answer)
# 07
|
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
V = lr()
answer = 0
limit = min(N, K)
for i in range(limit + 1): # iは左から取り出す個数
for j in range(limit - i + 1): # jは右から取り出す個数
stone = V[:i] + V[N - j :]
stone.sort()
result = sum(stone)
if result > answer:
answer = result
for k in range(min(len(stone), K - (i + j))): # kは戻す個数
if stone[k] > 0:
break
result -= stone[k]
if result > answer:
answer = result
print(answer)
# 07
| false | 3.703704 |
[
"-scores = [0]",
"+answer = 0",
"- scores.append(result)",
"+ if result > answer:",
"+ answer = result",
"- scores.append(result)",
"-answer = max(scores)",
"+ if result > answer:",
"+ answer = result"
] | false | 0.006908 | 0.05368 | 0.128689 |
[
"s681113066",
"s813991316"
] |
u706695185
|
p03262
|
python
|
s271466457
|
s648270777
| 88 | 76 | 16,304 | 14,596 |
Accepted
|
Accepted
| 13.64 |
from functools import reduce
from fractions import gcd
def gcd(a, b):
while b:
a, b = b, a%b
return a
def gcd_list(nums):
return reduce(gcd, nums)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
diff = [abs(xi - X) for xi in x]
print((gcd_list(diff)))
|
from functools import reduce
def gcd(a, b):
while b:
a, b = b, a%b
return a
def gcd_list(nums):
return reduce(gcd, nums)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
diff = [abs(xi - X) for xi in x]
print((gcd_list(diff)))
| 15 | 16 | 314 | 291 |
from functools import reduce
from fractions import gcd
def gcd(a, b):
while b:
a, b = b, a % b
return a
def gcd_list(nums):
return reduce(gcd, nums)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
diff = [abs(xi - X) for xi in x]
print((gcd_list(diff)))
|
from functools import reduce
def gcd(a, b):
while b:
a, b = b, a % b
return a
def gcd_list(nums):
return reduce(gcd, nums)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
diff = [abs(xi - X) for xi in x]
print((gcd_list(diff)))
| false | 6.25 |
[
"-from fractions import gcd"
] | false | 0.056719 | 0.034804 | 1.629679 |
[
"s271466457",
"s648270777"
] |
u498487134
|
p02851
|
python
|
s846637653
|
s944011338
| 340 | 148 | 112,972 | 126,668 |
Accepted
|
Accepted
| 56.47 |
N, K = list(map(int,input().split()))
A = list(map(int, input().split()))
S = [0]*(N+1)
S2 = [0]*(N+1)
dict = {}#最新K件の度数分布の管理
for i in range(N):
S[i+1]=S[i]+A[i]
S2[i+1] =(S[i+1]-i-1)%K
ans =0
for i in range(N+1):
if dict.get(S2[i],0):
ans += dict[S2[i]]
dict[S2[i]]=dict.get(S2[i],0)+1
if i >=K-1:
dict[S2[i-(K-1)]]-=1
print(ans)
|
import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
"""
N^2なので素直に計算は無理,部分和を使いたいのでとりあえず累積和
[i+1:j]が条件を満たすとはS[j]-S[i]とj-iが合同.
移行して,S[j]-jとS[i]-iが合同
基本は個数だけ見れば良い
これだけだと,個数がKより大きい時にダメ
直近Kこの情報だけ持つ,今見てる数字が直近K個のものと何個組にできるか
"""
def main():
mod=10**9+7
N,K=MI()
A=LI()
from collections import defaultdict
dd = defaultdict(int)
S=[0]*(N+1)
for i in range(N):
S[i+1]=(S[i]+A[i])%K
ans=0
for i in range(min(K,N+1)):
temp=(S[i]-i)%K
ans+=dd[temp]
dd[temp]+=1
for i in range(K,N+1):
temp=(S[i]-i)%K
temp_m=(S[(i-K)]-(i-K))%K
dd[temp_m]-=1
ans+=dd[temp]
dd[temp]+=1
print(ans)
main()
| 19 | 50 | 381 | 912 |
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0] * (N + 1)
S2 = [0] * (N + 1)
dict = {} # 最新K件の度数分布の管理
for i in range(N):
S[i + 1] = S[i] + A[i]
S2[i + 1] = (S[i + 1] - i - 1) % K
ans = 0
for i in range(N + 1):
if dict.get(S2[i], 0):
ans += dict[S2[i]]
dict[S2[i]] = dict.get(S2[i], 0) + 1
if i >= K - 1:
dict[S2[i - (K - 1)]] -= 1
print(ans)
|
import sys
input = sys.stdin.readline
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
"""
N^2なので素直に計算は無理,部分和を使いたいのでとりあえず累積和
[i+1:j]が条件を満たすとはS[j]-S[i]とj-iが合同.
移行して,S[j]-jとS[i]-iが合同
基本は個数だけ見れば良い
これだけだと,個数がKより大きい時にダメ
直近Kこの情報だけ持つ,今見てる数字が直近K個のものと何個組にできるか
"""
def main():
mod = 10**9 + 7
N, K = MI()
A = LI()
from collections import defaultdict
dd = defaultdict(int)
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = (S[i] + A[i]) % K
ans = 0
for i in range(min(K, N + 1)):
temp = (S[i] - i) % K
ans += dd[temp]
dd[temp] += 1
for i in range(K, N + 1):
temp = (S[i] - i) % K
temp_m = (S[(i - K)] - (i - K)) % K
dd[temp_m] -= 1
ans += dd[temp]
dd[temp] += 1
print(ans)
main()
| false | 62 |
[
"-N, K = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-S = [0] * (N + 1)",
"-S2 = [0] * (N + 1)",
"-dict = {} # 最新K件の度数分布の管理",
"-for i in range(N):",
"- S[i + 1] = S[i] + A[i]",
"- S2[i + 1] = (S[i + 1] - i - 1) % K",
"-ans = 0",
"-for i in range(N + 1):",
"- if dict.get(S2[i], 0):",
"- ans += dict[S2[i]]",
"- dict[S2[i]] = dict.get(S2[i], 0) + 1",
"- if i >= K - 1:",
"- dict[S2[i - (K - 1)]] -= 1",
"-print(ans)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+\"\"\"",
"+N^2なので素直に計算は無理,部分和を使いたいのでとりあえず累積和",
"+[i+1:j]が条件を満たすとはS[j]-S[i]とj-iが合同.",
"+移行して,S[j]-jとS[i]-iが合同",
"+基本は個数だけ見れば良い",
"+これだけだと,個数がKより大きい時にダメ",
"+直近Kこの情報だけ持つ,今見てる数字が直近K個のものと何個組にできるか",
"+\"\"\"",
"+",
"+",
"+def main():",
"+ mod = 10**9 + 7",
"+ N, K = MI()",
"+ A = LI()",
"+ from collections import defaultdict",
"+",
"+ dd = defaultdict(int)",
"+ S = [0] * (N + 1)",
"+ for i in range(N):",
"+ S[i + 1] = (S[i] + A[i]) % K",
"+ ans = 0",
"+ for i in range(min(K, N + 1)):",
"+ temp = (S[i] - i) % K",
"+ ans += dd[temp]",
"+ dd[temp] += 1",
"+ for i in range(K, N + 1):",
"+ temp = (S[i] - i) % K",
"+ temp_m = (S[(i - K)] - (i - K)) % K",
"+ dd[temp_m] -= 1",
"+ ans += dd[temp]",
"+ dd[temp] += 1",
"+ print(ans)",
"+",
"+",
"+main()"
] | false | 0.047412 | 0.047663 | 0.994721 |
[
"s846637653",
"s944011338"
] |
u077291787
|
p03588
|
python
|
s554791678
|
s111798430
| 181 | 69 | 25,940 | 25,812 |
Accepted
|
Accepted
| 61.88 |
# tenka1-2017-beginnerB - Different Distribution
def main():
N, *AB = list(map(int, open(0).read().split()))
A = [(i, j) for i, j in zip(*[iter(AB)] * 2)]
A.sort()
ans = sum(A[-1])
print(ans)
if __name__ == "__main__":
main()
|
# tenka1-2017-beginnerB - Different Distribution
def main():
N, *AB = list(map(int, open(0).read().split()))
A = max(list(zip(*[iter(AB)] * 2)))
ans = sum(A)
print(ans)
if __name__ == "__main__":
main()
| 11 | 10 | 255 | 221 |
# tenka1-2017-beginnerB - Different Distribution
def main():
N, *AB = list(map(int, open(0).read().split()))
A = [(i, j) for i, j in zip(*[iter(AB)] * 2)]
A.sort()
ans = sum(A[-1])
print(ans)
if __name__ == "__main__":
main()
|
# tenka1-2017-beginnerB - Different Distribution
def main():
N, *AB = list(map(int, open(0).read().split()))
A = max(list(zip(*[iter(AB)] * 2)))
ans = sum(A)
print(ans)
if __name__ == "__main__":
main()
| false | 9.090909 |
[
"- A = [(i, j) for i, j in zip(*[iter(AB)] * 2)]",
"- A.sort()",
"- ans = sum(A[-1])",
"+ A = max(list(zip(*[iter(AB)] * 2)))",
"+ ans = sum(A)"
] | false | 0.036616 | 0.038465 | 0.951939 |
[
"s554791678",
"s111798430"
] |
u327125861
|
p02396
|
python
|
s022105294
|
s033486468
| 150 | 130 | 7,508 | 7,564 |
Accepted
|
Accepted
| 13.33 |
i = 1
while 1:
x = int(eval(input()))
if x == 0:
break
print(("Case " + str(i) + ": " + str(x)))
i = i + 1
|
i = 0
while True:
x = int(eval(input()))
if x == 0: break
i = i + 1
print(("Case " + str(i) + ": " + str(x)))
| 7 | 6 | 110 | 110 |
i = 1
while 1:
x = int(eval(input()))
if x == 0:
break
print(("Case " + str(i) + ": " + str(x)))
i = i + 1
|
i = 0
while True:
x = int(eval(input()))
if x == 0:
break
i = i + 1
print(("Case " + str(i) + ": " + str(x)))
| false | 14.285714 |
[
"-i = 1",
"-while 1:",
"+i = 0",
"+while True:",
"+ i = i + 1",
"- i = i + 1"
] | false | 0.04324 | 0.045594 | 0.948364 |
[
"s022105294",
"s033486468"
] |
u235598818
|
p02699
|
python
|
s840295301
|
s435477353
| 66 | 23 | 61,584 | 9,172 |
Accepted
|
Accepted
| 65.15 |
def main():
S,W=list(map(int,input().split()))
if S<=W:
print("unsafe")
else:
print("safe")
if __name__ == '__main__':
main()
|
S,W=list(map(int,input().split()))
answer="safe"
if S<=W:
answer="unsafe"
print(answer)
| 13 | 5 | 174 | 89 |
def main():
S, W = list(map(int, input().split()))
if S <= W:
print("unsafe")
else:
print("safe")
if __name__ == "__main__":
main()
|
S, W = list(map(int, input().split()))
answer = "safe"
if S <= W:
answer = "unsafe"
print(answer)
| false | 61.538462 |
[
"-def main():",
"- S, W = list(map(int, input().split()))",
"- if S <= W:",
"- print(\"unsafe\")",
"- else:",
"- print(\"safe\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+S, W = list(map(int, input().split()))",
"+answer = \"safe\"",
"+if S <= W:",
"+ answer = \"unsafe\"",
"+print(answer)"
] | false | 0.074843 | 0.036807 | 2.033362 |
[
"s840295301",
"s435477353"
] |
u086566114
|
p02266
|
python
|
s481869817
|
s945138653
| 20 | 10 | 6,856 | 6,860 |
Accepted
|
Accepted
| 50 |
# -*- coding: utf-8 -*-
def main():
down_positions = []
ponds = []
for index, value in enumerate(input()):
if value == '\\':
down_positions.append(index)
elif value == '/' and down_positions:
right = index
left = down_positions.pop()
area = right - left
# candidate_pond = []
area2 = 0
while ponds and left < ponds[-1][0]:
# candidate_pond.append(ponds.pop(-1))
area2 += ponds.pop(-1)[1]
# new_pond = (left, area + sum([x[1] for x in candidate_pond]))
new_pond = (left, area + area2)
ponds.append(new_pond)
print(sum(x[1] for x in ponds))
print(len(ponds), end=' ')
for pond in ponds:
print(pond[1], end=' ')
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
def main():
down_positions = []
ponds = []
for index, value in enumerate(input()):
if value == '\\':
down_positions.append(index)
elif value == '/' and down_positions:
right = index
left = down_positions.pop()
area = right - left
candidate_area = 0
while ponds and left < ponds[-1][0]:
candidate_area += ponds.pop(-1)[1]
# new_pond = (left, area + candidate_area)
ponds.append((left, area + candidate_area))
# ponds.append(new_pond)
print(sum(x[1] for x in ponds))
print(len(ponds), end=' ')
for pond in ponds:
print(pond[1], end=' ')
if __name__ == '__main__':
main()
| 29 | 27 | 867 | 788 |
# -*- coding: utf-8 -*-
def main():
down_positions = []
ponds = []
for index, value in enumerate(input()):
if value == "\\":
down_positions.append(index)
elif value == "/" and down_positions:
right = index
left = down_positions.pop()
area = right - left
# candidate_pond = []
area2 = 0
while ponds and left < ponds[-1][0]:
# candidate_pond.append(ponds.pop(-1))
area2 += ponds.pop(-1)[1]
# new_pond = (left, area + sum([x[1] for x in candidate_pond]))
new_pond = (left, area + area2)
ponds.append(new_pond)
print(sum(x[1] for x in ponds))
print(len(ponds), end=" ")
for pond in ponds:
print(pond[1], end=" ")
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
def main():
down_positions = []
ponds = []
for index, value in enumerate(input()):
if value == "\\":
down_positions.append(index)
elif value == "/" and down_positions:
right = index
left = down_positions.pop()
area = right - left
candidate_area = 0
while ponds and left < ponds[-1][0]:
candidate_area += ponds.pop(-1)[1]
# new_pond = (left, area + candidate_area)
ponds.append((left, area + candidate_area))
# ponds.append(new_pond)
print(sum(x[1] for x in ponds))
print(len(ponds), end=" ")
for pond in ponds:
print(pond[1], end=" ")
if __name__ == "__main__":
main()
| false | 6.896552 |
[
"- # candidate_pond = []",
"- area2 = 0",
"+ candidate_area = 0",
"- # candidate_pond.append(ponds.pop(-1))",
"- area2 += ponds.pop(-1)[1]",
"- # new_pond = (left, area + sum([x[1] for x in candidate_pond]))",
"- new_pond = (left, area + area2)",
"- ponds.append(new_pond)",
"+ candidate_area += ponds.pop(-1)[1]",
"+ # new_pond = (left, area + candidate_area)",
"+ ponds.append((left, area + candidate_area))",
"+ # ponds.append(new_pond)"
] | false | 0.086754 | 0.085831 | 1.010755 |
[
"s481869817",
"s945138653"
] |
u546285759
|
p01223
|
python
|
s710522146
|
s557598045
| 40 | 30 | 7,544 | 7,572 |
Accepted
|
Accepted
| 25 |
for _ in range(int(eval(input()))):
_= int(eval(input()))
upv=dov=0
h= list(map(int, input().split()))
for i in range(len(h)-1):
upv= max(upv, h[i+1]-h[i])
dov= max(dov, h[i]-h[i+1])
print((upv, dov))
|
t = int(eval(input()))
for _ in range(t):
n = int(eval(input()))
h = list(map(int, input().split()))
maxv = minv = 0
for i in range(len(h)-1):
maxv = max(maxv, h[i+1]-h[i])
minv = max(minv, h[i]-h[i+1])
print((maxv, minv))
| 8 | 9 | 229 | 252 |
for _ in range(int(eval(input()))):
_ = int(eval(input()))
upv = dov = 0
h = list(map(int, input().split()))
for i in range(len(h) - 1):
upv = max(upv, h[i + 1] - h[i])
dov = max(dov, h[i] - h[i + 1])
print((upv, dov))
|
t = int(eval(input()))
for _ in range(t):
n = int(eval(input()))
h = list(map(int, input().split()))
maxv = minv = 0
for i in range(len(h) - 1):
maxv = max(maxv, h[i + 1] - h[i])
minv = max(minv, h[i] - h[i + 1])
print((maxv, minv))
| false | 11.111111 |
[
"-for _ in range(int(eval(input()))):",
"- _ = int(eval(input()))",
"- upv = dov = 0",
"+t = int(eval(input()))",
"+for _ in range(t):",
"+ n = int(eval(input()))",
"+ maxv = minv = 0",
"- upv = max(upv, h[i + 1] - h[i])",
"- dov = max(dov, h[i] - h[i + 1])",
"- print((upv, dov))",
"+ maxv = max(maxv, h[i + 1] - h[i])",
"+ minv = max(minv, h[i] - h[i + 1])",
"+ print((maxv, minv))"
] | false | 0.095969 | 0.173826 | 0.552099 |
[
"s710522146",
"s557598045"
] |
u678167152
|
p02684
|
python
|
s652602409
|
s782114379
| 438 | 296 | 236,944 | 184,216 |
Accepted
|
Accepted
| 32.42 |
N, K = list(map(int, input().split()))
A = list([int(x)-1 for x in input().split()])
db = [[0]*N for _ in range(100)]
db[0] = A[:]
for i in range(1,100):
for j in range(N):
db[i][j] = db[i-1][db[i-1][j]]
ans = p = 0
while K>0:
if K%2==1:
ans = db[p][ans]
p += 1
K >>= 1
print((ans+1))
|
N, K = list(map(int, input().split()))
A = list([int(x)-1 for x in input().split()])
db = [[0]*N for _ in range(60)]
db[0] = A[:]
for i in range(1,60):
for j in range(N):
db[i][j] = db[i-1][db[i-1][j]]
ans = p = 0
while K>0:
if K%2==1:
ans = db[p][ans]
p += 1
K >>= 1
print((ans+1))
| 14 | 14 | 310 | 308 |
N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
db = [[0] * N for _ in range(100)]
db[0] = A[:]
for i in range(1, 100):
for j in range(N):
db[i][j] = db[i - 1][db[i - 1][j]]
ans = p = 0
while K > 0:
if K % 2 == 1:
ans = db[p][ans]
p += 1
K >>= 1
print((ans + 1))
|
N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
db = [[0] * N for _ in range(60)]
db[0] = A[:]
for i in range(1, 60):
for j in range(N):
db[i][j] = db[i - 1][db[i - 1][j]]
ans = p = 0
while K > 0:
if K % 2 == 1:
ans = db[p][ans]
p += 1
K >>= 1
print((ans + 1))
| false | 0 |
[
"-db = [[0] * N for _ in range(100)]",
"+db = [[0] * N for _ in range(60)]",
"-for i in range(1, 100):",
"+for i in range(1, 60):"
] | false | 0.036894 | 0.054412 | 0.678055 |
[
"s652602409",
"s782114379"
] |
u997641430
|
p03078
|
python
|
s367555466
|
s353299317
| 1,982 | 1,604 | 161,608 | 160,192 |
Accepted
|
Accepted
| 19.07 |
X, Y, Z, K = list(map(int, input().split()))
*A, = sorted(map(int, input().split()), reverse=True)
*B, = sorted(map(int, input().split()), reverse=True)
*C, = sorted(map(int, input().split()), reverse=True)
AB = [A[x] + B[y] for y in range(Y) for x in range(X)]
AB.sort(reverse=True)
AB = AB[:K]
XY = len(AB)
ABC = [AB[xy] + C[z] for z in range(Z) for xy in range(XY)]
ABC.sort(reverse=True)
for k in range(K):
print((ABC[k]))
|
X, Y, Z, K = list(map(int, input().split()))
*A, = sorted(map(int, input().split()), reverse=True)
*B, = sorted(map(int, input().split()), reverse=True)
*C, = sorted(map(int, input().split()), reverse=True)
AB = [a+b for a in A for b in B]
AB.sort(reverse=True)
AB = AB[:K]
XY = len(AB)
ABC = [ab+c for c in C for ab in AB]
ABC.sort(reverse=True)
ABC = ABC[:K]
for abc in ABC:
print(abc)
| 12 | 13 | 434 | 398 |
X, Y, Z, K = list(map(int, input().split()))
(*A,) = sorted(map(int, input().split()), reverse=True)
(*B,) = sorted(map(int, input().split()), reverse=True)
(*C,) = sorted(map(int, input().split()), reverse=True)
AB = [A[x] + B[y] for y in range(Y) for x in range(X)]
AB.sort(reverse=True)
AB = AB[:K]
XY = len(AB)
ABC = [AB[xy] + C[z] for z in range(Z) for xy in range(XY)]
ABC.sort(reverse=True)
for k in range(K):
print((ABC[k]))
|
X, Y, Z, K = list(map(int, input().split()))
(*A,) = sorted(map(int, input().split()), reverse=True)
(*B,) = sorted(map(int, input().split()), reverse=True)
(*C,) = sorted(map(int, input().split()), reverse=True)
AB = [a + b for a in A for b in B]
AB.sort(reverse=True)
AB = AB[:K]
XY = len(AB)
ABC = [ab + c for c in C for ab in AB]
ABC.sort(reverse=True)
ABC = ABC[:K]
for abc in ABC:
print(abc)
| false | 7.692308 |
[
"-AB = [A[x] + B[y] for y in range(Y) for x in range(X)]",
"+AB = [a + b for a in A for b in B]",
"-ABC = [AB[xy] + C[z] for z in range(Z) for xy in range(XY)]",
"+ABC = [ab + c for c in C for ab in AB]",
"-for k in range(K):",
"- print((ABC[k]))",
"+ABC = ABC[:K]",
"+for abc in ABC:",
"+ print(abc)"
] | false | 0.046019 | 0.03836 | 1.19967 |
[
"s367555466",
"s353299317"
] |
u619458041
|
p03361
|
python
|
s558706635
|
s817982475
| 21 | 19 | 3,064 | 3,064 |
Accepted
|
Accepted
| 9.52 |
import sys
def main():
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [[0 for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
a = [0] + [int(c == '#') for c in input().strip()] + [0]
A[i+1] = a
ans = 'Yes'
for i in range(H):
for j in range(W):
if A[i+1][j+1] == 1:
u, d, r, l = A[i][j+1], A[i+2][j+1], A[i+1][j+2], A[i+1][j]
if any([a == 1 for a in [u, d, r, l]]):
continue
else:
ans = 'No'
break
print(ans)
if __name__ == '__main__':
main()
|
import sys
def main():
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [[0 for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
a = [0] + [c == '#' for c in input().strip()] + [0]
A[i+1] = a
ans = 'Yes'
for i in range(H):
for j in range(W):
if A[i+1][j+1] == 1:
u, d, r, l = A[i][j+1], A[i+2][j+1], A[i+1][j+2], A[i+1][j]
if any([u, d, r, l]):
continue
else:
ans = 'No'
break
print(ans)
if __name__ == '__main__':
main()
| 25 | 25 | 585 | 563 |
import sys
def main():
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [[0 for _ in range(W + 2)] for _ in range(H + 2)]
for i in range(H):
a = [0] + [int(c == "#") for c in input().strip()] + [0]
A[i + 1] = a
ans = "Yes"
for i in range(H):
for j in range(W):
if A[i + 1][j + 1] == 1:
u, d, r, l = A[i][j + 1], A[i + 2][j + 1], A[i + 1][j + 2], A[i + 1][j]
if any([a == 1 for a in [u, d, r, l]]):
continue
else:
ans = "No"
break
print(ans)
if __name__ == "__main__":
main()
|
import sys
def main():
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [[0 for _ in range(W + 2)] for _ in range(H + 2)]
for i in range(H):
a = [0] + [c == "#" for c in input().strip()] + [0]
A[i + 1] = a
ans = "Yes"
for i in range(H):
for j in range(W):
if A[i + 1][j + 1] == 1:
u, d, r, l = A[i][j + 1], A[i + 2][j + 1], A[i + 1][j + 2], A[i + 1][j]
if any([u, d, r, l]):
continue
else:
ans = "No"
break
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"- a = [0] + [int(c == \"#\") for c in input().strip()] + [0]",
"+ a = [0] + [c == \"#\" for c in input().strip()] + [0]",
"- if any([a == 1 for a in [u, d, r, l]]):",
"+ if any([u, d, r, l]):"
] | false | 0.09761 | 0.068123 | 1.432859 |
[
"s558706635",
"s817982475"
] |
u040298438
|
p03681
|
python
|
s407523844
|
s671058657
| 418 | 290 | 11,096 | 10,004 |
Accepted
|
Accepted
| 30.62 |
from math import factorial
n, m = list(map(int, input().split()))
if n == m:
print(((factorial(n) ** 2 * 2) % (10 ** 9 + 7)))
elif abs(n - m) == 1:
print(((factorial(n) * factorial(m)) % (10 ** 9 + 7)))
else:
print((0))
|
from math import factorial
n, m = list(map(int, input().split()))
if n == m:
ans = factorial(n) % (10 ** 9 + 7)
ans = ans ** 2 % (10 ** 9 + 7)
print((ans * 2 % (10 ** 9 + 7)))
elif abs(n - m) == 1:
ans1 = factorial(n) % (10 ** 9 + 7)
ans2 = factorial(m) % (10 ** 9 + 7)
print((ans1 * ans2 % (10 ** 9 + 7)))
else:
print((0))
| 9 | 13 | 228 | 352 |
from math import factorial
n, m = list(map(int, input().split()))
if n == m:
print(((factorial(n) ** 2 * 2) % (10**9 + 7)))
elif abs(n - m) == 1:
print(((factorial(n) * factorial(m)) % (10**9 + 7)))
else:
print((0))
|
from math import factorial
n, m = list(map(int, input().split()))
if n == m:
ans = factorial(n) % (10**9 + 7)
ans = ans**2 % (10**9 + 7)
print((ans * 2 % (10**9 + 7)))
elif abs(n - m) == 1:
ans1 = factorial(n) % (10**9 + 7)
ans2 = factorial(m) % (10**9 + 7)
print((ans1 * ans2 % (10**9 + 7)))
else:
print((0))
| false | 30.769231 |
[
"- print(((factorial(n) ** 2 * 2) % (10**9 + 7)))",
"+ ans = factorial(n) % (10**9 + 7)",
"+ ans = ans**2 % (10**9 + 7)",
"+ print((ans * 2 % (10**9 + 7)))",
"- print(((factorial(n) * factorial(m)) % (10**9 + 7)))",
"+ ans1 = factorial(n) % (10**9 + 7)",
"+ ans2 = factorial(m) % (10**9 + 7)",
"+ print((ans1 * ans2 % (10**9 + 7)))"
] | false | 0.119539 | 0.043748 | 2.732417 |
[
"s407523844",
"s671058657"
] |
u277104886
|
p02695
|
python
|
s263949235
|
s158890585
| 641 | 309 | 22,652 | 9,140 |
Accepted
|
Accepted
| 51.79 |
from _collections import deque
def cacl(seq):
score = 0
for a, b, c, d in req:
if seq[b-1] - seq[a-1] == c:
score += d
return score
n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]
ans = 0
que = deque()
for i in range(1, m+1):
que.append([i])
while que:
seq = que.popleft()
if len(seq) == n:
score = cacl(seq)
ans = max(ans, score)
else:
for i in range(seq[-1], m + 1):
seq_next = seq + [i]
que.append(seq_next)
print(ans)
|
def dfs(seq):
ans = 0
if len(seq) == n:
score = 0
for a, b, c, d in req:
if seq[b-1] - seq[a-1] == c:
score += d
return score
else:
for i in range(seq[-1], m+1):
next_seq = seq + (i,)
score = dfs(next_seq)
ans = max(ans, score)
return ans
n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]
print((dfs((1,))))
| 29 | 20 | 603 | 490 |
from _collections import deque
def cacl(seq):
score = 0
for a, b, c, d in req:
if seq[b - 1] - seq[a - 1] == c:
score += d
return score
n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]
ans = 0
que = deque()
for i in range(1, m + 1):
que.append([i])
while que:
seq = que.popleft()
if len(seq) == n:
score = cacl(seq)
ans = max(ans, score)
else:
for i in range(seq[-1], m + 1):
seq_next = seq + [i]
que.append(seq_next)
print(ans)
|
def dfs(seq):
ans = 0
if len(seq) == n:
score = 0
for a, b, c, d in req:
if seq[b - 1] - seq[a - 1] == c:
score += d
return score
else:
for i in range(seq[-1], m + 1):
next_seq = seq + (i,)
score = dfs(next_seq)
ans = max(ans, score)
return ans
n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]
print((dfs((1,))))
| false | 31.034483 |
[
"-from _collections import deque",
"-",
"-",
"-def cacl(seq):",
"- score = 0",
"- for a, b, c, d in req:",
"- if seq[b - 1] - seq[a - 1] == c:",
"- score += d",
"- return score",
"+def dfs(seq):",
"+ ans = 0",
"+ if len(seq) == n:",
"+ score = 0",
"+ for a, b, c, d in req:",
"+ if seq[b - 1] - seq[a - 1] == c:",
"+ score += d",
"+ return score",
"+ else:",
"+ for i in range(seq[-1], m + 1):",
"+ next_seq = seq + (i,)",
"+ score = dfs(next_seq)",
"+ ans = max(ans, score)",
"+ return ans",
"-ans = 0",
"-que = deque()",
"-for i in range(1, m + 1):",
"- que.append([i])",
"-while que:",
"- seq = que.popleft()",
"- if len(seq) == n:",
"- score = cacl(seq)",
"- ans = max(ans, score)",
"- else:",
"- for i in range(seq[-1], m + 1):",
"- seq_next = seq + [i]",
"- que.append(seq_next)",
"-print(ans)",
"+print((dfs((1,))))"
] | false | 0.09233 | 0.055313 | 1.669228 |
[
"s263949235",
"s158890585"
] |
u736479342
|
p03760
|
python
|
s848603660
|
s556419996
| 28 | 25 | 8,984 | 8,912 |
Accepted
|
Accepted
| 10.71 |
O = list(eval(input()))
E = list(eval(input()))+[""]
o = len(O)
x =[]
for i in range(o):
ans = O[i] + E[i]
x.append(ans)
print(("".join(x)))
|
O = list(input())
E = list(input())+[""]
for o,e in zip(O,E):print(o+e, end="")
| 9 | 3 | 139 | 81 |
O = list(eval(input()))
E = list(eval(input())) + [""]
o = len(O)
x = []
for i in range(o):
ans = O[i] + E[i]
x.append(ans)
print(("".join(x)))
|
O = list(input())
E = list(input()) + [""]
for o, e in zip(O, E):
print(o + e, end="")
| false | 66.666667 |
[
"-O = list(eval(input()))",
"-E = list(eval(input())) + [\"\"]",
"-o = len(O)",
"-x = []",
"-for i in range(o):",
"- ans = O[i] + E[i]",
"- x.append(ans)",
"-print((\"\".join(x)))",
"+O = list(input())",
"+E = list(input()) + [\"\"]",
"+for o, e in zip(O, E):",
"+ print(o + e, end=\"\")"
] | false | 0.042624 | 0.03386 | 1.258806 |
[
"s848603660",
"s556419996"
] |
u226082503
|
p02642
|
python
|
s088078041
|
s650062500
| 390 | 173 | 195,124 | 195,384 |
Accepted
|
Accepted
| 55.64 |
N = int(eval(input()))
A = list(map(int, input().split()))
M = 10**6 + 2
cnt = [0 for _ in range(M)]
A.sort()
for i in A:
if cnt[i] != 0: # cnt[i]がそれまでに出てきた数値で割り切れていたとき
cnt[i] = 2 # cnt[i]の倍数はどうせすでに1か2になっているので考慮しなくていい
continue
j = i
while j < M:
cnt[j] += 1
j += i
ans = 0
for i in A:
if cnt[i] == 1:
ans += 1
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
M = 10**6 + 5
cnt = [0 for _ in range(M)]
for i in A:
if cnt[i] != 0:
cnt[i] = 2
continue
j = i
while j < M:
cnt[j] += 1
j += i
ans = 0
for i in A:
if cnt[i] == 1:
ans += 1
print(ans)
| 19 | 19 | 389 | 316 |
N = int(eval(input()))
A = list(map(int, input().split()))
M = 10**6 + 2
cnt = [0 for _ in range(M)]
A.sort()
for i in A:
if cnt[i] != 0: # cnt[i]がそれまでに出てきた数値で割り切れていたとき
cnt[i] = 2 # cnt[i]の倍数はどうせすでに1か2になっているので考慮しなくていい
continue
j = i
while j < M:
cnt[j] += 1
j += i
ans = 0
for i in A:
if cnt[i] == 1:
ans += 1
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
M = 10**6 + 5
cnt = [0 for _ in range(M)]
for i in A:
if cnt[i] != 0:
cnt[i] = 2
continue
j = i
while j < M:
cnt[j] += 1
j += i
ans = 0
for i in A:
if cnt[i] == 1:
ans += 1
print(ans)
| false | 0 |
[
"-M = 10**6 + 2",
"+M = 10**6 + 5",
"-A.sort()",
"- if cnt[i] != 0: # cnt[i]がそれまでに出てきた数値で割り切れていたとき",
"- cnt[i] = 2 # cnt[i]の倍数はどうせすでに1か2になっているので考慮しなくていい",
"+ if cnt[i] != 0:",
"+ cnt[i] = 2"
] | false | 1.005838 | 0.583998 | 1.72233 |
[
"s088078041",
"s650062500"
] |
u261103969
|
p02699
|
python
|
s773800213
|
s847900296
| 60 | 20 | 61,584 | 9,072 |
Accepted
|
Accepted
| 66.67 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
s, w = list(map(int, readline().split()))
if w >= s:
print("unsafe")
else:
print("safe")
if __name__ == '__main__':
main()
|
s, w = list(map(int, input().split()))
if w >= s:
print("unsafe")
else:
print("safe")
| 19 | 6 | 300 | 99 |
import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
def main():
s, w = list(map(int, readline().split()))
if w >= s:
print("unsafe")
else:
print("safe")
if __name__ == "__main__":
main()
|
s, w = list(map(int, input().split()))
if w >= s:
print("unsafe")
else:
print("safe")
| false | 68.421053 |
[
"-import sys",
"-",
"-readline = sys.stdin.readline",
"-MOD = 10**9 + 7",
"-INF = float(\"INF\")",
"-sys.setrecursionlimit(10**5)",
"-",
"-",
"-def main():",
"- s, w = list(map(int, readline().split()))",
"- if w >= s:",
"- print(\"unsafe\")",
"- else:",
"- print(\"safe\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+s, w = list(map(int, input().split()))",
"+if w >= s:",
"+ print(\"unsafe\")",
"+else:",
"+ print(\"safe\")"
] | false | 0.15238 | 0.037105 | 4.106781 |
[
"s773800213",
"s847900296"
] |
u077291787
|
p02558
|
python
|
s139832963
|
s495190870
| 315 | 276 | 146,408 | 145,288 |
Accepted
|
Accepted
| 12.38 |
from typing import List
class UnionFind:
"""Union Find (Disjoint Set): O(α(N))
References:
https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
"""
__slots__ = ["_data_size", "_roots"]
def __init__(self, data_size: int) -> None:
self._data_size = data_size
self._roots = [-1] * data_size
def __getitem__(self, x: int) -> int:
"""Find the group (root) of vertex x in O(α(n)) amortized."""
while self._roots[x] >= 0:
x = self._roots[x]
return x
def is_connected(self, x: int, y: int) -> bool:
"""Return whether two vertices x and y are connected in O(α(n)) amortized."""
return self[x] == self[y]
def unite(self, x: int, y: int) -> None:
"""Unite two groups of vertices x and y in O(α(n)) amortized."""
x, y = self[x], self[y]
if x == y:
return
if self._roots[x] > self._roots[y]:
x, y = y, x
self._roots[x] += self._roots[y]
self._roots[y] = x
def unionfind():
# https://judge.yosupo.jp/problem/unionfind
# https://atcoder.jp/contests/practice2/tasks/practice2_a
import sys
read = sys.stdin.buffer.read
N, Q, *TUV = list(map(int, read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
if __name__ == "__main__":
unionfind()
|
class UnionFind:
__slots__ = ["_data_size", "_roots"]
def __init__(self, N):
self._data_size = N
self._roots = [-1] * N
def __getitem__(self, x: int) -> int:
while self._roots[x] >= 0:
x = self._roots[x]
return x
def unite(self, x, y):
x = self[x]
y = self[y]
if x == y:
return
elif self._roots[y] < self._roots[x]:
x, y = y, x
self._roots[x] += self._roots[y]
self._roots[y] = x
def is_connected(self, x, y):
return self[x] == self[y]
def main():
import sys
read = sys.stdin.buffer.read
N, Q, *TUV = list(map(int, read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
if __name__ == "__main__":
main()
| 57 | 44 | 1,672 | 998 |
from typing import List
class UnionFind:
"""Union Find (Disjoint Set): O(α(N))
References:
https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
"""
__slots__ = ["_data_size", "_roots"]
def __init__(self, data_size: int) -> None:
self._data_size = data_size
self._roots = [-1] * data_size
def __getitem__(self, x: int) -> int:
"""Find the group (root) of vertex x in O(α(n)) amortized."""
while self._roots[x] >= 0:
x = self._roots[x]
return x
def is_connected(self, x: int, y: int) -> bool:
"""Return whether two vertices x and y are connected in O(α(n)) amortized."""
return self[x] == self[y]
def unite(self, x: int, y: int) -> None:
"""Unite two groups of vertices x and y in O(α(n)) amortized."""
x, y = self[x], self[y]
if x == y:
return
if self._roots[x] > self._roots[y]:
x, y = y, x
self._roots[x] += self._roots[y]
self._roots[y] = x
def unionfind():
# https://judge.yosupo.jp/problem/unionfind
# https://atcoder.jp/contests/practice2/tasks/practice2_a
import sys
read = sys.stdin.buffer.read
N, Q, *TUV = list(map(int, read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
if __name__ == "__main__":
unionfind()
|
class UnionFind:
__slots__ = ["_data_size", "_roots"]
def __init__(self, N):
self._data_size = N
self._roots = [-1] * N
def __getitem__(self, x: int) -> int:
while self._roots[x] >= 0:
x = self._roots[x]
return x
def unite(self, x, y):
x = self[x]
y = self[y]
if x == y:
return
elif self._roots[y] < self._roots[x]:
x, y = y, x
self._roots[x] += self._roots[y]
self._roots[y] = x
def is_connected(self, x, y):
return self[x] == self[y]
def main():
import sys
read = sys.stdin.buffer.read
N, Q, *TUV = list(map(int, read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
if __name__ == "__main__":
main()
| false | 22.807018 |
[
"-from typing import List",
"-",
"-",
"- \"\"\"Union Find (Disjoint Set): O(α(N))",
"- References:",
"- https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp",
"- https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html",
"- \"\"\"",
"-",
"- def __init__(self, data_size: int) -> None:",
"- self._data_size = data_size",
"- self._roots = [-1] * data_size",
"+ def __init__(self, N):",
"+ self._data_size = N",
"+ self._roots = [-1] * N",
"- \"\"\"Find the group (root) of vertex x in O(α(n)) amortized.\"\"\"",
"- def is_connected(self, x: int, y: int) -> bool:",
"- \"\"\"Return whether two vertices x and y are connected in O(α(n)) amortized.\"\"\"",
"- return self[x] == self[y]",
"-",
"- def unite(self, x: int, y: int) -> None:",
"- \"\"\"Unite two groups of vertices x and y in O(α(n)) amortized.\"\"\"",
"- x, y = self[x], self[y]",
"+ def unite(self, x, y):",
"+ x = self[x]",
"+ y = self[y]",
"- if self._roots[x] > self._roots[y]:",
"+ elif self._roots[y] < self._roots[x]:",
"+ def is_connected(self, x, y):",
"+ return self[x] == self[y]",
"-def unionfind():",
"- # https://judge.yosupo.jp/problem/unionfind",
"- # https://atcoder.jp/contests/practice2/tasks/practice2_a",
"+",
"+def main():",
"- unionfind()",
"+ main()"
] | false | 0.034506 | 0.035028 | 0.985097 |
[
"s139832963",
"s495190870"
] |
u818283165
|
p03478
|
python
|
s124077424
|
s278897305
| 41 | 30 | 3,060 | 3,060 |
Accepted
|
Accepted
| 26.83 |
N,A,B = list(map(int,input().split()))
ans = 0
for i in range(N+1):
n = str(i)
a = 0
for j in range(len(n)):
a += int(n[j:j+1])
if a >= A and a <= B:
ans += i
print(ans)
|
N,A,B = list(map(int,input().split()))
def digit_sum(n):
sum = 0
while (n>0):
sum += n%10
n = int(n/10)
return(sum)
ans = 0
for i in range(N+1):
a = digit_sum(i)
if A <= a <= B:
ans += i
# print(i)
print(ans)
| 10 | 15 | 204 | 268 |
N, A, B = list(map(int, input().split()))
ans = 0
for i in range(N + 1):
n = str(i)
a = 0
for j in range(len(n)):
a += int(n[j : j + 1])
if a >= A and a <= B:
ans += i
print(ans)
|
N, A, B = list(map(int, input().split()))
def digit_sum(n):
sum = 0
while n > 0:
sum += n % 10
n = int(n / 10)
return sum
ans = 0
for i in range(N + 1):
a = digit_sum(i)
if A <= a <= B:
ans += i
# print(i)
print(ans)
| false | 33.333333 |
[
"+",
"+",
"+def digit_sum(n):",
"+ sum = 0",
"+ while n > 0:",
"+ sum += n % 10",
"+ n = int(n / 10)",
"+ return sum",
"+",
"+",
"- n = str(i)",
"- a = 0",
"- for j in range(len(n)):",
"- a += int(n[j : j + 1])",
"- if a >= A and a <= B:",
"+ a = digit_sum(i)",
"+ if A <= a <= B:",
"+# print(i)"
] | false | 0.042493 | 0.036255 | 1.17208 |
[
"s124077424",
"s278897305"
] |
u977661421
|
p03319
|
python
|
s353393180
|
s894493375
| 44 | 40 | 13,880 | 13,812 |
Accepted
|
Accepted
| 9.09 |
# -*- coding: utf-8 -*-
n, k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
ans = ((n - 1) + (k - 1) - 1) // (k - 1)
print(ans)
|
import math
n, k = list(map(int,input().split()))
a = list(map(int, input().split()))
ans = math.ceil((n - 1) / (k - 1))
print(ans)
| 6 | 6 | 152 | 131 |
# -*- coding: utf-8 -*-
n, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
ans = ((n - 1) + (k - 1) - 1) // (k - 1)
print(ans)
|
import math
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = math.ceil((n - 1) / (k - 1))
print(ans)
| false | 0 |
[
"-# -*- coding: utf-8 -*-",
"+import math",
"+",
"-a = [int(i) for i in input().split()]",
"-ans = ((n - 1) + (k - 1) - 1) // (k - 1)",
"+a = list(map(int, input().split()))",
"+ans = math.ceil((n - 1) / (k - 1))"
] | false | 0.050438 | 0.051361 | 0.982029 |
[
"s353393180",
"s894493375"
] |
u652656291
|
p03625
|
python
|
s464892147
|
s447661699
| 162 | 103 | 17,424 | 14,252 |
Accepted
|
Accepted
| 36.42 |
n=int(eval(input()))
a=sorted(list(map(int,input().split())),reverse=True)
x,y=0,0
def groupby(a):
a2=[[a[0],1]]
for i in range(1,len(a)):
if a2[-1][0]==a[i]:
a2[-1][1]+=1
else:
a2.append([a[i],1])
return a2
b=groupby(a)
l=len(b)
for i in range(l):
if x==0:
if b[i][1]>=4:
x,y=b[i][0],b[i][0]
elif b[i][1]>=2:
x=b[i][0]
elif y==0:
if b[i][1]>=2:
y=b[i][0]
else:
break
print((x*y))
|
n =int(eval(input()))
a = list(map(int,input().split()))
a.sort()
x,y,i = 0,0,0
while i<n:
if a[i-1] == a[i]:
x,y = y,a[i]
i += 1
i += 1
print((x*y))
| 25 | 10 | 528 | 163 |
n = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)
x, y = 0, 0
def groupby(a):
a2 = [[a[0], 1]]
for i in range(1, len(a)):
if a2[-1][0] == a[i]:
a2[-1][1] += 1
else:
a2.append([a[i], 1])
return a2
b = groupby(a)
l = len(b)
for i in range(l):
if x == 0:
if b[i][1] >= 4:
x, y = b[i][0], b[i][0]
elif b[i][1] >= 2:
x = b[i][0]
elif y == 0:
if b[i][1] >= 2:
y = b[i][0]
else:
break
print((x * y))
|
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
x, y, i = 0, 0, 0
while i < n:
if a[i - 1] == a[i]:
x, y = y, a[i]
i += 1
i += 1
print((x * y))
| false | 60 |
[
"-a = sorted(list(map(int, input().split())), reverse=True)",
"-x, y = 0, 0",
"-",
"-",
"-def groupby(a):",
"- a2 = [[a[0], 1]]",
"- for i in range(1, len(a)):",
"- if a2[-1][0] == a[i]:",
"- a2[-1][1] += 1",
"- else:",
"- a2.append([a[i], 1])",
"- return a2",
"-",
"-",
"-b = groupby(a)",
"-l = len(b)",
"-for i in range(l):",
"- if x == 0:",
"- if b[i][1] >= 4:",
"- x, y = b[i][0], b[i][0]",
"- elif b[i][1] >= 2:",
"- x = b[i][0]",
"- elif y == 0:",
"- if b[i][1] >= 2:",
"- y = b[i][0]",
"- else:",
"- break",
"+a = list(map(int, input().split()))",
"+a.sort()",
"+x, y, i = 0, 0, 0",
"+while i < n:",
"+ if a[i - 1] == a[i]:",
"+ x, y = y, a[i]",
"+ i += 1",
"+ i += 1"
] | false | 0.03763 | 0.042919 | 0.876768 |
[
"s464892147",
"s447661699"
] |
u706414019
|
p02579
|
python
|
s357940273
|
s046373711
| 1,425 | 1,201 | 128,192 | 127,548 |
Accepted
|
Accepted
| 15.72 |
#abc176-d
import sys,math,collections,itertools
input = sys.stdin.readline
H,W=list(map(int,input().split()))
Ch,Cw=list(map(int,input().split()))
Dh,Dw=list(map(int,input().split()))
s=[ input().rstrip() for _ in range(H)]
#DPで遷移が2種類 初期値をinf として、現在値より小さければ遷移可能とする
dp = [ [float('inf') ]*W for _ in range(H)]
q = collections.deque([])
q.append((Ch-1,Cw-1))
dp[Ch-1][Cw-1]=0
while q:
visit = []
while q:
nh,nw = q.popleft()
visit.append((nh,nw))
#徒歩での遷移
if nh>0 and s[nh-1][nw] =='.' and dp[nh-1][nw]>dp[nh][nw]:
q.append((nh-1,nw))
dp[nh-1][nw] = dp[nh][nw]
if nh<H-1 and s[nh+1][nw] =='.' and dp[nh+1][nw]>dp[nh][nw]:
q.append((nh+1,nw))
dp[nh+1][nw] = dp[nh][nw]
if nw>0 and s[nh][nw-1] =='.' and dp[nh][nw-1]>dp[nh][nw]:
q.append((nh,nw-1))
dp[nh][nw-1] = dp[nh][nw]
if nw<W-1 and s[nh][nw+1] =='.' and dp[nh][nw+1]>dp[nh][nw]:
q.append((nh,nw+1))
dp[nh][nw+1] = dp[nh][nw]
while visit:
#ワープで遷移
nh,nw = visit.pop()
for ih in range(-2,3,1):
for iw in range(-2,3,1):
if (0<= nh+ih<=H-1) and (0<=nw+iw<=W-1):
if s[nh+ih][nw+iw] =='.' and dp[nh+ih][nw+iw]>dp[nh][nw]:
q.append((nh+ih,nw+iw))
dp[nh+ih][nw+iw] = dp[nh][nw]+1
ans = dp[Dh-1][Dw-1]
print((-1 if ans==float('inf') else ans))
|
#abc176-d
import sys,math,collections,itertools
input = sys.stdin.readline
H,W=list(map(int,input().split()))
Ch,Cw=list(map(int,input().split()))
Dh,Dw=list(map(int,input().split()))
s=[ input().rstrip() for _ in range(H)]
#DPで遷移が2種類 初期値をinf として、現在値より小さければ遷移可能とする
dp = [ [float('inf') ]*W for _ in range(H)]
q = collections.deque([])
q.append((Ch-1,Cw-1))
dp[Ch-1][Cw-1]=0
while q:#qがある間の遷移 BSF
visit = [] #徒歩で動いたところをメモする
while q:#徒歩用のq
nh,nw = q.popleft()
visit.append((nh,nw))
#徒歩での遷移
move = [(-1,0),(1,0),(0,-1),(0,1)]
for ih,iw in move:
if (0<= nh+ih<=H-1) and (0<=nw+iw<=W-1):
if s[nh+ih][nw+iw] =='.' and dp[nh+ih][nw+iw]>dp[nh][nw]:
q.append((nh+ih,nw+iw))
dp[nh+ih][nw+iw] = dp[nh][nw]
while visit:#徒歩で訪れたところからワープ先を探す
#ワープで遷移
nh,nw = visit.pop()
for ih in range(-2,3,1):
for iw in range(-2,3,1):
if (0<= nh+ih<=H-1) and (0<=nw+iw<=W-1):
if s[nh+ih][nw+iw] =='.' and dp[nh+ih][nw+iw]>dp[nh][nw]:
q.append((nh+ih,nw+iw))
dp[nh+ih][nw+iw] = dp[nh][nw]+1
ans = dp[Dh-1][Dw-1]
print((-1 if ans==float('inf') else ans))
| 47 | 40 | 1,534 | 1,316 |
# abc176-d
import sys, math, collections, itertools
input = sys.stdin.readline
H, W = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
s = [input().rstrip() for _ in range(H)]
# DPで遷移が2種類 初期値をinf として、現在値より小さければ遷移可能とする
dp = [[float("inf")] * W for _ in range(H)]
q = collections.deque([])
q.append((Ch - 1, Cw - 1))
dp[Ch - 1][Cw - 1] = 0
while q:
visit = []
while q:
nh, nw = q.popleft()
visit.append((nh, nw))
# 徒歩での遷移
if nh > 0 and s[nh - 1][nw] == "." and dp[nh - 1][nw] > dp[nh][nw]:
q.append((nh - 1, nw))
dp[nh - 1][nw] = dp[nh][nw]
if nh < H - 1 and s[nh + 1][nw] == "." and dp[nh + 1][nw] > dp[nh][nw]:
q.append((nh + 1, nw))
dp[nh + 1][nw] = dp[nh][nw]
if nw > 0 and s[nh][nw - 1] == "." and dp[nh][nw - 1] > dp[nh][nw]:
q.append((nh, nw - 1))
dp[nh][nw - 1] = dp[nh][nw]
if nw < W - 1 and s[nh][nw + 1] == "." and dp[nh][nw + 1] > dp[nh][nw]:
q.append((nh, nw + 1))
dp[nh][nw + 1] = dp[nh][nw]
while visit:
# ワープで遷移
nh, nw = visit.pop()
for ih in range(-2, 3, 1):
for iw in range(-2, 3, 1):
if (0 <= nh + ih <= H - 1) and (0 <= nw + iw <= W - 1):
if s[nh + ih][nw + iw] == "." and dp[nh + ih][nw + iw] > dp[nh][nw]:
q.append((nh + ih, nw + iw))
dp[nh + ih][nw + iw] = dp[nh][nw] + 1
ans = dp[Dh - 1][Dw - 1]
print((-1 if ans == float("inf") else ans))
|
# abc176-d
import sys, math, collections, itertools
input = sys.stdin.readline
H, W = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
s = [input().rstrip() for _ in range(H)]
# DPで遷移が2種類 初期値をinf として、現在値より小さければ遷移可能とする
dp = [[float("inf")] * W for _ in range(H)]
q = collections.deque([])
q.append((Ch - 1, Cw - 1))
dp[Ch - 1][Cw - 1] = 0
while q: # qがある間の遷移 BSF
visit = [] # 徒歩で動いたところをメモする
while q: # 徒歩用のq
nh, nw = q.popleft()
visit.append((nh, nw))
# 徒歩での遷移
move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for ih, iw in move:
if (0 <= nh + ih <= H - 1) and (0 <= nw + iw <= W - 1):
if s[nh + ih][nw + iw] == "." and dp[nh + ih][nw + iw] > dp[nh][nw]:
q.append((nh + ih, nw + iw))
dp[nh + ih][nw + iw] = dp[nh][nw]
while visit: # 徒歩で訪れたところからワープ先を探す
# ワープで遷移
nh, nw = visit.pop()
for ih in range(-2, 3, 1):
for iw in range(-2, 3, 1):
if (0 <= nh + ih <= H - 1) and (0 <= nw + iw <= W - 1):
if s[nh + ih][nw + iw] == "." and dp[nh + ih][nw + iw] > dp[nh][nw]:
q.append((nh + ih, nw + iw))
dp[nh + ih][nw + iw] = dp[nh][nw] + 1
ans = dp[Dh - 1][Dw - 1]
print((-1 if ans == float("inf") else ans))
| false | 14.893617 |
[
"-while q:",
"- visit = []",
"- while q:",
"+while q: # qがある間の遷移 BSF",
"+ visit = [] # 徒歩で動いたところをメモする",
"+ while q: # 徒歩用のq",
"- if nh > 0 and s[nh - 1][nw] == \".\" and dp[nh - 1][nw] > dp[nh][nw]:",
"- q.append((nh - 1, nw))",
"- dp[nh - 1][nw] = dp[nh][nw]",
"- if nh < H - 1 and s[nh + 1][nw] == \".\" and dp[nh + 1][nw] > dp[nh][nw]:",
"- q.append((nh + 1, nw))",
"- dp[nh + 1][nw] = dp[nh][nw]",
"- if nw > 0 and s[nh][nw - 1] == \".\" and dp[nh][nw - 1] > dp[nh][nw]:",
"- q.append((nh, nw - 1))",
"- dp[nh][nw - 1] = dp[nh][nw]",
"- if nw < W - 1 and s[nh][nw + 1] == \".\" and dp[nh][nw + 1] > dp[nh][nw]:",
"- q.append((nh, nw + 1))",
"- dp[nh][nw + 1] = dp[nh][nw]",
"- while visit:",
"+ move = [(-1, 0), (1, 0), (0, -1), (0, 1)]",
"+ for ih, iw in move:",
"+ if (0 <= nh + ih <= H - 1) and (0 <= nw + iw <= W - 1):",
"+ if s[nh + ih][nw + iw] == \".\" and dp[nh + ih][nw + iw] > dp[nh][nw]:",
"+ q.append((nh + ih, nw + iw))",
"+ dp[nh + ih][nw + iw] = dp[nh][nw]",
"+ while visit: # 徒歩で訪れたところからワープ先を探す"
] | false | 0.047492 | 0.16254 | 0.292184 |
[
"s357940273",
"s046373711"
] |
u631277801
|
p03611
|
python
|
s023135566
|
s904267114
| 162 | 109 | 30,684 | 29,960 |
Accepted
|
Accepted
| 32.72 |
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A_p1 = [a+1 for a in A]
A_m1 = [a-1 for a in A]
cnt = Counter(A_p1)
cnt += Counter(A)
cnt += Counter(A_m1)
print((max(list(cnt.values()))))
|
import sys
stdin = sys.stdin
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 collections import Counter
n = ni()
a = list(li())
ap = [ai+1 for ai in a]
am = [ai-1 for ai in a]
cnt = Counter(am+a+ap)
print((cnt.most_common(1)[0][1]))
| 13 | 23 | 238 | 582 |
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A_p1 = [a + 1 for a in A]
A_m1 = [a - 1 for a in A]
cnt = Counter(A_p1)
cnt += Counter(A)
cnt += Counter(A_m1)
print((max(list(cnt.values()))))
|
import sys
stdin = sys.stdin
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 collections import Counter
n = ni()
a = list(li())
ap = [ai + 1 for ai in a]
am = [ai - 1 for ai in a]
cnt = Counter(am + a + ap)
print((cnt.most_common(1)[0][1]))
| false | 43.478261 |
[
"+import sys",
"+",
"+stdin = sys.stdin",
"+",
"+",
"+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())",
"+",
"+",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-A_p1 = [a + 1 for a in A]",
"-A_m1 = [a - 1 for a in A]",
"-cnt = Counter(A_p1)",
"-cnt += Counter(A)",
"-cnt += Counter(A_m1)",
"-print((max(list(cnt.values()))))",
"+n = ni()",
"+a = list(li())",
"+ap = [ai + 1 for ai in a]",
"+am = [ai - 1 for ai in a]",
"+cnt = Counter(am + a + ap)",
"+print((cnt.most_common(1)[0][1]))"
] | false | 0.044637 | 0.044159 | 1.010837 |
[
"s023135566",
"s904267114"
] |
u934442292
|
p03161
|
python
|
s053525925
|
s244709051
| 736 | 641 | 111,652 | 121,828 |
Accepted
|
Accepted
| 12.91 |
import sys
import numba as nb
import numpy as np
input = sys.stdin.readline
INF = float("inf")
@nb.njit
def solve(N, K, h):
dp = [0] * N
for i in range(1, N):
min_cost = INF
for k in range(1, min(K + 1, i + 1)):
cost = dp[i - k] + abs(h[i] - h[i - k])
if cost < min_cost:
min_cost = cost
dp[i] = min_cost
return dp[-1]
def main():
N, K = list(map(int, input().split()))
h = np.array(input().split(), dtype=np.int64)
ans = solve(N, K, h)
print(ans)
if __name__ == "__main__":
main()
|
import sys
import numba as nb
import numpy as np
input = sys.stdin.readline
INF = float("inf")
@nb.njit("i8(i8,i8,i8[:])")
def solve(N, K, h):
dp = [0] * N
for i in range(1, N):
min_cost = INF
for k in range(1, min(K + 1, i + 1)):
cost = dp[i - k] + abs(h[i] - h[i - k])
if cost < min_cost:
min_cost = cost
dp[i] = min_cost
return dp[-1]
def main():
N, K = list(map(int, input().split()))
h = np.array(input().split(), dtype=np.int64)
ans = solve(N, K, h)
print(ans)
if __name__ == "__main__":
main()
| 32 | 32 | 612 | 631 |
import sys
import numba as nb
import numpy as np
input = sys.stdin.readline
INF = float("inf")
@nb.njit
def solve(N, K, h):
dp = [0] * N
for i in range(1, N):
min_cost = INF
for k in range(1, min(K + 1, i + 1)):
cost = dp[i - k] + abs(h[i] - h[i - k])
if cost < min_cost:
min_cost = cost
dp[i] = min_cost
return dp[-1]
def main():
N, K = list(map(int, input().split()))
h = np.array(input().split(), dtype=np.int64)
ans = solve(N, K, h)
print(ans)
if __name__ == "__main__":
main()
|
import sys
import numba as nb
import numpy as np
input = sys.stdin.readline
INF = float("inf")
@nb.njit("i8(i8,i8,i8[:])")
def solve(N, K, h):
dp = [0] * N
for i in range(1, N):
min_cost = INF
for k in range(1, min(K + 1, i + 1)):
cost = dp[i - k] + abs(h[i] - h[i - k])
if cost < min_cost:
min_cost = cost
dp[i] = min_cost
return dp[-1]
def main():
N, K = list(map(int, input().split()))
h = np.array(input().split(), dtype=np.int64)
ans = solve(N, K, h)
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"[email protected]",
"[email protected](\"i8(i8,i8,i8[:])\")"
] | false | 0.056094 | 0.081351 | 0.689532 |
[
"s053525925",
"s244709051"
] |
u135389999
|
p02687
|
python
|
s242724143
|
s672921962
| 23 | 21 | 9,024 | 9,076 |
Accepted
|
Accepted
| 8.7 |
n = str(eval(input()))
if n == "ABC":
print("ARC")
else:
print("ABC")
|
S = eval(input())
if S == "ABC":
print("ARC")
else:
print("ABC")
| 6 | 5 | 77 | 66 |
n = str(eval(input()))
if n == "ABC":
print("ARC")
else:
print("ABC")
|
S = eval(input())
if S == "ABC":
print("ARC")
else:
print("ABC")
| false | 16.666667 |
[
"-n = str(eval(input()))",
"-if n == \"ABC\":",
"+S = eval(input())",
"+if S == \"ABC\":"
] | false | 0.047275 | 0.035862 | 1.318247 |
[
"s242724143",
"s672921962"
] |
u952708174
|
p03078
|
python
|
s125802808
|
s591592823
| 976 | 576 | 138,736 | 4,084 |
Accepted
|
Accepted
| 40.98 |
def d_cake_123_sort_modified(X, Y, Z, K, A, B, C):
# editionalの解法1
ab = sorted([a + b for b in B for a in A], reverse=True)[:K]
ans = sorted([e + c for e in ab for c in C], reverse=True)[:K]
return ' '.join(map(str, ans))
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print((d_cake_123_sort_modified(X, Y, Z, K, A, B, C)))
|
def d_cake_123_priority_queue(X, Y, Z, K, A, B, C):
# editionalの解法3
import heapq
# 数列A, B, Cを降順ソート
a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)
def evaluation(x, y, z):
# heapqは最小値を取り出す方式なので、符号を反転させないといけない
return (-(a[x] + b[y] + c[z]), x, y, z)
# priority queue を定義し、(A_1 + B_1 + C_1, 1, 1, 1) を追加
q = []
heapq.heappush(q, evaluation(0, 0, 0))
ans = []
# priority queueに対するK回の操作の部分
for _ in range(K):
(e, x, y, z) = heapq.heappop(q)
ans.append(-e)
if x + 1 < X and evaluation(x + 1, y, z) not in q:
heapq.heappush(q, evaluation(x + 1, y, z))
if y + 1 < Y and evaluation(x, y + 1, z) not in q:
heapq.heappush(q, evaluation(x, y + 1, z))
if z + 1 < Z and evaluation(x, y, z + 1) not in q:
heapq.heappush(q, evaluation(x, y, z + 1))
return '\n'.join(map(str, ans[:K]))
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print((d_cake_123_priority_queue(X, Y, Z, K, A, B, C)))
| 11 | 32 | 462 | 1,195 |
def d_cake_123_sort_modified(X, Y, Z, K, A, B, C):
# editionalの解法1
ab = sorted([a + b for b in B for a in A], reverse=True)[:K]
ans = sorted([e + c for e in ab for c in C], reverse=True)[:K]
return " ".join(map(str, ans))
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print((d_cake_123_sort_modified(X, Y, Z, K, A, B, C)))
|
def d_cake_123_priority_queue(X, Y, Z, K, A, B, C):
# editionalの解法3
import heapq
# 数列A, B, Cを降順ソート
a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)
def evaluation(x, y, z):
# heapqは最小値を取り出す方式なので、符号を反転させないといけない
return (-(a[x] + b[y] + c[z]), x, y, z)
# priority queue を定義し、(A_1 + B_1 + C_1, 1, 1, 1) を追加
q = []
heapq.heappush(q, evaluation(0, 0, 0))
ans = []
# priority queueに対するK回の操作の部分
for _ in range(K):
(e, x, y, z) = heapq.heappop(q)
ans.append(-e)
if x + 1 < X and evaluation(x + 1, y, z) not in q:
heapq.heappush(q, evaluation(x + 1, y, z))
if y + 1 < Y and evaluation(x, y + 1, z) not in q:
heapq.heappush(q, evaluation(x, y + 1, z))
if z + 1 < Z and evaluation(x, y, z + 1) not in q:
heapq.heappush(q, evaluation(x, y, z + 1))
return "\n".join(map(str, ans[:K]))
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print((d_cake_123_priority_queue(X, Y, Z, K, A, B, C)))
| false | 65.625 |
[
"-def d_cake_123_sort_modified(X, Y, Z, K, A, B, C):",
"- # editionalの解法1",
"- ab = sorted([a + b for b in B for a in A], reverse=True)[:K]",
"- ans = sorted([e + c for e in ab for c in C], reverse=True)[:K]",
"- return \" \".join(map(str, ans))",
"+def d_cake_123_priority_queue(X, Y, Z, K, A, B, C):",
"+ # editionalの解法3",
"+ import heapq",
"+",
"+ # 数列A, B, Cを降順ソート",
"+ a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)",
"+",
"+ def evaluation(x, y, z):",
"+ # heapqは最小値を取り出す方式なので、符号を反転させないといけない",
"+ return (-(a[x] + b[y] + c[z]), x, y, z)",
"+",
"+ # priority queue を定義し、(A_1 + B_1 + C_1, 1, 1, 1) を追加",
"+ q = []",
"+ heapq.heappush(q, evaluation(0, 0, 0))",
"+ ans = []",
"+ # priority queueに対するK回の操作の部分",
"+ for _ in range(K):",
"+ (e, x, y, z) = heapq.heappop(q)",
"+ ans.append(-e)",
"+ if x + 1 < X and evaluation(x + 1, y, z) not in q:",
"+ heapq.heappush(q, evaluation(x + 1, y, z))",
"+ if y + 1 < Y and evaluation(x, y + 1, z) not in q:",
"+ heapq.heappush(q, evaluation(x, y + 1, z))",
"+ if z + 1 < Z and evaluation(x, y, z + 1) not in q:",
"+ heapq.heappush(q, evaluation(x, y, z + 1))",
"+ return \"\\n\".join(map(str, ans[:K]))",
"-print((d_cake_123_sort_modified(X, Y, Z, K, A, B, C)))",
"+print((d_cake_123_priority_queue(X, Y, Z, K, A, B, C)))"
] | false | 0.047813 | 0.042004 | 1.138302 |
[
"s125802808",
"s591592823"
] |
u888337853
|
p03112
|
python
|
s731153757
|
s296655255
| 983 | 579 | 19,184 | 19,140 |
Accepted
|
Accepted
| 41.1 |
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])
# ===CODE===
def disLR(a, idx):
small = a[max(0, idx - 1)]
large = a[min(len(a) - 1, idx)]
return small, large
def main():
a, b, q = ns()
s = [ni() for _ in range(a)]
t = [ni() for _ in range(b)]
for _ in range(q):
ans = INF
x = ni()
tmpans = [0] * 4
idxs = bisect.bisect_left(s, x)
sml, lrg = disLR(s, idxs)
tmpans[0] += abs(x - sml)
tmpans[1] += abs(x - lrg)
idxsml = bisect.bisect_left(t, sml)
tmpans[0] += min([abs(sml - i) for i in disLR(t, idxsml)])
idxlrg = bisect.bisect_left(t, lrg)
tmpans[1] += min([abs(lrg - i) for i in disLR(t, idxlrg)])
idxt = bisect.bisect_left(t, x)
sml, lrg = disLR(t, idxt)
tmpans[2] += abs(x - sml)
tmpans[3] += abs(x - lrg)
idxsml = bisect.bisect_left(s, sml)
tmpans[2] += min([abs(sml - i) for i in disLR(s, idxsml)])
idxlrg = bisect.bisect_left(s, lrg)
tmpans[3] += min([abs(lrg - i) for i in disLR(s, idxlrg)])
ans = min(ans, min(tmpans))
print(ans)
if __name__ == '__main__':
main()
|
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])
# ===CODE===
def disLR(a, idx):
small = a[max(0, idx - 1)]
large = a[min(len(a) - 1, idx)]
return [small, large]
def main():
a, b, q = ns()
s = [ni() for _ in range(a)]
t = [ni() for _ in range(b)]
for _ in range(q):
ans = INF
x = ni()
idxs = bisect.bisect_left(s, x)
a1 = disLR(s, idxs)
idxt = bisect.bisect_left(t, x)
a2 = disLR(t, idxt)
for ta1 in a1:
for ta2 in a2:
tmp1 = abs(x - ta1) + abs(ta2 - ta1)
tmp2 = abs(x - ta2) + abs(ta1 - ta2)
ans = min(ans, tmp1, tmp2)
print(ans)
if __name__ == '__main__':
main()
| 69 | 62 | 1,722 | 1,265 |
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10**9)
INF = 10**16
MOD = 10**9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])
# ===CODE===
def disLR(a, idx):
small = a[max(0, idx - 1)]
large = a[min(len(a) - 1, idx)]
return small, large
def main():
a, b, q = ns()
s = [ni() for _ in range(a)]
t = [ni() for _ in range(b)]
for _ in range(q):
ans = INF
x = ni()
tmpans = [0] * 4
idxs = bisect.bisect_left(s, x)
sml, lrg = disLR(s, idxs)
tmpans[0] += abs(x - sml)
tmpans[1] += abs(x - lrg)
idxsml = bisect.bisect_left(t, sml)
tmpans[0] += min([abs(sml - i) for i in disLR(t, idxsml)])
idxlrg = bisect.bisect_left(t, lrg)
tmpans[1] += min([abs(lrg - i) for i in disLR(t, idxlrg)])
idxt = bisect.bisect_left(t, x)
sml, lrg = disLR(t, idxt)
tmpans[2] += abs(x - sml)
tmpans[3] += abs(x - lrg)
idxsml = bisect.bisect_left(s, sml)
tmpans[2] += min([abs(sml - i) for i in disLR(s, idxsml)])
idxlrg = bisect.bisect_left(s, lrg)
tmpans[3] += min([abs(lrg - i) for i in disLR(s, idxlrg)])
ans = min(ans, min(tmpans))
print(ans)
if __name__ == "__main__":
main()
|
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10**9)
INF = 10**16
MOD = 10**9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])
# ===CODE===
def disLR(a, idx):
small = a[max(0, idx - 1)]
large = a[min(len(a) - 1, idx)]
return [small, large]
def main():
a, b, q = ns()
s = [ni() for _ in range(a)]
t = [ni() for _ in range(b)]
for _ in range(q):
ans = INF
x = ni()
idxs = bisect.bisect_left(s, x)
a1 = disLR(s, idxs)
idxt = bisect.bisect_left(t, x)
a2 = disLR(t, idxt)
for ta1 in a1:
for ta2 in a2:
tmp1 = abs(x - ta1) + abs(ta2 - ta1)
tmp2 = abs(x - ta2) + abs(ta1 - ta2)
ans = min(ans, tmp1, tmp2)
print(ans)
if __name__ == "__main__":
main()
| false | 10.144928 |
[
"- return small, large",
"+ return [small, large]",
"- tmpans = [0] * 4",
"- sml, lrg = disLR(s, idxs)",
"- tmpans[0] += abs(x - sml)",
"- tmpans[1] += abs(x - lrg)",
"- idxsml = bisect.bisect_left(t, sml)",
"- tmpans[0] += min([abs(sml - i) for i in disLR(t, idxsml)])",
"- idxlrg = bisect.bisect_left(t, lrg)",
"- tmpans[1] += min([abs(lrg - i) for i in disLR(t, idxlrg)])",
"+ a1 = disLR(s, idxs)",
"- sml, lrg = disLR(t, idxt)",
"- tmpans[2] += abs(x - sml)",
"- tmpans[3] += abs(x - lrg)",
"- idxsml = bisect.bisect_left(s, sml)",
"- tmpans[2] += min([abs(sml - i) for i in disLR(s, idxsml)])",
"- idxlrg = bisect.bisect_left(s, lrg)",
"- tmpans[3] += min([abs(lrg - i) for i in disLR(s, idxlrg)])",
"- ans = min(ans, min(tmpans))",
"+ a2 = disLR(t, idxt)",
"+ for ta1 in a1:",
"+ for ta2 in a2:",
"+ tmp1 = abs(x - ta1) + abs(ta2 - ta1)",
"+ tmp2 = abs(x - ta2) + abs(ta1 - ta2)",
"+ ans = min(ans, tmp1, tmp2)"
] | false | 0.037112 | 0.044902 | 0.826506 |
[
"s731153757",
"s296655255"
] |
u646336881
|
p02707
|
python
|
s322856930
|
s384616426
| 336 | 187 | 132,496 | 124,988 |
Accepted
|
Accepted
| 44.35 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, A: "List[int]"):
c = collections.Counter(A+[i+1 for i in range(N)])
return "\n".join([f'{c[i+1]-1}' for i in range(N)])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N - 2 + 1)] # type: "List[int]"
print((solve(N, A)))
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, A: "List[int]"):
c = collections.Counter(A)
return "\n".join([f'{c[i+1]}' for i in range(N)])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N - 2 + 1)] # type: "List[int]"
print((solve(N, A)))
if __name__ == '__main__':
main()
| 32 | 32 | 744 | 718 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float("inf")
def solve(N: int, A: "List[int]"):
c = collections.Counter(A + [i + 1 for i in range(N)])
return "\n".join([f"{c[i+1]-1}" for i in range(N)])
def main():
sys.setrecursionlimit(10**6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N - 2 + 1)] # type: "List[int]"
print((solve(N, A)))
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float("inf")
def solve(N: int, A: "List[int]"):
c = collections.Counter(A)
return "\n".join([f"{c[i+1]}" for i in range(N)])
def main():
sys.setrecursionlimit(10**6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N - 2 + 1)] # type: "List[int]"
print((solve(N, A)))
if __name__ == "__main__":
main()
| false | 0 |
[
"- c = collections.Counter(A + [i + 1 for i in range(N)])",
"- return \"\\n\".join([f\"{c[i+1]-1}\" for i in range(N)])",
"+ c = collections.Counter(A)",
"+ return \"\\n\".join([f\"{c[i+1]}\" for i in range(N)])"
] | false | 0.040568 | 0.043392 | 0.934926 |
[
"s322856930",
"s384616426"
] |
u861471387
|
p02665
|
python
|
s490377650
|
s997026575
| 225 | 156 | 86,576 | 83,452 |
Accepted
|
Accepted
| 30.67 |
N = int(eval(input()))
A = list(map(int,input().split()))
P=[0]*(N+1)
P[N]=A[N]
Q=[0]*(N+1)
Q[N]=A[N]
for i in range(N,0,-1):
mxp=P[i]+A[i-1]
mnp=(P[i]//2) + (P[i]%2) +A[i-1]
mxq=Q[i]+A[i-1]
mnq=(Q[i]//2) + (Q[i]%2) +A[i-1]
if mnp>2**i:
print((-1))
exit()
P[i-1]=mnp
Q[i-1]=min(mxq,2**i)
if P[0]!=1:
print((-1))
exit()
Q[0]=1
for i in range(1,N):
if Q[i]>2**i:
Q[i]=2**i
if Q[i]>(Q[i-1]-A[i-1])*2:
Q[i]=(Q[i-1]-A[i-1])*2
print((sum(Q)))
|
N = int(eval(input()))
A = list(map(int,input().split()))
P=[0]*(N+1)
P[N]=A[N]
Q=[0]*(N+1)
Q[N]=A[N]
for i in range(N,0,-1):
mxp=P[i]+A[i-1]
mnp=(P[i]//2) + (P[i]%2) +A[i-1]
mxq=Q[i]+A[i-1]
mnq=(Q[i]//2) + (Q[i]%2) +A[i-1]
P[i-1]=mnp
Q[i-1]=min(mxq,2**i)
if P[0]!=1:
print((-1))
exit()
Q[0]=1
for i in range(1,N):
if Q[i]>2**i:
Q[i]=2**i
if Q[i]>(Q[i-1]-A[i-1])*2:
Q[i]=(Q[i-1]-A[i-1])*2
print((sum(Q)))
| 32 | 29 | 537 | 490 |
N = int(eval(input()))
A = list(map(int, input().split()))
P = [0] * (N + 1)
P[N] = A[N]
Q = [0] * (N + 1)
Q[N] = A[N]
for i in range(N, 0, -1):
mxp = P[i] + A[i - 1]
mnp = (P[i] // 2) + (P[i] % 2) + A[i - 1]
mxq = Q[i] + A[i - 1]
mnq = (Q[i] // 2) + (Q[i] % 2) + A[i - 1]
if mnp > 2**i:
print((-1))
exit()
P[i - 1] = mnp
Q[i - 1] = min(mxq, 2**i)
if P[0] != 1:
print((-1))
exit()
Q[0] = 1
for i in range(1, N):
if Q[i] > 2**i:
Q[i] = 2**i
if Q[i] > (Q[i - 1] - A[i - 1]) * 2:
Q[i] = (Q[i - 1] - A[i - 1]) * 2
print((sum(Q)))
|
N = int(eval(input()))
A = list(map(int, input().split()))
P = [0] * (N + 1)
P[N] = A[N]
Q = [0] * (N + 1)
Q[N] = A[N]
for i in range(N, 0, -1):
mxp = P[i] + A[i - 1]
mnp = (P[i] // 2) + (P[i] % 2) + A[i - 1]
mxq = Q[i] + A[i - 1]
mnq = (Q[i] // 2) + (Q[i] % 2) + A[i - 1]
P[i - 1] = mnp
Q[i - 1] = min(mxq, 2**i)
if P[0] != 1:
print((-1))
exit()
Q[0] = 1
for i in range(1, N):
if Q[i] > 2**i:
Q[i] = 2**i
if Q[i] > (Q[i - 1] - A[i - 1]) * 2:
Q[i] = (Q[i - 1] - A[i - 1]) * 2
print((sum(Q)))
| false | 9.375 |
[
"- if mnp > 2**i:",
"- print((-1))",
"- exit()"
] | false | 0.0335 | 0.04184 | 0.800674 |
[
"s490377650",
"s997026575"
] |
u215334265
|
p02711
|
python
|
s577340780
|
s077720640
| 61 | 56 | 61,656 | 61,804 |
Accepted
|
Accepted
| 8.2 |
n = eval(input())
if n[0] == '7' or n[1] == '7' or n[2] == '7':
print('Yes')
else:
print('No')
|
n = eval(input())
n = n.count('7')
if n >= 1:
print('Yes')
else:
print('No')
| 5 | 7 | 101 | 89 |
n = eval(input())
if n[0] == "7" or n[1] == "7" or n[2] == "7":
print("Yes")
else:
print("No")
|
n = eval(input())
n = n.count("7")
if n >= 1:
print("Yes")
else:
print("No")
| false | 28.571429 |
[
"-if n[0] == \"7\" or n[1] == \"7\" or n[2] == \"7\":",
"+n = n.count(\"7\")",
"+if n >= 1:"
] | false | 0.048268 | 0.055956 | 0.862618 |
[
"s577340780",
"s077720640"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.