user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
sequence | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u777299405 | p02256 | python | s754096681 | s465300353 | 70 | 30 | 14,756 | 6,724 | Accepted | Accepted | 57.14 | from fractions import gcd
x, y = list(map(int, input().split()))
print((gcd(x, y))) | x, y = list(map(int, input().split()))
while y != 0:
x, y = y, x % y
print(x) | 3 | 4 | 77 | 78 | from fractions import gcd
x, y = list(map(int, input().split()))
print((gcd(x, y)))
| x, y = list(map(int, input().split()))
while y != 0:
x, y = y, x % y
print(x)
| false | 25 | [
"-from fractions import gcd",
"-",
"-print((gcd(x, y)))",
"+while y != 0:",
"+ x, y = y, x % y",
"+print(x)"
] | false | 0.058814 | 0.037229 | 1.579792 | [
"s754096681",
"s465300353"
] |
u744920373 | p03165 | python | s062809735 | s802328019 | 581 | 436 | 117,340 | 112,220 | Accepted | Accepted | 24.96 | import sys
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#N = ii()
#ss = [sys.stdin.readline().rstrip() for i in range(2*N)]
#for i in range(N):
S = eval(input())
T = eval(input())
#S = ss[2*i]
#T = ss[2*i+1]
ls, lt = len(S), len(T)
dp = dp2(0, ls+1, lt+1)
#if S[0] == T[0]:
#dp[1][1] = 1
for i in range(lt+1):
for j in range(ls+1):
if (i < lt and j < ls) and S[j] == T[i]:
dp[i+1][j+1] = dp[i][j] + 1
if j < ls:
dp[i][j+1] = max(dp[i][j], dp[i][j+1])
if i < lt:
dp[i+1][j] = max(dp[i][j], dp[i+1][j])
if not dp[lt][ls]:
dp[lt][ls] = max(dp[lt-1][ls], dp[lt][ls-1])
#print(dp[lt][ls])
i, j = lt, ls
ans = ''
while dp[i][j] != 0:
if dp[i][j] == dp[i-1][j]:
i -= 1
elif dp[i][j] == dp[i][j-1]:
j -= 1
else:
ans += S[j-1]
i -= 1
j -= 1
print((ans[::-1])) | import sys
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#N = ii()
#ss = [sys.stdin.readline().rstrip() for i in range(2*N)]
#for i in range(N):
S = eval(input())
T = eval(input())
#S = ss[2*i]
#T = ss[2*i+1]
ls, lt = len(S), len(T)
dp = dp2(0, ls+1, lt+1)
#if S[0] == T[0]:
#dp[1][1] = 1
for i in range(1, lt+1):
for j in range(1, ls+1):
#if (i < lt and j < ls) and S[j] == T[i]:
#dp[i+1][j+1] = dp[i][j] + 1
#if j < ls:
#dp[i][j+1] = max(dp[i][j], dp[i][j+1])
#if i < lt:
#dp[i+1][j] = max(dp[i][j], dp[i+1][j])
if S[j-1] == T[i-1]:
dp[i][j] = dp[i-1][j-1] + 1
else:
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
#if not dp[lt][ls]:
#dp[lt][ls] = max(dp[lt-1][ls], dp[lt][ls-1])
i, j = lt, ls
ans = ''
while dp[i][j] != 0:
if dp[i][j] == dp[i-1][j]:
i -= 1
elif dp[i][j] == dp[i][j-1]:
j -= 1
else:
ans += S[j-1]
i -= 1
j -= 1
print((ans[::-1])) | 51 | 55 | 1,370 | 1,520 | import sys
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# N = ii()
# ss = [sys.stdin.readline().rstrip() for i in range(2*N)]
# for i in range(N):
S = eval(input())
T = eval(input())
# S = ss[2*i]
# T = ss[2*i+1]
ls, lt = len(S), len(T)
dp = dp2(0, ls + 1, lt + 1)
# if S[0] == T[0]:
# dp[1][1] = 1
for i in range(lt + 1):
for j in range(ls + 1):
if (i < lt and j < ls) and S[j] == T[i]:
dp[i + 1][j + 1] = dp[i][j] + 1
if j < ls:
dp[i][j + 1] = max(dp[i][j], dp[i][j + 1])
if i < lt:
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])
if not dp[lt][ls]:
dp[lt][ls] = max(dp[lt - 1][ls], dp[lt][ls - 1])
# print(dp[lt][ls])
i, j = lt, ls
ans = ""
while dp[i][j] != 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
ans += S[j - 1]
i -= 1
j -= 1
print((ans[::-1]))
| import sys
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# N = ii()
# ss = [sys.stdin.readline().rstrip() for i in range(2*N)]
# for i in range(N):
S = eval(input())
T = eval(input())
# S = ss[2*i]
# T = ss[2*i+1]
ls, lt = len(S), len(T)
dp = dp2(0, ls + 1, lt + 1)
# if S[0] == T[0]:
# dp[1][1] = 1
for i in range(1, lt + 1):
for j in range(1, ls + 1):
# if (i < lt and j < ls) and S[j] == T[i]:
# dp[i+1][j+1] = dp[i][j] + 1
# if j < ls:
# dp[i][j+1] = max(dp[i][j], dp[i][j+1])
# if i < lt:
# dp[i+1][j] = max(dp[i][j], dp[i+1][j])
if S[j - 1] == T[i - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
# if not dp[lt][ls]:
# dp[lt][ls] = max(dp[lt-1][ls], dp[lt][ls-1])
i, j = lt, ls
ans = ""
while dp[i][j] != 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
ans += S[j - 1]
i -= 1
j -= 1
print((ans[::-1]))
| false | 7.272727 | [
"-for i in range(lt + 1):",
"- for j in range(ls + 1):",
"- if (i < lt and j < ls) and S[j] == T[i]:",
"- dp[i + 1][j + 1] = dp[i][j] + 1",
"- if j < ls:",
"- dp[i][j + 1] = max(dp[i][j], dp[i][j + 1])",
"- if i < lt:",
"- dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])",
"-if not dp[lt][ls]:",
"- dp[lt][ls] = max(dp[lt - 1][ls], dp[lt][ls - 1])",
"-# print(dp[lt][ls])",
"+for i in range(1, lt + 1):",
"+ for j in range(1, ls + 1):",
"+ # if (i < lt and j < ls) and S[j] == T[i]:",
"+ # dp[i+1][j+1] = dp[i][j] + 1",
"+ # if j < ls:",
"+ # dp[i][j+1] = max(dp[i][j], dp[i][j+1])",
"+ # if i < lt:",
"+ # dp[i+1][j] = max(dp[i][j], dp[i+1][j])",
"+ if S[j - 1] == T[i - 1]:",
"+ dp[i][j] = dp[i - 1][j - 1] + 1",
"+ else:",
"+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])",
"+# if not dp[lt][ls]:",
"+# dp[lt][ls] = max(dp[lt-1][ls], dp[lt][ls-1])"
] | false | 0.044474 | 0.044452 | 1.000514 | [
"s062809735",
"s802328019"
] |
u797016134 | p03289 | python | s081091250 | s816426812 | 27 | 17 | 3,772 | 2,940 | Accepted | Accepted | 37.04 | import string
li = list(string.ascii_lowercase)
s = list(eval(input()))
if s[0] == "A" and s[2:-1].count("C") == 1:
s.remove("C")
s.remove("A")
else:
print("WA")
exit()
if all([s[i] in li for i in range(len(s))]):
print("AC")
exit()
else:
print("WA") | i = input()
if i[0]=="A"and i[2:-1].count("C")==1\
and i[1:].replace("C","c",1).islower()==True:
print("AC")
else:print("WA")
| 14 | 5 | 285 | 133 | import string
li = list(string.ascii_lowercase)
s = list(eval(input()))
if s[0] == "A" and s[2:-1].count("C") == 1:
s.remove("C")
s.remove("A")
else:
print("WA")
exit()
if all([s[i] in li for i in range(len(s))]):
print("AC")
exit()
else:
print("WA")
| i = input()
if (
i[0] == "A"
and i[2:-1].count("C") == 1
and i[1:].replace("C", "c", 1).islower() == True
):
print("AC")
else:
print("WA")
| false | 64.285714 | [
"-import string",
"-",
"-li = list(string.ascii_lowercase)",
"-s = list(eval(input()))",
"-if s[0] == \"A\" and s[2:-1].count(\"C\") == 1:",
"- s.remove(\"C\")",
"- s.remove(\"A\")",
"+i = input()",
"+if (",
"+ i[0] == \"A\"",
"+ and i[2:-1].count(\"C\") == 1",
"+ and i[1:].replace(\"C\", \"c\", 1).islower() == True",
"+):",
"+ print(\"AC\")",
"- exit()",
"-if all([s[i] in li for i in range(len(s))]):",
"- print(\"AC\")",
"- exit()",
"-else:",
"- print(\"WA\")"
] | false | 0.045201 | 0.038308 | 1.17992 | [
"s081091250",
"s816426812"
] |
u796942881 | p03252 | python | s802090443 | s590871679 | 108 | 51 | 3,828 | 6,960 | Accepted | Accepted | 52.78 | input = open(0).read
S, T = input().split()
def main():
C1 = [None] * (ord('z') - ord('a') + 1)
C2 = [None] * (ord('z') - ord('a') + 1)
flg = True
for i in range(len(S)):
c1 = ord(S[i]) - ord('a')
c2 = ord(T[i]) - ord('a')
if C1[c1] or C2[c2]:
if c1 != C2[c2] or c2 != C1[c1]:
flg = False
break
C1[c1] = c2
C2[c2] = c1
print(("Yes" if flg else "No"))
return
main()
| #from sys import stdin
from collections import Counter
from operator import itemgetter
#input = stdin.readline
S = list(eval(input()))
T = list(eval(input()))
def main():
C1 = Counter(S).most_common()
C2 = Counter(T).most_common()
if len(C1) != len(C2):
print("No")
return
flg = True
for i in range(len(C1)):
if C1[i][1] != C2[i][1]:
flg = False
print(("Yes" if flg else "No"))
return
main()
| 27 | 28 | 506 | 478 | input = open(0).read
S, T = input().split()
def main():
C1 = [None] * (ord("z") - ord("a") + 1)
C2 = [None] * (ord("z") - ord("a") + 1)
flg = True
for i in range(len(S)):
c1 = ord(S[i]) - ord("a")
c2 = ord(T[i]) - ord("a")
if C1[c1] or C2[c2]:
if c1 != C2[c2] or c2 != C1[c1]:
flg = False
break
C1[c1] = c2
C2[c2] = c1
print(("Yes" if flg else "No"))
return
main()
| # from sys import stdin
from collections import Counter
from operator import itemgetter
# input = stdin.readline
S = list(eval(input()))
T = list(eval(input()))
def main():
C1 = Counter(S).most_common()
C2 = Counter(T).most_common()
if len(C1) != len(C2):
print("No")
return
flg = True
for i in range(len(C1)):
if C1[i][1] != C2[i][1]:
flg = False
print(("Yes" if flg else "No"))
return
main()
| false | 3.571429 | [
"-input = open(0).read",
"-S, T = input().split()",
"+# from sys import stdin",
"+from collections import Counter",
"+from operator import itemgetter",
"+",
"+# input = stdin.readline",
"+S = list(eval(input()))",
"+T = list(eval(input()))",
"- C1 = [None] * (ord(\"z\") - ord(\"a\") + 1)",
"- C2 = [None] * (ord(\"z\") - ord(\"a\") + 1)",
"+ C1 = Counter(S).most_common()",
"+ C2 = Counter(T).most_common()",
"+ if len(C1) != len(C2):",
"+ print(\"No\")",
"+ return",
"- for i in range(len(S)):",
"- c1 = ord(S[i]) - ord(\"a\")",
"- c2 = ord(T[i]) - ord(\"a\")",
"- if C1[c1] or C2[c2]:",
"- if c1 != C2[c2] or c2 != C1[c1]:",
"- flg = False",
"- break",
"- C1[c1] = c2",
"- C2[c2] = c1",
"+ for i in range(len(C1)):",
"+ if C1[i][1] != C2[i][1]:",
"+ flg = False"
] | false | 0.036268 | 0.035624 | 1.018093 | [
"s802090443",
"s590871679"
] |
u118147328 | p03126 | python | s936207884 | s180205167 | 21 | 18 | 3,060 | 3,064 | Accepted | Accepted | 14.29 | N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
K = []
for i in range(N):
K.append(A[i][0])
del A[i][0]
ans = A[0]
for i in range(N-1):
ans = set(ans) & set(A[i+1])
print((len(ans)))
| N, M = list(map(int, input().split()))
ans_list = []
for i in range(N):
k, *A = list(map(int, input().split()))
for a in A:
ans_list.append(a)
ans = 0
for i in range(1, M+1):
if ans_list.count(i) == N:
ans += 1
print(ans) | 12 | 14 | 251 | 269 | N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
K = []
for i in range(N):
K.append(A[i][0])
del A[i][0]
ans = A[0]
for i in range(N - 1):
ans = set(ans) & set(A[i + 1])
print((len(ans)))
| N, M = list(map(int, input().split()))
ans_list = []
for i in range(N):
k, *A = list(map(int, input().split()))
for a in A:
ans_list.append(a)
ans = 0
for i in range(1, M + 1):
if ans_list.count(i) == N:
ans += 1
print(ans)
| false | 14.285714 | [
"-A = [list(map(int, input().split())) for _ in range(N)]",
"-K = []",
"+ans_list = []",
"- K.append(A[i][0])",
"- del A[i][0]",
"-ans = A[0]",
"-for i in range(N - 1):",
"- ans = set(ans) & set(A[i + 1])",
"-print((len(ans)))",
"+ k, *A = list(map(int, input().split()))",
"+ for a in A:",
"+ ans_list.append(a)",
"+ans = 0",
"+for i in range(1, M + 1):",
"+ if ans_list.count(i) == N:",
"+ ans += 1",
"+print(ans)"
] | false | 0.046399 | 0.047231 | 0.982388 | [
"s936207884",
"s180205167"
] |
u227020436 | p02709 | python | s718365815 | s256579076 | 1,300 | 93 | 315,300 | 68,612 | Accepted | Accepted | 92.85 | # E - Active Infants
n = int(input())
a = list(map(int, input().split()))
assert len(a) == n
# 添字のリスト
p = list(range(n))
p.sort(key=lambda i: a[i])
# dp[(j, i)] = 位置jから幅iの区間に小さい方からi個を配置したときの最大うれしさ
dp = {(j, 0): 0 for j in range(n + 1)}
for i in range(n):
for j in range(n - i):
dp[(j, i + 1)] = \
max(dp[(j, i)] + a[p[i]] * abs(p[i] - (j + i)),
dp[(j + 1, i)] + a[p[i]] * abs(p[i] - j))
print(dp[(0, n)])
| # E - Active Infants
n = int(eval(input()))
a = list(map(int, input().split()))
assert len(a) == n
# 添字のリスト
p = list(range(n))
p.sort(key=lambda i: a[i])
# dp[j] = 位置jから幅iの区間に小さい方からi個を配置したときの最大うれしさ
dp = [0] * (n + 1)
for i in range(n):
for j in range(n - i):
dp[j] = max(dp[j] + a[p[i]] * abs(p[i] - (j + i)),
dp[j + 1] + a[p[i]] * abs(p[i] - j))
print((dp[0]))
| 20 | 19 | 473 | 413 | # E - Active Infants
n = int(input())
a = list(map(int, input().split()))
assert len(a) == n
# 添字のリスト
p = list(range(n))
p.sort(key=lambda i: a[i])
# dp[(j, i)] = 位置jから幅iの区間に小さい方からi個を配置したときの最大うれしさ
dp = {(j, 0): 0 for j in range(n + 1)}
for i in range(n):
for j in range(n - i):
dp[(j, i + 1)] = max(
dp[(j, i)] + a[p[i]] * abs(p[i] - (j + i)),
dp[(j + 1, i)] + a[p[i]] * abs(p[i] - j),
)
print(dp[(0, n)])
| # E - Active Infants
n = int(eval(input()))
a = list(map(int, input().split()))
assert len(a) == n
# 添字のリスト
p = list(range(n))
p.sort(key=lambda i: a[i])
# dp[j] = 位置jから幅iの区間に小さい方からi個を配置したときの最大うれしさ
dp = [0] * (n + 1)
for i in range(n):
for j in range(n - i):
dp[j] = max(
dp[j] + a[p[i]] * abs(p[i] - (j + i)), dp[j + 1] + a[p[i]] * abs(p[i] - j)
)
print((dp[0]))
| false | 5 | [
"-n = int(input())",
"+n = int(eval(input()))",
"-# dp[(j, i)] = 位置jから幅iの区間に小さい方からi個を配置したときの最大うれしさ",
"-dp = {(j, 0): 0 for j in range(n + 1)}",
"+# dp[j] = 位置jから幅iの区間に小さい方からi個を配置したときの最大うれしさ",
"+dp = [0] * (n + 1)",
"- dp[(j, i + 1)] = max(",
"- dp[(j, i)] + a[p[i]] * abs(p[i] - (j + i)),",
"- dp[(j + 1, i)] + a[p[i]] * abs(p[i] - j),",
"+ dp[j] = max(",
"+ dp[j] + a[p[i]] * abs(p[i] - (j + i)), dp[j + 1] + a[p[i]] * abs(p[i] - j)",
"-print(dp[(0, n)])",
"+print((dp[0]))"
] | false | 0.040757 | 0.036187 | 1.126298 | [
"s718365815",
"s256579076"
] |
u746419473 | p03073 | python | s931535755 | s408668890 | 51 | 29 | 3,956 | 4,644 | Accepted | Accepted | 43.14 | s = list(eval(input()))
ans = 0
for i in range(1, len(s)):
if s[i-1] == s[i]:
ans += 1
s[i] = "1" if s[i-1] == "0" else "0"
print(ans)
| import collections
s = list(eval(input()))
even = collections.Counter(s[0::2])
odd = collections.Counter(s[1::2])
print((min(len(s) - (even["0"] + odd["1"]), len(s) - (even["1"] + odd["0"]))))
| 9 | 7 | 159 | 193 | s = list(eval(input()))
ans = 0
for i in range(1, len(s)):
if s[i - 1] == s[i]:
ans += 1
s[i] = "1" if s[i - 1] == "0" else "0"
print(ans)
| import collections
s = list(eval(input()))
even = collections.Counter(s[0::2])
odd = collections.Counter(s[1::2])
print((min(len(s) - (even["0"] + odd["1"]), len(s) - (even["1"] + odd["0"]))))
| false | 22.222222 | [
"+import collections",
"+",
"-ans = 0",
"-for i in range(1, len(s)):",
"- if s[i - 1] == s[i]:",
"- ans += 1",
"- s[i] = \"1\" if s[i - 1] == \"0\" else \"0\"",
"-print(ans)",
"+even = collections.Counter(s[0::2])",
"+odd = collections.Counter(s[1::2])",
"+print((min(len(s) - (even[\"0\"] + odd[\"1\"]), len(s) - (even[\"1\"] + odd[\"0\"]))))"
] | false | 0.038092 | 0.037361 | 1.019565 | [
"s931535755",
"s408668890"
] |
u564902833 | p03148 | python | s600041592 | s392918787 | 676 | 578 | 58,828 | 58,456 | Accepted | Accepted | 14.5 | from operator import itemgetter
from functools import reduce
N, K = list(map(int, input().split()))
t, d = list(zip(*(list(map(int, input().split())) for _ in range(N))))
fn = itemgetter(0)
fd = itemgetter(1)
ss = sorted(zip(t, d), key=fd, reverse=True)
netas = set()
duplicates = []
for s in ss[:K]:
if s[0] in netas:
duplicates.append(s[1])
else:
netas.add(s[0])
p = sum(map(fd, ss[:K])) + len(netas)**2
ans = p
for s in ss[K:]:
if s[0] not in netas and duplicates:
netas.add(s[0])
duplicate = duplicates.pop()
p += (s[1] - duplicate) + 2 * len(netas) - 1
ans = max(ans, p)
print(ans) | from heapq import heappush, heappop
N, K = list(map(int, input().split()))
t, d = (
list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else
((), ())
)
# おいしさについて貪欲に寿司を食べたときの満足ポイントを求める
# その後、種類ボーナスを1個ずつ増やしたときの満足ポイントをそれぞれ求め、
# それらの最大値を求める
S = sorted(zip(d, t), reverse=True)
q = []
v = set()
s = 0
for D, T in S[:K]:
s += D
if T in v:
heappush(q, D)
else:
v.add(T)
s += len(v)**2
opt = s
for D, T in S[K:]:
if T not in v and q:
z = heappop(q)
s += D + 2 * len(v) + 1 - z
v.add(T)
opt = max(opt, s)
ans = opt
print(ans)
| 23 | 32 | 620 | 623 | from operator import itemgetter
from functools import reduce
N, K = list(map(int, input().split()))
t, d = list(zip(*(list(map(int, input().split())) for _ in range(N))))
fn = itemgetter(0)
fd = itemgetter(1)
ss = sorted(zip(t, d), key=fd, reverse=True)
netas = set()
duplicates = []
for s in ss[:K]:
if s[0] in netas:
duplicates.append(s[1])
else:
netas.add(s[0])
p = sum(map(fd, ss[:K])) + len(netas) ** 2
ans = p
for s in ss[K:]:
if s[0] not in netas and duplicates:
netas.add(s[0])
duplicate = duplicates.pop()
p += (s[1] - duplicate) + 2 * len(netas) - 1
ans = max(ans, p)
print(ans)
| from heapq import heappush, heappop
N, K = list(map(int, input().split()))
t, d = (
list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ())
)
# おいしさについて貪欲に寿司を食べたときの満足ポイントを求める
# その後、種類ボーナスを1個ずつ増やしたときの満足ポイントをそれぞれ求め、
# それらの最大値を求める
S = sorted(zip(d, t), reverse=True)
q = []
v = set()
s = 0
for D, T in S[:K]:
s += D
if T in v:
heappush(q, D)
else:
v.add(T)
s += len(v) ** 2
opt = s
for D, T in S[K:]:
if T not in v and q:
z = heappop(q)
s += D + 2 * len(v) + 1 - z
v.add(T)
opt = max(opt, s)
ans = opt
print(ans)
| false | 28.125 | [
"-from operator import itemgetter",
"-from functools import reduce",
"+from heapq import heappush, heappop",
"-t, d = list(zip(*(list(map(int, input().split())) for _ in range(N))))",
"-fn = itemgetter(0)",
"-fd = itemgetter(1)",
"-ss = sorted(zip(t, d), key=fd, reverse=True)",
"-netas = set()",
"-duplicates = []",
"-for s in ss[:K]:",
"- if s[0] in netas:",
"- duplicates.append(s[1])",
"+t, d = (",
"+ list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ())",
"+)",
"+# おいしさについて貪欲に寿司を食べたときの満足ポイントを求める",
"+# その後、種類ボーナスを1個ずつ増やしたときの満足ポイントをそれぞれ求め、",
"+# それらの最大値を求める",
"+S = sorted(zip(d, t), reverse=True)",
"+q = []",
"+v = set()",
"+s = 0",
"+for D, T in S[:K]:",
"+ s += D",
"+ if T in v:",
"+ heappush(q, D)",
"- netas.add(s[0])",
"-p = sum(map(fd, ss[:K])) + len(netas) ** 2",
"-ans = p",
"-for s in ss[K:]:",
"- if s[0] not in netas and duplicates:",
"- netas.add(s[0])",
"- duplicate = duplicates.pop()",
"- p += (s[1] - duplicate) + 2 * len(netas) - 1",
"- ans = max(ans, p)",
"+ v.add(T)",
"+s += len(v) ** 2",
"+opt = s",
"+for D, T in S[K:]:",
"+ if T not in v and q:",
"+ z = heappop(q)",
"+ s += D + 2 * len(v) + 1 - z",
"+ v.add(T)",
"+ opt = max(opt, s)",
"+ans = opt"
] | false | 0.030765 | 0.0484 | 0.635644 | [
"s600041592",
"s392918787"
] |
u868600519 | p03478 | python | s930961168 | s432134802 | 32 | 28 | 2,940 | 2,940 | Accepted | Accepted | 12.5 | N, A, B = list(map(int, input().split()))
print((sum(i for i in range(1, N+1) if A <= sum(int(c) for c in str(i)) <= B)))
| N, A, B = list(map(int, input().split()))
print((sum(i for i in range(1, N+1) if A <= sum(map(int, str(i))) <= B)))
| 3 | 3 | 117 | 111 | N, A, B = list(map(int, input().split()))
print((sum(i for i in range(1, N + 1) if A <= sum(int(c) for c in str(i)) <= B)))
| N, A, B = list(map(int, input().split()))
print((sum(i for i in range(1, N + 1) if A <= sum(map(int, str(i))) <= B)))
| false | 0 | [
"-print((sum(i for i in range(1, N + 1) if A <= sum(int(c) for c in str(i)) <= B)))",
"+print((sum(i for i in range(1, N + 1) if A <= sum(map(int, str(i))) <= B)))"
] | false | 0.040643 | 0.064084 | 0.634217 | [
"s930961168",
"s432134802"
] |
u716043626 | p03137 | python | s019229401 | s777024342 | 1,550 | 115 | 13,968 | 13,968 | Accepted | Accepted | 92.58 | n, m = list(map(int,input().split()))
x = list(map(int,input().split()))
x.sort()
dis = []
if n >= m:
print((0))
else:
for i in range(m-1):
dis.append(abs(x[i+1]-x[i]))
dis.sort(reverse=True)
for i in range(n-1):
dis.pop(0)
ans = sum(dis)
print(ans) | n,m = list(map(int,input().split()))
x = list(map(int,input().split()))
dif = []
x.sort()
for i in range(len(x)-1):
dif.append(abs(x[i]-x[i+1]))
dif.sort(reverse=True)
ans = sum(dif[n-1:])
print(ans) | 14 | 12 | 298 | 215 | n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
dis = []
if n >= m:
print((0))
else:
for i in range(m - 1):
dis.append(abs(x[i + 1] - x[i]))
dis.sort(reverse=True)
for i in range(n - 1):
dis.pop(0)
ans = sum(dis)
print(ans)
| n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
dif = []
x.sort()
for i in range(len(x) - 1):
dif.append(abs(x[i] - x[i + 1]))
dif.sort(reverse=True)
ans = sum(dif[n - 1 :])
print(ans)
| false | 14.285714 | [
"+dif = []",
"-dis = []",
"-if n >= m:",
"- print((0))",
"-else:",
"- for i in range(m - 1):",
"- dis.append(abs(x[i + 1] - x[i]))",
"- dis.sort(reverse=True)",
"- for i in range(n - 1):",
"- dis.pop(0)",
"- ans = sum(dis)",
"- print(ans)",
"+for i in range(len(x) - 1):",
"+ dif.append(abs(x[i] - x[i + 1]))",
"+dif.sort(reverse=True)",
"+ans = sum(dif[n - 1 :])",
"+print(ans)"
] | false | 0.099406 | 0.035772 | 2.7789 | [
"s019229401",
"s777024342"
] |
u024340351 | p02720 | python | s011702505 | s454088369 | 212 | 114 | 59,440 | 18,688 | Accepted | Accepted | 46.23 | K = int(eval(input()))
V = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range (0, 100000):
if V[i]%10 == 0:
V.append(10*V[i]+0)
V.append(10*V[i]+1)
elif V[i]%10 == 9:
V.append(10*V[i]+8)
V.append(10*V[i]+9)
else:
V.append(10*V[i]+V[i]%10-1)
V.append(10*V[i]+V[i]%10)
V.append(10*V[i]+V[i]%10+1)
print((V[K-1])) | import collections
K = int(eval(input()))
L = [1,2,3,4,5,6,7,8,9]
Q = collections.deque(L)
count = 0
while count < K-1:
V = Q.popleft()
count+=1
if V%10 == 0:
Q.append(10*V)
Q.append(10*V+1)
elif V%10 == 9:
Q.append(10*V+8)
Q.append(10*V+9)
else:
Q.append(10*V+(V%10)-1)
Q.append(10*V+(V%10))
Q.append(10*V+(V%10)+1)
print((Q.popleft())) | 17 | 23 | 330 | 432 | K = int(eval(input()))
V = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(0, 100000):
if V[i] % 10 == 0:
V.append(10 * V[i] + 0)
V.append(10 * V[i] + 1)
elif V[i] % 10 == 9:
V.append(10 * V[i] + 8)
V.append(10 * V[i] + 9)
else:
V.append(10 * V[i] + V[i] % 10 - 1)
V.append(10 * V[i] + V[i] % 10)
V.append(10 * V[i] + V[i] % 10 + 1)
print((V[K - 1]))
| import collections
K = int(eval(input()))
L = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Q = collections.deque(L)
count = 0
while count < K - 1:
V = Q.popleft()
count += 1
if V % 10 == 0:
Q.append(10 * V)
Q.append(10 * V + 1)
elif V % 10 == 9:
Q.append(10 * V + 8)
Q.append(10 * V + 9)
else:
Q.append(10 * V + (V % 10) - 1)
Q.append(10 * V + (V % 10))
Q.append(10 * V + (V % 10) + 1)
print((Q.popleft()))
| false | 26.086957 | [
"+import collections",
"+",
"-V = [1, 2, 3, 4, 5, 6, 7, 8, 9]",
"-for i in range(0, 100000):",
"- if V[i] % 10 == 0:",
"- V.append(10 * V[i] + 0)",
"- V.append(10 * V[i] + 1)",
"- elif V[i] % 10 == 9:",
"- V.append(10 * V[i] + 8)",
"- V.append(10 * V[i] + 9)",
"+L = [1, 2, 3, 4, 5, 6, 7, 8, 9]",
"+Q = collections.deque(L)",
"+count = 0",
"+while count < K - 1:",
"+ V = Q.popleft()",
"+ count += 1",
"+ if V % 10 == 0:",
"+ Q.append(10 * V)",
"+ Q.append(10 * V + 1)",
"+ elif V % 10 == 9:",
"+ Q.append(10 * V + 8)",
"+ Q.append(10 * V + 9)",
"- V.append(10 * V[i] + V[i] % 10 - 1)",
"- V.append(10 * V[i] + V[i] % 10)",
"- V.append(10 * V[i] + V[i] % 10 + 1)",
"-print((V[K - 1]))",
"+ Q.append(10 * V + (V % 10) - 1)",
"+ Q.append(10 * V + (V % 10))",
"+ Q.append(10 * V + (V % 10) + 1)",
"+print((Q.popleft()))"
] | false | 0.29704 | 0.050078 | 5.931523 | [
"s011702505",
"s454088369"
] |
u836737505 | p03361 | python | s463570616 | s297518023 | 192 | 20 | 40,688 | 3,064 | Accepted | Accepted | 89.58 | n, m = list(map(int, input().split()))
field = [list(eval(input())) for i in range(n)]
flg = True
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(n):
for j in range(m):
if field[i][j] == "#":
f = 0
for k in range(4):
# 移動した後の点を (nx, ny) とする
nx = i + dx[k]
ny = j + dy[k]
if 0 <= nx and nx < n and 0 <= ny and ny < m and field[nx][ny] == "#":
f += 1
if f==False:
flg = False
print(("Yes" if flg else "No")) | h,w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for k in range(h):
for j in range(w):
x,y = k,j
if a[x][y] == "#":
for i in range(4):
xi,yi = x+dx[i],y+dy[i]
if 0 <= xi < h and 0 <= yi < w and a[xi][yi] == "#":
break
else:
print("No")
exit()
print("Yes") | 19 | 17 | 575 | 453 | n, m = list(map(int, input().split()))
field = [list(eval(input())) for i in range(n)]
flg = True
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(n):
for j in range(m):
if field[i][j] == "#":
f = 0
for k in range(4):
# 移動した後の点を (nx, ny) とする
nx = i + dx[k]
ny = j + dy[k]
if 0 <= nx and nx < n and 0 <= ny and ny < m and field[nx][ny] == "#":
f += 1
if f == False:
flg = False
print(("Yes" if flg else "No"))
| h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for k in range(h):
for j in range(w):
x, y = k, j
if a[x][y] == "#":
for i in range(4):
xi, yi = x + dx[i], y + dy[i]
if 0 <= xi < h and 0 <= yi < w and a[xi][yi] == "#":
break
else:
print("No")
exit()
print("Yes")
| false | 10.526316 | [
"-n, m = list(map(int, input().split()))",
"-field = [list(eval(input())) for i in range(n)]",
"-flg = True",
"+h, w = list(map(int, input().split()))",
"+a = [list(eval(input())) for _ in range(h)]",
"-for i in range(n):",
"- for j in range(m):",
"- if field[i][j] == \"#\":",
"- f = 0",
"- for k in range(4):",
"- # 移動した後の点を (nx, ny) とする",
"- nx = i + dx[k]",
"- ny = j + dy[k]",
"- if 0 <= nx and nx < n and 0 <= ny and ny < m and field[nx][ny] == \"#\":",
"- f += 1",
"- if f == False:",
"- flg = False",
"-print((\"Yes\" if flg else \"No\"))",
"+for k in range(h):",
"+ for j in range(w):",
"+ x, y = k, j",
"+ if a[x][y] == \"#\":",
"+ for i in range(4):",
"+ xi, yi = x + dx[i], y + dy[i]",
"+ if 0 <= xi < h and 0 <= yi < w and a[xi][yi] == \"#\":",
"+ break",
"+ else:",
"+ print(\"No\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.109386 | 0.045075 | 2.426739 | [
"s463570616",
"s297518023"
] |
u716530146 | p04019 | python | s354980905 | s277354122 | 162 | 21 | 38,256 | 3,444 | Accepted | Accepted | 87.04 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
s=eval(input())
C=collections.Counter(s)
if ((C["N"] or C["S"]) and C["N"]*C["S"] == 0):
print("No")
elif ((C["W"] or C["E"]) and C["W"]*C["E"] == 0):
print("No")
else:
print("Yes") | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
S = eval(input())
C = collections.Counter(S)
if (C["N"] and not C["S"]) or ((not C["N"]) and C["S"]) or (C["W"] and not C["E"]) or ((not C["W"]) and C["E"]):
print("No")
else:
print("Yes")
# print(bool(((C["W"] and not C["E"])))) | 14 | 14 | 410 | 458 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
s = eval(input())
C = collections.Counter(s)
if (C["N"] or C["S"]) and C["N"] * C["S"] == 0:
print("No")
elif (C["W"] or C["E"]) and C["W"] * C["E"] == 0:
print("No")
else:
print("Yes")
| #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
S = eval(input())
C = collections.Counter(S)
if (
(C["N"] and not C["S"])
or ((not C["N"]) and C["S"])
or (C["W"] and not C["E"])
or ((not C["W"]) and C["E"])
):
print("No")
else:
print("Yes")
# print(bool(((C["W"] and not C["E"]))))
| false | 0 | [
"-s = eval(input())",
"-C = collections.Counter(s)",
"-if (C[\"N\"] or C[\"S\"]) and C[\"N\"] * C[\"S\"] == 0:",
"- print(\"No\")",
"-elif (C[\"W\"] or C[\"E\"]) and C[\"W\"] * C[\"E\"] == 0:",
"+S = eval(input())",
"+C = collections.Counter(S)",
"+if (",
"+ (C[\"N\"] and not C[\"S\"])",
"+ or ((not C[\"N\"]) and C[\"S\"])",
"+ or (C[\"W\"] and not C[\"E\"])",
"+ or ((not C[\"W\"]) and C[\"E\"])",
"+):",
"+# print(bool(((C[\"W\"] and not C[\"E\"]))))"
] | false | 0.03537 | 0.036969 | 0.956756 | [
"s354980905",
"s277354122"
] |
u893063840 | p02715 | python | s489438088 | s754354559 | 559 | 221 | 11,216 | 12,012 | Accepted | Accepted | 60.47 | n, k = list(map(int, input().split()))
mod = 10 ** 9 + 7
cnt = [0] * (k + 1)
for i in range(k, 0, -1):
c = pow(k // i, n, mod)
for j in range(2, k + 1):
if i * j > k:
break
c -= cnt[i * j]
c %= mod
cnt[i] = c
ans = 0
for i in range(1, k + 1):
ans += i * cnt[i]
ans %= mod
print(ans)
| n, k = list(map(int, input().split()))
mod = 10 ** 9 + 7
cnt = [0] * (k + 1)
for i in range(k, 0, -1):
c = pow(k // i, n, mod)
c -= sum(cnt[i * 2::i])
c %= mod
cnt[i] = c
ans = 0
for i in range(1, k + 1):
ans += i * cnt[i]
ans %= mod
print(ans)
| 21 | 17 | 358 | 283 | n, k = list(map(int, input().split()))
mod = 10**9 + 7
cnt = [0] * (k + 1)
for i in range(k, 0, -1):
c = pow(k // i, n, mod)
for j in range(2, k + 1):
if i * j > k:
break
c -= cnt[i * j]
c %= mod
cnt[i] = c
ans = 0
for i in range(1, k + 1):
ans += i * cnt[i]
ans %= mod
print(ans)
| n, k = list(map(int, input().split()))
mod = 10**9 + 7
cnt = [0] * (k + 1)
for i in range(k, 0, -1):
c = pow(k // i, n, mod)
c -= sum(cnt[i * 2 :: i])
c %= mod
cnt[i] = c
ans = 0
for i in range(1, k + 1):
ans += i * cnt[i]
ans %= mod
print(ans)
| false | 19.047619 | [
"- for j in range(2, k + 1):",
"- if i * j > k:",
"- break",
"- c -= cnt[i * j]",
"- c %= mod",
"+ c -= sum(cnt[i * 2 :: i])",
"+ c %= mod"
] | false | 0.142606 | 0.105776 | 1.348187 | [
"s489438088",
"s754354559"
] |
u681444474 | p03673 | python | s436084237 | s318974300 | 339 | 179 | 120,760 | 38,040 | Accepted | Accepted | 47.2 | # coding: utf-8
n=int(eval(input()))
A=list(map(int,input().split()))
B=[0]*n
l=n//2
if n%2==0:
for i in range(n):
if i%2==0:
B[l+i]=str(A[i])
l=l+i
else:
B[l-i]=str(A[i])
l=l-i
else:
for i in range(n):
if i%2==0:
B[l-i]=str(A[i])
l=l-i
else:
B[l+i]=str(A[i])
l=l+i
print((' '.join(B))) | # coding: utf-8
import math
from collections import deque
n = int(eval(input()))
#x, y = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
B = deque()
if n%2==0:
for i in range(n):
a=str(A[i])
if i%2==1:
B.appendleft(a)
else:
B.append(a)
if n%2==1:
for i in range(n):
a=str(A[i])
if i%2==0:
B.appendleft(a)
else:
B.append(a)
print((' '.join(B))) | 22 | 23 | 435 | 481 | # coding: utf-8
n = int(eval(input()))
A = list(map(int, input().split()))
B = [0] * n
l = n // 2
if n % 2 == 0:
for i in range(n):
if i % 2 == 0:
B[l + i] = str(A[i])
l = l + i
else:
B[l - i] = str(A[i])
l = l - i
else:
for i in range(n):
if i % 2 == 0:
B[l - i] = str(A[i])
l = l - i
else:
B[l + i] = str(A[i])
l = l + i
print((" ".join(B)))
| # coding: utf-8
import math
from collections import deque
n = int(eval(input()))
# x, y = map(int,input().split())
A = list(map(int, input().split()))
ans = 0
B = deque()
if n % 2 == 0:
for i in range(n):
a = str(A[i])
if i % 2 == 1:
B.appendleft(a)
else:
B.append(a)
if n % 2 == 1:
for i in range(n):
a = str(A[i])
if i % 2 == 0:
B.appendleft(a)
else:
B.append(a)
print((" ".join(B)))
| false | 4.347826 | [
"+import math",
"+from collections import deque",
"+",
"+# x, y = map(int,input().split())",
"-B = [0] * n",
"-l = n // 2",
"+ans = 0",
"+B = deque()",
"+ a = str(A[i])",
"+ if i % 2 == 1:",
"+ B.appendleft(a)",
"+ else:",
"+ B.append(a)",
"+if n % 2 == 1:",
"+ for i in range(n):",
"+ a = str(A[i])",
"- B[l + i] = str(A[i])",
"- l = l + i",
"+ B.appendleft(a)",
"- B[l - i] = str(A[i])",
"- l = l - i",
"-else:",
"- for i in range(n):",
"- if i % 2 == 0:",
"- B[l - i] = str(A[i])",
"- l = l - i",
"- else:",
"- B[l + i] = str(A[i])",
"- l = l + i",
"+ B.append(a)"
] | false | 0.034183 | 0.032964 | 1.036971 | [
"s436084237",
"s318974300"
] |
u294520705 | p02837 | python | s643119716 | s271002889 | 142 | 106 | 3,064 | 3,064 | Accepted | Accepted | 25.35 | import itertools
n = int(eval(input()))
data = {}
for x in range(n):
data[x] = []
for y in range(int(eval(input()))):
k, l = list(map(int, input().split()))
data[x].append((k - 1, l))
ans = 0
for i in itertools.product([1,0], repeat=n):
h = True
for x in range(n):
if i[x] == 1:
for g in data[x]:
if i[g[0]] != g[1]:
h = False
if h == False:
break
if h == True:
ans = max(ans, sum(list(i)))
print(ans) | import itertools
n = int(eval(input()))
data = []
for x in range(n):
for y in range(int(eval(input()))):
k, l = list(map(int, input().split()))
data.append((x, k - 1, l))
ans = 0
for i in itertools.product([1,0], repeat=n):
s = sum(list(i))
for g in data:
if i[g[0]] == 1 and i[g[1]] != g[2]:
s = 0
break
ans = max(ans, s)
print(ans) | 22 | 16 | 525 | 394 | import itertools
n = int(eval(input()))
data = {}
for x in range(n):
data[x] = []
for y in range(int(eval(input()))):
k, l = list(map(int, input().split()))
data[x].append((k - 1, l))
ans = 0
for i in itertools.product([1, 0], repeat=n):
h = True
for x in range(n):
if i[x] == 1:
for g in data[x]:
if i[g[0]] != g[1]:
h = False
if h == False:
break
if h == True:
ans = max(ans, sum(list(i)))
print(ans)
| import itertools
n = int(eval(input()))
data = []
for x in range(n):
for y in range(int(eval(input()))):
k, l = list(map(int, input().split()))
data.append((x, k - 1, l))
ans = 0
for i in itertools.product([1, 0], repeat=n):
s = sum(list(i))
for g in data:
if i[g[0]] == 1 and i[g[1]] != g[2]:
s = 0
break
ans = max(ans, s)
print(ans)
| false | 27.272727 | [
"-data = {}",
"+data = []",
"- data[x] = []",
"- data[x].append((k - 1, l))",
"+ data.append((x, k - 1, l))",
"- h = True",
"- for x in range(n):",
"- if i[x] == 1:",
"- for g in data[x]:",
"- if i[g[0]] != g[1]:",
"- h = False",
"- if h == False:",
"+ s = sum(list(i))",
"+ for g in data:",
"+ if i[g[0]] == 1 and i[g[1]] != g[2]:",
"+ s = 0",
"- if h == True:",
"- ans = max(ans, sum(list(i)))",
"+ ans = max(ans, s)"
] | false | 0.037007 | 0.037168 | 0.995679 | [
"s643119716",
"s271002889"
] |
u362347649 | p03295 | python | s830792210 | s092941946 | 368 | 159 | 18,212 | 29,956 | Accepted | Accepted | 56.79 | from operator import itemgetter
def main():
N, M = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(M)]
ab.sort(key=itemgetter(1))
east_island = ab[0][1]
answer = 1
for i, j in ab:
if i >= east_island:
answer += 1
east_island = j
print(answer)
if __name__ == '__main__':
main() | import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, M = list(map(int, readline().split()))
ab = list(map(int, read().split()))
ab = sorted(zip(ab, ab), key=itemgetter(1))
east_island = ab[0][1]
answer = 1
for i, j in ab:
if i >= east_island:
answer += 1
east_island = j
print(answer)
if __name__ == '__main__':
main() | 19 | 24 | 375 | 494 | from operator import itemgetter
def main():
N, M = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(M)]
ab.sort(key=itemgetter(1))
east_island = ab[0][1]
answer = 1
for i, j in ab:
if i >= east_island:
answer += 1
east_island = j
print(answer)
if __name__ == "__main__":
main()
| import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, M = list(map(int, readline().split()))
ab = list(map(int, read().split()))
ab = sorted(zip(ab, ab), key=itemgetter(1))
east_island = ab[0][1]
answer = 1
for i, j in ab:
if i >= east_island:
answer += 1
east_island = j
print(answer)
if __name__ == "__main__":
main()
| false | 20.833333 | [
"+import sys",
"+",
"+read = sys.stdin.read",
"+readline = sys.stdin.readline",
"+readlines = sys.stdin.readlines",
"- N, M = list(map(int, input().split()))",
"- ab = [tuple(map(int, input().split())) for _ in range(M)]",
"- ab.sort(key=itemgetter(1))",
"+ N, M = list(map(int, readline().split()))",
"+ ab = list(map(int, read().split()))",
"+ ab = sorted(zip(ab, ab), key=itemgetter(1))"
] | false | 0.036615 | 0.045961 | 0.796652 | [
"s830792210",
"s092941946"
] |
u407160848 | p02745 | python | s291712992 | s830029476 | 1,779 | 1,274 | 53,192 | 74,172 | Accepted | Accepted | 28.39 | a = eval(input())
b = eval(input())
c = eval(input())
# 文字のマッチング(?はワイルドカード)
def match(a, b):
return a=="?" or b=="?" or a==b
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
def check(a, b, ab):
for i in range(len(a)):
for j in range(len(b)):
if not match(a[i], b[j]):
ab[i-j+50000] = False
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
ans = len_a + len_b + len_c
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
# j = CをAに対していくつスライドして置くか
for j in range(-2 * len_max, 2 * len_max + 1):
if ab[i+50000] and ac[j+50000] and bc[j-i+50000]:
ans = min(ans, max(len_a, len_b+i, len_c+j) - min(0, i, j))
print(ans)
| a = eval(input())
b = eval(input())
c = eval(input())
# 文字のマッチング(?はワイルドカード)
def match(a, b):
return a=="?" or b=="?" or a==b
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
def check(a, b, ab):
for i in range(len(a)):
for j in range(len(b)):
if not match(a[i], b[j]):
ab[i-j+50000] = False
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
ans = len_a + len_b + len_c
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
# j = CをAに対していくつスライドして置くか
for j in range(-2 * len_max, 2 * len_max + 1):
if ab[i+50000] and ac[j+50000] and bc[j-i+50000]:
ans = min(ans, max(len_a, len_b+i, len_c+j) - min(0, i, j))
print(ans) | 37 | 37 | 914 | 921 | a = eval(input())
b = eval(input())
c = eval(input())
# 文字のマッチング(?はワイルドカード)
def match(a, b):
return a == "?" or b == "?" or a == b
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
def check(a, b, ab):
for i in range(len(a)):
for j in range(len(b)):
if not match(a[i], b[j]):
ab[i - j + 50000] = False
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
ans = len_a + len_b + len_c
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
# j = CをAに対していくつスライドして置くか
for j in range(-2 * len_max, 2 * len_max + 1):
if ab[i + 50000] and ac[j + 50000] and bc[j - i + 50000]:
ans = min(ans, max(len_a, len_b + i, len_c + j) - min(0, i, j))
print(ans)
| a = eval(input())
b = eval(input())
c = eval(input())
# 文字のマッチング(?はワイルドカード)
def match(a, b):
return a == "?" or b == "?" or a == b
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
def check(a, b, ab):
for i in range(len(a)):
for j in range(len(b)):
if not match(a[i], b[j]):
ab[i - j + 50000] = False
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
ans = len_a + len_b + len_c
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
# j = CをAに対していくつスライドして置くか
for j in range(-2 * len_max, 2 * len_max + 1):
if ab[i + 50000] and ac[j + 50000] and bc[j - i + 50000]:
ans = min(ans, max(len_a, len_b + i, len_c + j) - min(0, i, j))
print(ans)
| false | 0 | [
"-ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?",
"-ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?",
"-bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?",
"+ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?",
"+ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?",
"+bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?"
] | false | 0.045521 | 0.108577 | 0.419249 | [
"s291712992",
"s830029476"
] |
u989345508 | p03145 | python | s235840116 | s269560022 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | ab,bc,ca=input().split()
ab,bc,ca=int(ab),int(bc),int(ca)
print((ab*bc//2))
| a,b,_=list(map(int,input().split()))
print((a*b//2)) | 4 | 2 | 78 | 45 | ab, bc, ca = input().split()
ab, bc, ca = int(ab), int(bc), int(ca)
print((ab * bc // 2))
| a, b, _ = list(map(int, input().split()))
print((a * b // 2))
| false | 50 | [
"-ab, bc, ca = input().split()",
"-ab, bc, ca = int(ab), int(bc), int(ca)",
"-print((ab * bc // 2))",
"+a, b, _ = list(map(int, input().split()))",
"+print((a * b // 2))"
] | false | 0.050316 | 0.04957 | 1.015042 | [
"s235840116",
"s269560022"
] |
u692453235 | p03160 | python | s523119804 | s351387000 | 135 | 123 | 20,460 | 20,388 | Accepted | Accepted | 8.89 | N = int(eval(input()))
H = list(map(int, input().split()))
dp = [0]*N
for i, x in enumerate(H):
if i == 0:
continue
elif i == 1:
dp[i] = abs(H[i]-H[i-1])
else:
dp[i] = min( dp[i-2] + abs(H[i] - H[i-2]) , dp[i-1] + abs( H[i] - H[i-1] ))
print((dp[-1])) | N = int(eval(input()))
H = list(map(int, input().split()))
dp = [0]
for i, x in enumerate(H):
if i == 0:
continue
elif i == 1:
dp.append( abs(H[i] - H[i-1]) )
else:
dp.append( min( dp[i-2] + abs(H[i] - H[i-2]) , dp[i-1] + abs(H[i] - H[i-1]) ) )
print((dp[-1])) | 14 | 14 | 277 | 286 | N = int(eval(input()))
H = list(map(int, input().split()))
dp = [0] * N
for i, x in enumerate(H):
if i == 0:
continue
elif i == 1:
dp[i] = abs(H[i] - H[i - 1])
else:
dp[i] = min(dp[i - 2] + abs(H[i] - H[i - 2]), dp[i - 1] + abs(H[i] - H[i - 1]))
print((dp[-1]))
| N = int(eval(input()))
H = list(map(int, input().split()))
dp = [0]
for i, x in enumerate(H):
if i == 0:
continue
elif i == 1:
dp.append(abs(H[i] - H[i - 1]))
else:
dp.append(
min(dp[i - 2] + abs(H[i] - H[i - 2]), dp[i - 1] + abs(H[i] - H[i - 1]))
)
print((dp[-1]))
| false | 0 | [
"-dp = [0] * N",
"+dp = [0]",
"- dp[i] = abs(H[i] - H[i - 1])",
"+ dp.append(abs(H[i] - H[i - 1]))",
"- dp[i] = min(dp[i - 2] + abs(H[i] - H[i - 2]), dp[i - 1] + abs(H[i] - H[i - 1]))",
"+ dp.append(",
"+ min(dp[i - 2] + abs(H[i] - H[i - 2]), dp[i - 1] + abs(H[i] - H[i - 1]))",
"+ )"
] | false | 0.147598 | 0.104462 | 1.412945 | [
"s523119804",
"s351387000"
] |
u279493135 | p03696 | python | s421187441 | s342581653 | 162 | 17 | 13,588 | 3,060 | Accepted | Accepted | 89.51 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
S = eval(input())
T = S
while 1:
if T.count("()") == 0:
break
try:
T = T.replace("()", "")
except:
pass
l = 0
r = 0
for x in T:
if x == ")":
l += 1
else:
r += 1
print(("("*l + S + ")"*r))
| N = int(eval(input()))
S = eval(input())
l = 0
r = 0
for s in S:
if s == "(":
r += 1
else:
if r >= 1:
r -= 1
else:
l += 1
print(("("*l + S + ")"*r)) | 39 | 15 | 905 | 180 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import numpy as np
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
S = eval(input())
T = S
while 1:
if T.count("()") == 0:
break
try:
T = T.replace("()", "")
except:
pass
l = 0
r = 0
for x in T:
if x == ")":
l += 1
else:
r += 1
print(("(" * l + S + ")" * r))
| N = int(eval(input()))
S = eval(input())
l = 0
r = 0
for s in S:
if s == "(":
r += 1
else:
if r >= 1:
r -= 1
else:
l += 1
print(("(" * l + S + ")" * r))
| false | 61.538462 | [
"-import sys, re",
"-from collections import deque, defaultdict, Counter",
"-from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees",
"-from itertools import permutations, combinations, product, accumulate",
"-from operator import itemgetter, mul",
"-from copy import deepcopy",
"-from string import ascii_lowercase, ascii_uppercase, digits",
"-from fractions import gcd",
"-from bisect import bisect",
"-import numpy as np",
"-",
"-",
"-def input():",
"- return sys.stdin.readline().strip()",
"-",
"-",
"-def INT():",
"- return int(eval(input()))",
"-",
"-",
"-def MAP():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def LIST():",
"- return list(map(int, input().split()))",
"-",
"-",
"-sys.setrecursionlimit(10**9)",
"-INF = float(\"inf\")",
"-mod = 10**9 + 7",
"-N = INT()",
"+N = int(eval(input()))",
"-T = S",
"-while 1:",
"- if T.count(\"()\") == 0:",
"- break",
"- try:",
"- T = T.replace(\"()\", \"\")",
"- except:",
"- pass",
"-for x in T:",
"- if x == \")\":",
"- l += 1",
"+for s in S:",
"+ if s == \"(\":",
"+ r += 1",
"- r += 1",
"+ if r >= 1:",
"+ r -= 1",
"+ else:",
"+ l += 1"
] | false | 0.100011 | 0.035764 | 2.79639 | [
"s421187441",
"s342581653"
] |
u022579771 | p02397 | python | s805708720 | s857971388 | 70 | 40 | 8,068 | 7,912 | Accepted | Accepted | 42.86 | import sys
for in_str in sys.stdin:
comp_list = list(map(int, in_str.split(" ")))
# a, b = map(int, in_str.split())
a = comp_list[0]
b = comp_list[1]
if (a == 0) & (b == 0) : break
elif a < b :
print((a, b))
else :
print((b, a)) | import sys
for in_str in sys.stdin:
comp_list = list(map(int, in_str.split(" ")))
# a, b = map(int, in_str.split())
a = comp_list[0]
b = comp_list[1]
if a == 0 and b == 0 : break
elif a < b :
print((a, b))
else :
print((b, a)) | 12 | 12 | 279 | 277 | import sys
for in_str in sys.stdin:
comp_list = list(map(int, in_str.split(" ")))
# a, b = map(int, in_str.split())
a = comp_list[0]
b = comp_list[1]
if (a == 0) & (b == 0):
break
elif a < b:
print((a, b))
else:
print((b, a))
| import sys
for in_str in sys.stdin:
comp_list = list(map(int, in_str.split(" ")))
# a, b = map(int, in_str.split())
a = comp_list[0]
b = comp_list[1]
if a == 0 and b == 0:
break
elif a < b:
print((a, b))
else:
print((b, a))
| false | 0 | [
"- if (a == 0) & (b == 0):",
"+ if a == 0 and b == 0:"
] | false | 0.045965 | 0.038935 | 1.180556 | [
"s805708720",
"s857971388"
] |
u019637926 | p03163 | python | s075199944 | s886866313 | 672 | 270 | 171,656 | 41,580 | Accepted | Accepted | 59.82 | N, W = list(map(int, input().split()))
Bs = []
for i in range(N):
Bs.append(tuple(map(int, input().split())))
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
for j in range(W + 1):
dp[i][j] = max(dp[i + 1][j], (dp[i + 1][j - Bs[i][0]] + Bs[i][1]) if j >= Bs[i][0] else 0)
print((dp[0][W])) | N, W = list(map(int, input().split()))
Bs = [tuple(map(int, input().split())) for _ in range(N)]
dp = [0] * (W + 1)
for w, v in Bs:
for i in range(W, w - 1, -1):
dp[i] = max(dp[i], dp[i - w] + v)
print((dp[W]))
| 11 | 9 | 353 | 225 | N, W = list(map(int, input().split()))
Bs = []
for i in range(N):
Bs.append(tuple(map(int, input().split())))
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
for j in range(W + 1):
dp[i][j] = max(
dp[i + 1][j], (dp[i + 1][j - Bs[i][0]] + Bs[i][1]) if j >= Bs[i][0] else 0
)
print((dp[0][W]))
| N, W = list(map(int, input().split()))
Bs = [tuple(map(int, input().split())) for _ in range(N)]
dp = [0] * (W + 1)
for w, v in Bs:
for i in range(W, w - 1, -1):
dp[i] = max(dp[i], dp[i - w] + v)
print((dp[W]))
| false | 18.181818 | [
"-Bs = []",
"-for i in range(N):",
"- Bs.append(tuple(map(int, input().split())))",
"-dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]",
"-for i in range(N - 1, -1, -1):",
"- for j in range(W + 1):",
"- dp[i][j] = max(",
"- dp[i + 1][j], (dp[i + 1][j - Bs[i][0]] + Bs[i][1]) if j >= Bs[i][0] else 0",
"- )",
"-print((dp[0][W]))",
"+Bs = [tuple(map(int, input().split())) for _ in range(N)]",
"+dp = [0] * (W + 1)",
"+for w, v in Bs:",
"+ for i in range(W, w - 1, -1):",
"+ dp[i] = max(dp[i], dp[i - w] + v)",
"+print((dp[W]))"
] | false | 0.041791 | 0.193526 | 0.215947 | [
"s075199944",
"s886866313"
] |
u307516601 | p02629 | python | s042432674 | s283562077 | 32 | 25 | 9,196 | 9,192 | Accepted | Accepted | 21.88 | import sys
sys.setrecursionlimit(10**6)
n = int(eval(input()))
d = {(i-97+1):chr(i) for i in range(97,97+26)}
d[0] = 'z'
l = []
while n > 0:
tmp = n%26
l.append(tmp)
if tmp == 0:
n = n//26-1
else:
n //= 26
ans = ''
for i in l[::-1]:
ans += d[i]
print(ans) | import sys
sys.setrecursionlimit(10**6)
n = int(eval(input()))
d = {(i-97+1)%26:chr(i) for i in range(97,97+26)}
#d[0] = 'z'
l = []
while n > 0:
tmp = n%26
l.append(tmp)
if tmp == 0:
n = n//26-1
else:
n //= 26
ans = ''
for i in l[::-1]:
ans += d[i]
print(ans) | 24 | 24 | 319 | 323 | import sys
sys.setrecursionlimit(10**6)
n = int(eval(input()))
d = {(i - 97 + 1): chr(i) for i in range(97, 97 + 26)}
d[0] = "z"
l = []
while n > 0:
tmp = n % 26
l.append(tmp)
if tmp == 0:
n = n // 26 - 1
else:
n //= 26
ans = ""
for i in l[::-1]:
ans += d[i]
print(ans)
| import sys
sys.setrecursionlimit(10**6)
n = int(eval(input()))
d = {(i - 97 + 1) % 26: chr(i) for i in range(97, 97 + 26)}
# d[0] = 'z'
l = []
while n > 0:
tmp = n % 26
l.append(tmp)
if tmp == 0:
n = n // 26 - 1
else:
n //= 26
ans = ""
for i in l[::-1]:
ans += d[i]
print(ans)
| false | 0 | [
"-d = {(i - 97 + 1): chr(i) for i in range(97, 97 + 26)}",
"-d[0] = \"z\"",
"+d = {(i - 97 + 1) % 26: chr(i) for i in range(97, 97 + 26)}",
"+# d[0] = 'z'"
] | false | 0.085371 | 0.043889 | 1.945176 | [
"s042432674",
"s283562077"
] |
u374146618 | p03106 | python | s901388368 | s884141218 | 20 | 17 | 3,064 | 3,060 | Accepted | Accepted | 15 | a, b, k = [int(x) for x in input().split()]
# a,bの最大公約数
def gcd(A, B):
if A%B == 0:
return B
return gcd(B, A%B)
# 約数を列挙。
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
wk1 = gcd(a, b)
wk2 = make_divisors(wk1)
ans = wk2[-k]
print(ans) | a, b, k = [int(x) for x in input().split()]
cnt = 0
N = min(a, b)
for i in range(N, 0, -1):
if a%i == 0 and b%i == 0:
cnt += 1
if cnt == k:
print(i)
break | 23 | 10 | 465 | 196 | a, b, k = [int(x) for x in input().split()]
# a,bの最大公約数
def gcd(A, B):
if A % B == 0:
return B
return gcd(B, A % B)
# 約数を列挙。
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
wk1 = gcd(a, b)
wk2 = make_divisors(wk1)
ans = wk2[-k]
print(ans)
| a, b, k = [int(x) for x in input().split()]
cnt = 0
N = min(a, b)
for i in range(N, 0, -1):
if a % i == 0 and b % i == 0:
cnt += 1
if cnt == k:
print(i)
break
| false | 56.521739 | [
"-# a,bの最大公約数",
"-def gcd(A, B):",
"- if A % B == 0:",
"- return B",
"- return gcd(B, A % B)",
"-",
"-",
"-# 約数を列挙。",
"-def make_divisors(n):",
"- divisors = []",
"- for i in range(1, int(n**0.5) + 1):",
"- if n % i == 0:",
"- divisors.append(i)",
"- if i != n // i:",
"- divisors.append(n // i)",
"- divisors.sort()",
"- return divisors",
"-",
"-",
"-wk1 = gcd(a, b)",
"-wk2 = make_divisors(wk1)",
"-ans = wk2[-k]",
"-print(ans)",
"+cnt = 0",
"+N = min(a, b)",
"+for i in range(N, 0, -1):",
"+ if a % i == 0 and b % i == 0:",
"+ cnt += 1",
"+ if cnt == k:",
"+ print(i)",
"+ break"
] | false | 0.048966 | 0.04738 | 1.033461 | [
"s901388368",
"s884141218"
] |
u693378622 | p02837 | python | s855041348 | s058819884 | 243 | 83 | 3,064 | 3,064 | Accepted | Accepted | 65.84 | n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
k = int(eval(input()))
a.append(k)
for j in range(k):
x[i].append(list(map(int,input().split())))
# print(x)
ans = 0
for i in range(1<<n):
cnt = bin(i).count("1")
if ans > cnt:
continue
flag = True
for j in range(n):
# if i==3:
# print(i,j,i>>j&1,cnt)
if i>>j & 1:
# True if 1
# if i==3:
# print(i,j)
for t in x[j]:
# 証言:testimony
# if i == 3:
# print(i,t[0]-1, i>>t[0]-1, t[1])
if (i>>(t[0]-1) &1 ) != t[1]:
flag = False
break
# if flag == False:
# break
if flag == True:
# print(i) # 0 000
ans = cnt
print(ans)
| n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
k = int(eval(input()))
a.append(k)
for j in range(k):
x[i].append(list(map(int,input().split())))
# print(x)
ans = 0
for i in range(1<<n):
cnt = bin(i).count("1")
if ans > cnt:
continue
flag = True
for j in range(n):
# if i==3:
# print(i,j,i>>j&1,cnt)
if i>>j & 1:
# True if 1
# if i==3:
# print(i,j)
for t in x[j]:
# 証言:testimony
# if i == 3:
# print(i,t[0]-1, i>>t[0]-1, t[1])
if (i>>(t[0]-1) &1 ) != t[1]:
flag = False
break
if flag == False:
break
if flag == True:
# print(i) # 0 000
ans = cnt
print(ans)
| 42 | 42 | 901 | 905 | n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
k = int(eval(input()))
a.append(k)
for j in range(k):
x[i].append(list(map(int, input().split())))
# print(x)
ans = 0
for i in range(1 << n):
cnt = bin(i).count("1")
if ans > cnt:
continue
flag = True
for j in range(n):
# if i==3:
# print(i,j,i>>j&1,cnt)
if i >> j & 1:
# True if 1
# if i==3:
# print(i,j)
for t in x[j]:
# 証言:testimony
# if i == 3:
# print(i,t[0]-1, i>>t[0]-1, t[1])
if (i >> (t[0] - 1) & 1) != t[1]:
flag = False
break
# if flag == False:
# break
if flag == True:
# print(i) # 0 000
ans = cnt
print(ans)
| n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
k = int(eval(input()))
a.append(k)
for j in range(k):
x[i].append(list(map(int, input().split())))
# print(x)
ans = 0
for i in range(1 << n):
cnt = bin(i).count("1")
if ans > cnt:
continue
flag = True
for j in range(n):
# if i==3:
# print(i,j,i>>j&1,cnt)
if i >> j & 1:
# True if 1
# if i==3:
# print(i,j)
for t in x[j]:
# 証言:testimony
# if i == 3:
# print(i,t[0]-1, i>>t[0]-1, t[1])
if (i >> (t[0] - 1) & 1) != t[1]:
flag = False
break
if flag == False:
break
if flag == True:
# print(i) # 0 000
ans = cnt
print(ans)
| false | 0 | [
"- # if flag == False:",
"- # break",
"+ if flag == False:",
"+ break"
] | false | 0.037748 | 0.031665 | 1.192102 | [
"s855041348",
"s058819884"
] |
u453815934 | p03295 | python | s105818595 | s798337333 | 427 | 382 | 22,108 | 30,384 | Accepted | Accepted | 10.54 | a,b=list(map(int,input().split()))
List=[]
for i in range(b):
p,q=list(map(int,input().split()))
List.append([p,q])
List=sorted(List,key=lambda x:x[1])
ans=0
l=1
for i in range(b):
if List[i][0]>=l:
ans+=1
l=List[i][1]
print(ans) | import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi() : return list(map(int,sys.stdin.readline().split()))
def ii() : return int(sys.stdin.readline().rstrip())
a,b=mi()
l=[list(mi()) for _ in range(b)]
l=sorted(l,key=lambda x:x[1])
q=deque([1,1])
ans=0
for i,j in l:
y=q.pop()
x=q.pop()
if i<x:
q.append(x)
q.append(y)
else:
ans+=1
q.append(j)
q.append(j)
print(ans)
| 13 | 24 | 243 | 484 | a, b = list(map(int, input().split()))
List = []
for i in range(b):
p, q = list(map(int, input().split()))
List.append([p, q])
List = sorted(List, key=lambda x: x[1])
ans = 0
l = 1
for i in range(b):
if List[i][0] >= l:
ans += 1
l = List[i][1]
print(ans)
| import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi():
return list(map(int, sys.stdin.readline().split()))
def ii():
return int(sys.stdin.readline().rstrip())
a, b = mi()
l = [list(mi()) for _ in range(b)]
l = sorted(l, key=lambda x: x[1])
q = deque([1, 1])
ans = 0
for i, j in l:
y = q.pop()
x = q.pop()
if i < x:
q.append(x)
q.append(y)
else:
ans += 1
q.append(j)
q.append(j)
print(ans)
| false | 45.833333 | [
"-a, b = list(map(int, input().split()))",
"-List = []",
"-for i in range(b):",
"- p, q = list(map(int, input().split()))",
"- List.append([p, q])",
"-List = sorted(List, key=lambda x: x[1])",
"+import math",
"+import sys",
"+from collections import deque",
"+import copy",
"+import itertools",
"+from itertools import permutations",
"+",
"+",
"+def mi():",
"+ return list(map(int, sys.stdin.readline().split()))",
"+",
"+",
"+def ii():",
"+ return int(sys.stdin.readline().rstrip())",
"+",
"+",
"+a, b = mi()",
"+l = [list(mi()) for _ in range(b)]",
"+l = sorted(l, key=lambda x: x[1])",
"+q = deque([1, 1])",
"-l = 1",
"-for i in range(b):",
"- if List[i][0] >= l:",
"+for i, j in l:",
"+ y = q.pop()",
"+ x = q.pop()",
"+ if i < x:",
"+ q.append(x)",
"+ q.append(y)",
"+ else:",
"- l = List[i][1]",
"+ q.append(j)",
"+ q.append(j)"
] | false | 0.079697 | 0.042735 | 1.864914 | [
"s105818595",
"s798337333"
] |
u112247039 | p02767 | python | s678424779 | s103494511 | 32 | 25 | 9,112 | 9,104 | Accepted | Accepted | 21.88 | import sys
readline = sys.stdin.readline
N = int(readline())
X = list(map(int, readline().split()))
X.sort()
INF = 10**9+7
ans = INF
for p in range(0, 102):
res = 0
for x in X:
res += (p-x)**2
ans = min(ans, res)
print(ans)
| n = int(eval(input()))
(*x,) = list(map(int, input().split()))
a = round(sum(x) / n)
print((sum(((i - a) ** 2) for i in x))) | 14 | 4 | 258 | 113 | import sys
readline = sys.stdin.readline
N = int(readline())
X = list(map(int, readline().split()))
X.sort()
INF = 10**9 + 7
ans = INF
for p in range(0, 102):
res = 0
for x in X:
res += (p - x) ** 2
ans = min(ans, res)
print(ans)
| n = int(eval(input()))
(*x,) = list(map(int, input().split()))
a = round(sum(x) / n)
print((sum(((i - a) ** 2) for i in x)))
| false | 71.428571 | [
"-import sys",
"-",
"-readline = sys.stdin.readline",
"-N = int(readline())",
"-X = list(map(int, readline().split()))",
"-X.sort()",
"-INF = 10**9 + 7",
"-ans = INF",
"-for p in range(0, 102):",
"- res = 0",
"- for x in X:",
"- res += (p - x) ** 2",
"- ans = min(ans, res)",
"-print(ans)",
"+n = int(eval(input()))",
"+(*x,) = list(map(int, input().split()))",
"+a = round(sum(x) / n)",
"+print((sum(((i - a) ** 2) for i in x)))"
] | false | 0.035991 | 0.037226 | 0.966827 | [
"s678424779",
"s103494511"
] |
u852798899 | p02755 | python | s039730280 | s741597472 | 25 | 18 | 3,060 | 3,060 | Accepted | Accepted | 28 | import math
a, b= list(map(int, input().split()))
for n in range(1, 20000):
if math.floor(n*0.08) == a and math.floor(n*0.1) == b:
break
if n != 19999:
print(n)
else:
print((-1)) | import math
a, b= list(map(int, input().split()))
for n in range(1, 1010):
aa, bb = math.floor(n*0.08), math.floor(n*0.1)
if aa == a and bb == b:
print(n)
exit()
print((-1)) | 10 | 8 | 194 | 187 | import math
a, b = list(map(int, input().split()))
for n in range(1, 20000):
if math.floor(n * 0.08) == a and math.floor(n * 0.1) == b:
break
if n != 19999:
print(n)
else:
print((-1))
| import math
a, b = list(map(int, input().split()))
for n in range(1, 1010):
aa, bb = math.floor(n * 0.08), math.floor(n * 0.1)
if aa == a and bb == b:
print(n)
exit()
print((-1))
| false | 20 | [
"-for n in range(1, 20000):",
"- if math.floor(n * 0.08) == a and math.floor(n * 0.1) == b:",
"- break",
"-if n != 19999:",
"- print(n)",
"-else:",
"- print((-1))",
"+for n in range(1, 1010):",
"+ aa, bb = math.floor(n * 0.08), math.floor(n * 0.1)",
"+ if aa == a and bb == b:",
"+ print(n)",
"+ exit()",
"+print((-1))"
] | false | 0.039334 | 0.042889 | 0.91711 | [
"s039730280",
"s741597472"
] |
u501278784 | p02547 | python | s470432250 | s982830793 | 76 | 59 | 62,508 | 62,684 | Accepted | Accepted | 22.37 | n=int(eval(input()))
idx=[]
c=0
for i in range(n):
x,y=list(map(int,input().split()))
if x==y:
idx.append(c)
c+=1
if len(idx)<3:
print('No')
else:
flag=False
#print(idx)
for i in range(len(idx)-2):
if idx[i]-idx[i+1]==-1 and idx[i+1]-idx[i+2]==-1:
flag=True
break
dd={False:'No',True:'Yes'}
print((dd[flag]))
| import sys
def main():
n=int(eval(input()))
idx=[]
c=0
for i in range(n):
x,y=list(map(int,input().split()))
if x==y:
idx.append(c)
c+=1
if len(idx)<3:
print('No')
else:
flag=False
#print(idx)
for i in range(len(idx)-2):
if idx[i]-idx[i+1]==-1 and idx[i+1]-idx[i+2]==-1:
flag=True
break
dd={False:'No',True:'Yes'}
print((dd[flag]))
try:
sys.stdin = open('INP01.txt', 'r')
# Printing the Output to output.txt file
sys.stdout = open('out.txt', 'w')
main()
except:
main()
| 26 | 30 | 359 | 551 | n = int(eval(input()))
idx = []
c = 0
for i in range(n):
x, y = list(map(int, input().split()))
if x == y:
idx.append(c)
c += 1
if len(idx) < 3:
print("No")
else:
flag = False
# print(idx)
for i in range(len(idx) - 2):
if idx[i] - idx[i + 1] == -1 and idx[i + 1] - idx[i + 2] == -1:
flag = True
break
dd = {False: "No", True: "Yes"}
print((dd[flag]))
| import sys
def main():
n = int(eval(input()))
idx = []
c = 0
for i in range(n):
x, y = list(map(int, input().split()))
if x == y:
idx.append(c)
c += 1
if len(idx) < 3:
print("No")
else:
flag = False
# print(idx)
for i in range(len(idx) - 2):
if idx[i] - idx[i + 1] == -1 and idx[i + 1] - idx[i + 2] == -1:
flag = True
break
dd = {False: "No", True: "Yes"}
print((dd[flag]))
try:
sys.stdin = open("INP01.txt", "r")
# Printing the Output to output.txt file
sys.stdout = open("out.txt", "w")
main()
except:
main()
| false | 13.333333 | [
"-n = int(eval(input()))",
"-idx = []",
"-c = 0",
"-for i in range(n):",
"- x, y = list(map(int, input().split()))",
"- if x == y:",
"- idx.append(c)",
"- c += 1",
"-if len(idx) < 3:",
"- print(\"No\")",
"-else:",
"- flag = False",
"- # print(idx)",
"- for i in range(len(idx) - 2):",
"- if idx[i] - idx[i + 1] == -1 and idx[i + 1] - idx[i + 2] == -1:",
"- flag = True",
"- break",
"- dd = {False: \"No\", True: \"Yes\"}",
"- print((dd[flag]))",
"+import sys",
"+",
"+",
"+def main():",
"+ n = int(eval(input()))",
"+ idx = []",
"+ c = 0",
"+ for i in range(n):",
"+ x, y = list(map(int, input().split()))",
"+ if x == y:",
"+ idx.append(c)",
"+ c += 1",
"+ if len(idx) < 3:",
"+ print(\"No\")",
"+ else:",
"+ flag = False",
"+ # print(idx)",
"+ for i in range(len(idx) - 2):",
"+ if idx[i] - idx[i + 1] == -1 and idx[i + 1] - idx[i + 2] == -1:",
"+ flag = True",
"+ break",
"+ dd = {False: \"No\", True: \"Yes\"}",
"+ print((dd[flag]))",
"+",
"+",
"+try:",
"+ sys.stdin = open(\"INP01.txt\", \"r\")",
"+ # Printing the Output to output.txt file",
"+ sys.stdout = open(\"out.txt\", \"w\")",
"+ main()",
"+except:",
"+ main()"
] | false | 0.043712 | 0.045737 | 0.955728 | [
"s470432250",
"s982830793"
] |
u970308980 | p03078 | python | s906002438 | s302095139 | 739 | 230 | 148,548 | 46,288 | Accepted | Accepted | 68.88 | 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 = []
for i in range(X):
for j in range(Y):
AB.append(A[i] + B[j])
AB.sort(reverse=True)
ABC = []
for i in range(min(K, len(AB))):
for j in range(Z):
ABC.append(AB[i] + C[j])
ABC.sort(reverse=True)
for i in range(K):
print((ABC[i]))
| 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)
ABC = []
for a in range(X):
for b in range(Y):
if (a + 1) * (b + 1) > K:
break
for c in range(Z):
if (a + 1) * (b + 1) * (c + 1) > K:
break
ABC.append(A[a] + B[b] + C[c])
ABC.sort(reverse=True)
for i in range(K):
print((ABC[i]))
| 21 | 19 | 481 | 519 | 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 = []
for i in range(X):
for j in range(Y):
AB.append(A[i] + B[j])
AB.sort(reverse=True)
ABC = []
for i in range(min(K, len(AB))):
for j in range(Z):
ABC.append(AB[i] + C[j])
ABC.sort(reverse=True)
for i in range(K):
print((ABC[i]))
| 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)
ABC = []
for a in range(X):
for b in range(Y):
if (a + 1) * (b + 1) > K:
break
for c in range(Z):
if (a + 1) * (b + 1) * (c + 1) > K:
break
ABC.append(A[a] + B[b] + C[c])
ABC.sort(reverse=True)
for i in range(K):
print((ABC[i]))
| false | 9.52381 | [
"-AB = []",
"-for i in range(X):",
"- for j in range(Y):",
"- AB.append(A[i] + B[j])",
"-AB.sort(reverse=True)",
"-for i in range(min(K, len(AB))):",
"- for j in range(Z):",
"- ABC.append(AB[i] + C[j])",
"+for a in range(X):",
"+ for b in range(Y):",
"+ if (a + 1) * (b + 1) > K:",
"+ break",
"+ for c in range(Z):",
"+ if (a + 1) * (b + 1) * (c + 1) > K:",
"+ break",
"+ ABC.append(A[a] + B[b] + C[c])"
] | false | 0.075101 | 0.036912 | 2.034589 | [
"s906002438",
"s302095139"
] |
u912862653 | p02537 | python | s868387096 | s675324361 | 575 | 482 | 86,876 | 85,508 | Accepted | Accepted | 16.17 | from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = float("inf")
# update: node[x] を更新する
# getmin: 区間 [a, b) の最小値を返す
class SegmentTree:
def __init__(self, arr):
size = len(arr)
n = 1 << size.bit_length()
self.n = n
self.node = [0]*(2*n - 1)
for i in range(size):
self.node[i+n-1] = arr[i]
for i in reversed(list(range(n-2))):
self.node[i] = max(self.node[2*i+1], self.node[2*i+2])
def update(self, x, val):
x += (self.n - 1)
self.node[x] = val
while x > 0:
x = (x - 1) // 2
self.node[x] = max(self.node[2*x+1], self.node[2*x+2])
def getmax(self, l, r):
res = 0
l += self.n - 1
r += self.n - 1
while l <= r:
res = max(res, self.node[l])
res = max(res, self.node[r])
l = l // 2
r = r // 2 - 1
return res
# 処理内容
def main():
N, K = list(map(int, input().split()))
seg = SegmentTree([0]*300010)
ans = 0
for _ in range(N):
A = int(eval(input()))
a = max(A-K, 0)
b = min(A+K, 300000)
tmp = seg.getmax(a, b) + 1
ans = max(ans, tmp)
seg.update(A, tmp)
print(ans)
if __name__ == '__main__':
main() | from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = float("inf")
# update: node[x] を更新する
# getmin: 区間 [a, b) の最小値を返す
class SegmentTree:
def __init__(self, arr):
size = len(arr)
n = 1 << size.bit_length()
self.n = n
self.node = [0]*(2*n - 1)
for i in range(size):
self.node[i+n-1] = arr[i]
for i in reversed(list(range(n-2))):
self.node[i] = max(self.node[2*i+1], self.node[2*i+2])
def update(self, x, val):
x += (self.n - 1)
self.node[x] = val
while x > 0:
x = (x - 1) // 2
self.node[x] = max(self.node[2*x+1], self.node[2*x+2])
def getmax(self, a, b):
res = 0
l = self.n - 1 + a
r = self.n - 1 + (b-1)
while l <= r:
res = max(res, self.node[l])
res = max(res, self.node[r])
l = l // 2
r = r // 2 - 1
return res
# 処理内容
def main():
N, K = list(map(int, input().split()))
seg = SegmentTree([0]*300010)
for _ in range(N):
A = int(eval(input()))
a = max(A-K, 0)
b = min(A+K, 300000)
tmp = seg.getmax(a, b+1) + 1
seg.update(A, tmp)
print((seg.getmax(0, 300000)))
if __name__ == '__main__':
main() | 62 | 60 | 1,472 | 1,460 | from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = float("inf")
# update: node[x] を更新する
# getmin: 区間 [a, b) の最小値を返す
class SegmentTree:
def __init__(self, arr):
size = len(arr)
n = 1 << size.bit_length()
self.n = n
self.node = [0] * (2 * n - 1)
for i in range(size):
self.node[i + n - 1] = arr[i]
for i in reversed(list(range(n - 2))):
self.node[i] = max(self.node[2 * i + 1], self.node[2 * i + 2])
def update(self, x, val):
x += self.n - 1
self.node[x] = val
while x > 0:
x = (x - 1) // 2
self.node[x] = max(self.node[2 * x + 1], self.node[2 * x + 2])
def getmax(self, l, r):
res = 0
l += self.n - 1
r += self.n - 1
while l <= r:
res = max(res, self.node[l])
res = max(res, self.node[r])
l = l // 2
r = r // 2 - 1
return res
# 処理内容
def main():
N, K = list(map(int, input().split()))
seg = SegmentTree([0] * 300010)
ans = 0
for _ in range(N):
A = int(eval(input()))
a = max(A - K, 0)
b = min(A + K, 300000)
tmp = seg.getmax(a, b) + 1
ans = max(ans, tmp)
seg.update(A, tmp)
print(ans)
if __name__ == "__main__":
main()
| from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = float("inf")
# update: node[x] を更新する
# getmin: 区間 [a, b) の最小値を返す
class SegmentTree:
def __init__(self, arr):
size = len(arr)
n = 1 << size.bit_length()
self.n = n
self.node = [0] * (2 * n - 1)
for i in range(size):
self.node[i + n - 1] = arr[i]
for i in reversed(list(range(n - 2))):
self.node[i] = max(self.node[2 * i + 1], self.node[2 * i + 2])
def update(self, x, val):
x += self.n - 1
self.node[x] = val
while x > 0:
x = (x - 1) // 2
self.node[x] = max(self.node[2 * x + 1], self.node[2 * x + 2])
def getmax(self, a, b):
res = 0
l = self.n - 1 + a
r = self.n - 1 + (b - 1)
while l <= r:
res = max(res, self.node[l])
res = max(res, self.node[r])
l = l // 2
r = r // 2 - 1
return res
# 処理内容
def main():
N, K = list(map(int, input().split()))
seg = SegmentTree([0] * 300010)
for _ in range(N):
A = int(eval(input()))
a = max(A - K, 0)
b = min(A + K, 300000)
tmp = seg.getmax(a, b + 1) + 1
seg.update(A, tmp)
print((seg.getmax(0, 300000)))
if __name__ == "__main__":
main()
| false | 3.225806 | [
"- def getmax(self, l, r):",
"+ def getmax(self, a, b):",
"- l += self.n - 1",
"- r += self.n - 1",
"+ l = self.n - 1 + a",
"+ r = self.n - 1 + (b - 1)",
"- ans = 0",
"- tmp = seg.getmax(a, b) + 1",
"- ans = max(ans, tmp)",
"+ tmp = seg.getmax(a, b + 1) + 1",
"- print(ans)",
"+ print((seg.getmax(0, 300000)))"
] | false | 0.987725 | 1.535852 | 0.643112 | [
"s868387096",
"s675324361"
] |
u437351386 | p03722 | python | s485679348 | s292465056 | 299 | 261 | 74,676 | 74,620 | Accepted | Accepted | 12.71 | #nに行くまでの道で正の閉路があればいくらでも大きくすることができる
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
a,b,c=list(map(int,input().split()))
es.append([a-1,b-1,c])
def BellmanFord(n,s,es):
d=[-float("INF")]*n
d[s]=0
cnt=0
while(1):
update=False
for p,q,r in es:
if d[p]!=-float("INF") and d[q]<d[p]+r:
d[q]=d[p]+r
update=True
cnt+=1
if not update:
break
if cnt==n:
#負の経路がある場合
#さらにこっからn回繰り返してd[n-1]が更新されるかみる
negative=[False]*n
for i in range(n):
for p,q,r in es:
if d[q]<d[p]+r:
negative[q]=True
d[q]=d[p]+r
if negative[n-1]==True:
print("inf")
exit()
else:
print((d[n-1]))
exit()
print((d[n-1]))
BellmanFord(n,0,es) | #nに行くまでの道で正の閉路があればいくらでも大きくすることができる
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
a,b,c=list(map(int,input().split()))
es.append((a-1,b-1,c))
def BellmanFord(n,s,es):
d=[-float("INF")]*n
d[s]=0
cnt=0
while(1):
update=False
for p,q,r in es:
if d[p]!=-float("INF") and d[q]<d[p]+r:
d[q]=d[p]+r
update=True
cnt+=1
if not update:
break
if cnt==n:
#負の経路がある場合
#さらにこっからn回繰り返してd[n-1]が更新されるかみる
negative=[False]*n
for i in range(n):
for p,q,r in es:
if d[q]<d[p]+r:
negative[q]=True
d[q]=d[p]+r
if negative[n-1]==True:
print("inf")
exit()
else:
print((d[n-1]))
exit()
print((d[n-1]))
BellmanFord(n,0,es) | 41 | 41 | 827 | 827 | # nに行くまでの道で正の閉路があればいくらでも大きくすることができる
n, m = list(map(int, input().split()))
es = []
for i in range(m):
a, b, c = list(map(int, input().split()))
es.append([a - 1, b - 1, c])
def BellmanFord(n, s, es):
d = [-float("INF")] * n
d[s] = 0
cnt = 0
while 1:
update = False
for p, q, r in es:
if d[p] != -float("INF") and d[q] < d[p] + r:
d[q] = d[p] + r
update = True
cnt += 1
if not update:
break
if cnt == n:
# 負の経路がある場合
# さらにこっからn回繰り返してd[n-1]が更新されるかみる
negative = [False] * n
for i in range(n):
for p, q, r in es:
if d[q] < d[p] + r:
negative[q] = True
d[q] = d[p] + r
if negative[n - 1] == True:
print("inf")
exit()
else:
print((d[n - 1]))
exit()
print((d[n - 1]))
BellmanFord(n, 0, es)
| # nに行くまでの道で正の閉路があればいくらでも大きくすることができる
n, m = list(map(int, input().split()))
es = []
for i in range(m):
a, b, c = list(map(int, input().split()))
es.append((a - 1, b - 1, c))
def BellmanFord(n, s, es):
d = [-float("INF")] * n
d[s] = 0
cnt = 0
while 1:
update = False
for p, q, r in es:
if d[p] != -float("INF") and d[q] < d[p] + r:
d[q] = d[p] + r
update = True
cnt += 1
if not update:
break
if cnt == n:
# 負の経路がある場合
# さらにこっからn回繰り返してd[n-1]が更新されるかみる
negative = [False] * n
for i in range(n):
for p, q, r in es:
if d[q] < d[p] + r:
negative[q] = True
d[q] = d[p] + r
if negative[n - 1] == True:
print("inf")
exit()
else:
print((d[n - 1]))
exit()
print((d[n - 1]))
BellmanFord(n, 0, es)
| false | 0 | [
"- es.append([a - 1, b - 1, c])",
"+ es.append((a - 1, b - 1, c))"
] | false | 0.037658 | 0.074403 | 0.506137 | [
"s485679348",
"s292465056"
] |
u600261652 | p02718 | python | s878639044 | s095750551 | 25 | 21 | 9,176 | 9,184 | Accepted | Accepted | 16 | def resolve():
N, M = list(map(int, input().split()))
vote = list(map(int, input().split()))
bot = sorted(vote)
print(("Yes" if bot[M*-1] >= sum(vote)/(4*M) else "No"))
resolve() | def resolve():
N, M = list(map(int, input().split()))
vote = list(map(int, input().split()))
bot = sorted(vote)[M*-1:]
print(("Yes" if min(bot) >= sum(vote)/(4*M) else "No"))
resolve() | 6 | 6 | 191 | 197 | def resolve():
N, M = list(map(int, input().split()))
vote = list(map(int, input().split()))
bot = sorted(vote)
print(("Yes" if bot[M * -1] >= sum(vote) / (4 * M) else "No"))
resolve()
| def resolve():
N, M = list(map(int, input().split()))
vote = list(map(int, input().split()))
bot = sorted(vote)[M * -1 :]
print(("Yes" if min(bot) >= sum(vote) / (4 * M) else "No"))
resolve()
| false | 0 | [
"- bot = sorted(vote)",
"- print((\"Yes\" if bot[M * -1] >= sum(vote) / (4 * M) else \"No\"))",
"+ bot = sorted(vote)[M * -1 :]",
"+ print((\"Yes\" if min(bot) >= sum(vote) / (4 * M) else \"No\"))"
] | false | 0.104003 | 0.120613 | 0.862288 | [
"s878639044",
"s095750551"
] |
u892251744 | p03553 | python | s493602466 | s594007559 | 476 | 188 | 52,328 | 41,068 | Accepted | Accepted | 60.5 | from copy import deepcopy
N = int(eval(input()))
a0 = list(map(int, input().split()))
for i in range(N, 0, -1):
if a0[i - 1] < 0:
tmp = 0
b = []
for j in range(1, 101):
if i * j - 1 >= N:
break
tmp += a0[i * j - 1]
b.append(i * j - 1)
if tmp < 0:
for j in b:
a0[j] = 0
for k1 in range(N, 0, -1):
for k2 in range(k1-1, 0, -1):
a = deepcopy(a0)
for j in range(1, 101):
if k1*j-1 >= N:
break
a[k1*j-1] = 0
for j in range(1, 101):
if k2*j-1 >= N:
break
a[k2*j-1] = 0
for i in range(N, 0, -1):
if a[i - 1] < 0:
tmp = 0
b = []
for j in range(1, 101):
if i * j - 1 >= N:
break
tmp += a[i * j - 1]
b.append(i * j - 1)
if tmp < 0:
for j in b:
a[j] = 0
for i in range(N, 0, -1):
if a0[i - 1] < 0:
tmp = 0
b = []
for j in range(1, 101):
if i * j - 1 >= N:
break
tmp += a0[i * j - 1]
b.append(i * j - 1)
if tmp < 0:
for j in b:
a0[j] = 0
if sum(a) > sum(a0):
a0 = a
print((sum(a0)))
| def main():
import sys
input = sys.stdin.readline
# Dinic's algorithm
from collections import deque
class Dinic:
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap):
forward = [to, cap, None]
forward[2] = backward = [fr, 0, forward]
self.G[fr].append(forward)
self.G[to].append(backward)
def add_multi_edge(self, v1, v2, cap1, cap2):
edge1 = [v2, cap1, None]
edge1[2] = edge2 = [v1, cap2, edge1]
self.G[v1].append(edge1)
self.G[v2].append(edge2)
def bfs(self, s, t):
self.level = level = [None] * self.N
deq = deque([s])
level[s] = 0
G = self.G
while deq:
v = deq.popleft()
lv = level[v] + 1
for w, cap, _ in G[v]:
if cap and level[w] is None:
level[w] = lv
deq.append(w)
return level[t] is not None
def dfs(self, v, t, f):
if v == t:
return f
level = self.level
for e in self.it[v]:
w, cap, rev = e
if cap and level[v] < level[w]:
d = self.dfs(w, t, min(f, cap))
if d:
e[1] -= d
rev[1] += d
return d
return 0
def flow(self, s, t):
flow = 0
INF = 10 ** 9 + 7
G = self.G
while self.bfs(s, t):
*self.it, = list(map(iter, self.G))
f = INF
while f:
f = self.dfs(s, t, INF)
flow += f
return flow
inf = 1<<40
N = int(eval(input()))
A = list(map(int, input().split()))
dinic = Dinic(N+2)
ans = 0
for i, a in enumerate(A):
if a > 0:
ans += a
#dinic.add_edge(0, i+1, 0)
dinic.add_edge(i+1, N+1, a)
else:
dinic.add_edge(0, i+1, -a)
#dinic.add_edge(i+1, N+1, 0)
for i in range(1, N+1):
for k in range(1, N+1):
if i*k > N:
break
dinic.add_edge(i, i*k, inf)
print((ans - dinic.flow(0, N+1)))
if __name__ == '__main__':
main() | 58 | 87 | 1,593 | 2,532 | from copy import deepcopy
N = int(eval(input()))
a0 = list(map(int, input().split()))
for i in range(N, 0, -1):
if a0[i - 1] < 0:
tmp = 0
b = []
for j in range(1, 101):
if i * j - 1 >= N:
break
tmp += a0[i * j - 1]
b.append(i * j - 1)
if tmp < 0:
for j in b:
a0[j] = 0
for k1 in range(N, 0, -1):
for k2 in range(k1 - 1, 0, -1):
a = deepcopy(a0)
for j in range(1, 101):
if k1 * j - 1 >= N:
break
a[k1 * j - 1] = 0
for j in range(1, 101):
if k2 * j - 1 >= N:
break
a[k2 * j - 1] = 0
for i in range(N, 0, -1):
if a[i - 1] < 0:
tmp = 0
b = []
for j in range(1, 101):
if i * j - 1 >= N:
break
tmp += a[i * j - 1]
b.append(i * j - 1)
if tmp < 0:
for j in b:
a[j] = 0
for i in range(N, 0, -1):
if a0[i - 1] < 0:
tmp = 0
b = []
for j in range(1, 101):
if i * j - 1 >= N:
break
tmp += a0[i * j - 1]
b.append(i * j - 1)
if tmp < 0:
for j in b:
a0[j] = 0
if sum(a) > sum(a0):
a0 = a
print((sum(a0)))
| def main():
import sys
input = sys.stdin.readline
# Dinic's algorithm
from collections import deque
class Dinic:
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap):
forward = [to, cap, None]
forward[2] = backward = [fr, 0, forward]
self.G[fr].append(forward)
self.G[to].append(backward)
def add_multi_edge(self, v1, v2, cap1, cap2):
edge1 = [v2, cap1, None]
edge1[2] = edge2 = [v1, cap2, edge1]
self.G[v1].append(edge1)
self.G[v2].append(edge2)
def bfs(self, s, t):
self.level = level = [None] * self.N
deq = deque([s])
level[s] = 0
G = self.G
while deq:
v = deq.popleft()
lv = level[v] + 1
for w, cap, _ in G[v]:
if cap and level[w] is None:
level[w] = lv
deq.append(w)
return level[t] is not None
def dfs(self, v, t, f):
if v == t:
return f
level = self.level
for e in self.it[v]:
w, cap, rev = e
if cap and level[v] < level[w]:
d = self.dfs(w, t, min(f, cap))
if d:
e[1] -= d
rev[1] += d
return d
return 0
def flow(self, s, t):
flow = 0
INF = 10**9 + 7
G = self.G
while self.bfs(s, t):
(*self.it,) = list(map(iter, self.G))
f = INF
while f:
f = self.dfs(s, t, INF)
flow += f
return flow
inf = 1 << 40
N = int(eval(input()))
A = list(map(int, input().split()))
dinic = Dinic(N + 2)
ans = 0
for i, a in enumerate(A):
if a > 0:
ans += a
# dinic.add_edge(0, i+1, 0)
dinic.add_edge(i + 1, N + 1, a)
else:
dinic.add_edge(0, i + 1, -a)
# dinic.add_edge(i+1, N+1, 0)
for i in range(1, N + 1):
for k in range(1, N + 1):
if i * k > N:
break
dinic.add_edge(i, i * k, inf)
print((ans - dinic.flow(0, N + 1)))
if __name__ == "__main__":
main()
| false | 33.333333 | [
"-from copy import deepcopy",
"+def main():",
"+ import sys",
"-N = int(eval(input()))",
"-a0 = list(map(int, input().split()))",
"-for i in range(N, 0, -1):",
"- if a0[i - 1] < 0:",
"- tmp = 0",
"- b = []",
"- for j in range(1, 101):",
"- if i * j - 1 >= N:",
"+ input = sys.stdin.readline",
"+ # Dinic's algorithm",
"+ from collections import deque",
"+",
"+ class Dinic:",
"+ def __init__(self, N):",
"+ self.N = N",
"+ self.G = [[] for i in range(N)]",
"+",
"+ def add_edge(self, fr, to, cap):",
"+ forward = [to, cap, None]",
"+ forward[2] = backward = [fr, 0, forward]",
"+ self.G[fr].append(forward)",
"+ self.G[to].append(backward)",
"+",
"+ def add_multi_edge(self, v1, v2, cap1, cap2):",
"+ edge1 = [v2, cap1, None]",
"+ edge1[2] = edge2 = [v1, cap2, edge1]",
"+ self.G[v1].append(edge1)",
"+ self.G[v2].append(edge2)",
"+",
"+ def bfs(self, s, t):",
"+ self.level = level = [None] * self.N",
"+ deq = deque([s])",
"+ level[s] = 0",
"+ G = self.G",
"+ while deq:",
"+ v = deq.popleft()",
"+ lv = level[v] + 1",
"+ for w, cap, _ in G[v]:",
"+ if cap and level[w] is None:",
"+ level[w] = lv",
"+ deq.append(w)",
"+ return level[t] is not None",
"+",
"+ def dfs(self, v, t, f):",
"+ if v == t:",
"+ return f",
"+ level = self.level",
"+ for e in self.it[v]:",
"+ w, cap, rev = e",
"+ if cap and level[v] < level[w]:",
"+ d = self.dfs(w, t, min(f, cap))",
"+ if d:",
"+ e[1] -= d",
"+ rev[1] += d",
"+ return d",
"+ return 0",
"+",
"+ def flow(self, s, t):",
"+ flow = 0",
"+ INF = 10**9 + 7",
"+ G = self.G",
"+ while self.bfs(s, t):",
"+ (*self.it,) = list(map(iter, self.G))",
"+ f = INF",
"+ while f:",
"+ f = self.dfs(s, t, INF)",
"+ flow += f",
"+ return flow",
"+",
"+ inf = 1 << 40",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ dinic = Dinic(N + 2)",
"+ ans = 0",
"+ for i, a in enumerate(A):",
"+ if a > 0:",
"+ ans += a",
"+ # dinic.add_edge(0, i+1, 0)",
"+ dinic.add_edge(i + 1, N + 1, a)",
"+ else:",
"+ dinic.add_edge(0, i + 1, -a)",
"+ # dinic.add_edge(i+1, N+1, 0)",
"+ for i in range(1, N + 1):",
"+ for k in range(1, N + 1):",
"+ if i * k > N:",
"- tmp += a0[i * j - 1]",
"- b.append(i * j - 1)",
"- if tmp < 0:",
"- for j in b:",
"- a0[j] = 0",
"-for k1 in range(N, 0, -1):",
"- for k2 in range(k1 - 1, 0, -1):",
"- a = deepcopy(a0)",
"- for j in range(1, 101):",
"- if k1 * j - 1 >= N:",
"- break",
"- a[k1 * j - 1] = 0",
"- for j in range(1, 101):",
"- if k2 * j - 1 >= N:",
"- break",
"- a[k2 * j - 1] = 0",
"- for i in range(N, 0, -1):",
"- if a[i - 1] < 0:",
"- tmp = 0",
"- b = []",
"- for j in range(1, 101):",
"- if i * j - 1 >= N:",
"- break",
"- tmp += a[i * j - 1]",
"- b.append(i * j - 1)",
"- if tmp < 0:",
"- for j in b:",
"- a[j] = 0",
"- for i in range(N, 0, -1):",
"- if a0[i - 1] < 0:",
"- tmp = 0",
"- b = []",
"- for j in range(1, 101):",
"- if i * j - 1 >= N:",
"- break",
"- tmp += a0[i * j - 1]",
"- b.append(i * j - 1)",
"- if tmp < 0:",
"- for j in b:",
"- a0[j] = 0",
"- if sum(a) > sum(a0):",
"- a0 = a",
"-print((sum(a0)))",
"+ dinic.add_edge(i, i * k, inf)",
"+ print((ans - dinic.flow(0, N + 1)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.047018 | 0.04472 | 1.051402 | [
"s493602466",
"s594007559"
] |
u489959379 | p03805 | python | s434916769 | s754931211 | 34 | 31 | 9,316 | 9,348 | Accepted | Accepted | 8.82 | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, m = list(map(int, input().split()))
edge = [[f_inf] * n for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
edge[a - 1][b - 1] = 1
edge[b - 1][a - 1] = 1
dp = [[f_inf] * n for _ in range(1 << n)]
dp[0][0] = 0
cnt = [[0] * n for _ in range(1 << n)]
cnt[0][0] = 1
for S in range(1 << n):
for v in range(n):
for u in range(n):
if v == u or S & (1 << v) or edge[u][v] == f_inf:
continue
if dp[S | (1 << v)][v] > dp[S][u] + edge[u][v]:
dp[S | (1 << v)][v] = dp[S][u] + edge[u][v]
cnt[S | (1 << v)][v] = cnt[S][u]
elif dp[S | (1 << v)][v] == dp[S][u] + edge[u][v]:
cnt[S | (1 << v)][v] += cnt[S][u]
mi = min(dp[-2])
idx = []
for i in range(n):
if dp[-2][i] == mi:
idx.append(i)
res = 0
for j in idx:
res += cnt[-2][j]
print(res)
if __name__ == '__main__':
resolve()
| import sys
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
"""
順列を全部試す。計算量O(N!)
"""
n, m = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
res = 0
for pattern in permutations(list(range(n))):
if pattern[0] == 0:
for i in range(n - 1):
if pattern[i + 1] not in tree[pattern[i]]:
break
else:
res += 1
print(res)
def resolve2():
"""
bit DP。計算量O(2^N*N^2)
"""
n, m = list(map(int, input().split()))
edge = [[f_inf] * n for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
edge[a - 1][b - 1] = 1
edge[b - 1][a - 1] = 1
dp = [[f_inf] * n for _ in range(1 << n)]
dp[0][0] = 0
cnt = [[0] * n for _ in range(1 << n)]
cnt[0][0] = 1
for S in range(1 << n):
for v in range(n):
for u in range(n):
if v == u or S & (1 << v) or edge[u][v] == f_inf:
continue
if dp[S | (1 << v)][v] > dp[S][u] + edge[u][v]:
dp[S | (1 << v)][v] = dp[S][u] + edge[u][v]
cnt[S | (1 << v)][v] = cnt[S][u]
elif dp[S | (1 << v)][v] == dp[S][u] + edge[u][v]:
cnt[S | (1 << v)][v] += cnt[S][u]
mi = min(dp[-2])
idx = []
for i in range(n):
if dp[-2][i] == mi:
idx.append(i)
res = 0
for j in idx:
res += cnt[-2][j]
print(res)
if __name__ == '__main__':
resolve2()
| 45 | 71 | 1,211 | 1,834 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n, m = list(map(int, input().split()))
edge = [[f_inf] * n for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
edge[a - 1][b - 1] = 1
edge[b - 1][a - 1] = 1
dp = [[f_inf] * n for _ in range(1 << n)]
dp[0][0] = 0
cnt = [[0] * n for _ in range(1 << n)]
cnt[0][0] = 1
for S in range(1 << n):
for v in range(n):
for u in range(n):
if v == u or S & (1 << v) or edge[u][v] == f_inf:
continue
if dp[S | (1 << v)][v] > dp[S][u] + edge[u][v]:
dp[S | (1 << v)][v] = dp[S][u] + edge[u][v]
cnt[S | (1 << v)][v] = cnt[S][u]
elif dp[S | (1 << v)][v] == dp[S][u] + edge[u][v]:
cnt[S | (1 << v)][v] += cnt[S][u]
mi = min(dp[-2])
idx = []
for i in range(n):
if dp[-2][i] == mi:
idx.append(i)
res = 0
for j in idx:
res += cnt[-2][j]
print(res)
if __name__ == "__main__":
resolve()
| import sys
from itertools import permutations
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
"""
順列を全部試す。計算量O(N!)
"""
n, m = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
res = 0
for pattern in permutations(list(range(n))):
if pattern[0] == 0:
for i in range(n - 1):
if pattern[i + 1] not in tree[pattern[i]]:
break
else:
res += 1
print(res)
def resolve2():
"""
bit DP。計算量O(2^N*N^2)
"""
n, m = list(map(int, input().split()))
edge = [[f_inf] * n for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
edge[a - 1][b - 1] = 1
edge[b - 1][a - 1] = 1
dp = [[f_inf] * n for _ in range(1 << n)]
dp[0][0] = 0
cnt = [[0] * n for _ in range(1 << n)]
cnt[0][0] = 1
for S in range(1 << n):
for v in range(n):
for u in range(n):
if v == u or S & (1 << v) or edge[u][v] == f_inf:
continue
if dp[S | (1 << v)][v] > dp[S][u] + edge[u][v]:
dp[S | (1 << v)][v] = dp[S][u] + edge[u][v]
cnt[S | (1 << v)][v] = cnt[S][u]
elif dp[S | (1 << v)][v] == dp[S][u] + edge[u][v]:
cnt[S | (1 << v)][v] += cnt[S][u]
mi = min(dp[-2])
idx = []
for i in range(n):
if dp[-2][i] == mi:
idx.append(i)
res = 0
for j in idx:
res += cnt[-2][j]
print(res)
if __name__ == "__main__":
resolve2()
| false | 36.619718 | [
"+from itertools import permutations",
"+ \"\"\"",
"+ 順列を全部試す。計算量O(N!)",
"+ \"\"\"",
"+ n, m = list(map(int, input().split()))",
"+ tree = [[] for _ in range(n)]",
"+ for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ tree[a - 1].append(b - 1)",
"+ tree[b - 1].append(a - 1)",
"+ res = 0",
"+ for pattern in permutations(list(range(n))):",
"+ if pattern[0] == 0:",
"+ for i in range(n - 1):",
"+ if pattern[i + 1] not in tree[pattern[i]]:",
"+ break",
"+ else:",
"+ res += 1",
"+ print(res)",
"+",
"+",
"+def resolve2():",
"+ \"\"\"",
"+ bit DP。計算量O(2^N*N^2)",
"+ \"\"\"",
"- resolve()",
"+ resolve2()"
] | false | 0.040797 | 0.044556 | 0.915644 | [
"s434916769",
"s754931211"
] |
u747602774 | p03045 | python | s156963971 | s293514073 | 507 | 261 | 8,624 | 82,772 | Accepted | Accepted | 48.52 | N,M = list(map(int,input().split()))
# parent(親)
par = [i for i in range(N+1)]
# rank(深さ)
rank = [0 for i in range(N+1)]
# 同グループの頂点数
size = [1 for i in range(N+1)]
# 木の根を求める
def root(x):
if par[x] == x: # 根の時
return x
else:
par[x] = root(par[x]) # 経路圧縮
return par[x]
# xとyの属する集合を併合(ランク有)
def unite(x,y):
x = root(x)
y = root(y)
if x == y:
return
if rank[x] < rank[y]:
par[x] = y # xの親をyに
size[y] += size[x] # yの頂点数+=xの頂点数
else:
par[y] = x # yの親をxに
size[x] += size[y] # xの頂点数+=yの頂点数
if rank[x] == rank[y]:
rank[x] += 1
for _ in range(M):
x,y,z = list(map(int,input().split()))
unite(x,y)
ans = 0
for i in range(1,N+1):
if par[i] == i:
ans += 1
print(ans) | import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
N,Q = list(map(int,readline().split()))
# 1-indexed union-find
# parent(親)
par = [i for i in range(N+1)]
# rank(深さ)
rank = [0]*(N+1)
# 同グループの頂点数
size = [1]*(N+1)
# 木の根を求める
def root(x):
if par[x] == x: # 根の時
return x
else:
par[x] = root(par[x]) # 経路圧縮
return par[x]
# xとyの属する集合を併合(ランク有)
def unite(x,y):
x = root(x)
y = root(y)
if x == y:
return
if rank[x] < rank[y]:
par[x] = y # xの親をyに
size[y] += size[x] # yの頂点数+=xの頂点数
else:
par[y] = x # yの親をxに
size[x] += size[y] # xの頂点数+=yの頂点数
if rank[x] == rank[y]:
rank[x] += 1
for i in range(Q):
x,y,z = list(map(int,readline().split()))
unite(x,y)
ans = [0]*(N+1)
for i in par:
ans[root(i)] += 1
aaa = 0
for i in range(N+1):
if ans[i] > 0:
aaa += 1
print((aaa-1))
| 40 | 55 | 866 | 1,066 | N, M = list(map(int, input().split()))
# parent(親)
par = [i for i in range(N + 1)]
# rank(深さ)
rank = [0 for i in range(N + 1)]
# 同グループの頂点数
size = [1 for i in range(N + 1)]
# 木の根を求める
def root(x):
if par[x] == x: # 根の時
return x
else:
par[x] = root(par[x]) # 経路圧縮
return par[x]
# xとyの属する集合を併合(ランク有)
def unite(x, y):
x = root(x)
y = root(y)
if x == y:
return
if rank[x] < rank[y]:
par[x] = y # xの親をyに
size[y] += size[x] # yの頂点数+=xの頂点数
else:
par[y] = x # yの親をxに
size[x] += size[y] # xの頂点数+=yの頂点数
if rank[x] == rank[y]:
rank[x] += 1
for _ in range(M):
x, y, z = list(map(int, input().split()))
unite(x, y)
ans = 0
for i in range(1, N + 1):
if par[i] == i:
ans += 1
print(ans)
| import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
# mod = 998244353
INF = 10**18
eps = 10**-7
N, Q = list(map(int, readline().split()))
# 1-indexed union-find
# parent(親)
par = [i for i in range(N + 1)]
# rank(深さ)
rank = [0] * (N + 1)
# 同グループの頂点数
size = [1] * (N + 1)
# 木の根を求める
def root(x):
if par[x] == x: # 根の時
return x
else:
par[x] = root(par[x]) # 経路圧縮
return par[x]
# xとyの属する集合を併合(ランク有)
def unite(x, y):
x = root(x)
y = root(y)
if x == y:
return
if rank[x] < rank[y]:
par[x] = y # xの親をyに
size[y] += size[x] # yの頂点数+=xの頂点数
else:
par[y] = x # yの親をxに
size[x] += size[y] # xの頂点数+=yの頂点数
if rank[x] == rank[y]:
rank[x] += 1
for i in range(Q):
x, y, z = list(map(int, readline().split()))
unite(x, y)
ans = [0] * (N + 1)
for i in par:
ans[root(i)] += 1
aaa = 0
for i in range(N + 1):
if ans[i] > 0:
aaa += 1
print((aaa - 1))
| false | 27.272727 | [
"-N, M = list(map(int, input().split()))",
"+import sys",
"+",
"+readline = sys.stdin.readline",
"+sys.setrecursionlimit(10**8)",
"+mod = 10**9 + 7",
"+# mod = 998244353",
"+INF = 10**18",
"+eps = 10**-7",
"+N, Q = list(map(int, readline().split()))",
"+# 1-indexed union-find",
"-rank = [0 for i in range(N + 1)]",
"+rank = [0] * (N + 1)",
"-size = [1 for i in range(N + 1)]",
"+size = [1] * (N + 1)",
"-for _ in range(M):",
"- x, y, z = list(map(int, input().split()))",
"+for i in range(Q):",
"+ x, y, z = list(map(int, readline().split()))",
"-ans = 0",
"-for i in range(1, N + 1):",
"- if par[i] == i:",
"- ans += 1",
"-print(ans)",
"+ans = [0] * (N + 1)",
"+for i in par:",
"+ ans[root(i)] += 1",
"+aaa = 0",
"+for i in range(N + 1):",
"+ if ans[i] > 0:",
"+ aaa += 1",
"+print((aaa - 1))"
] | false | 0.104197 | 0.058844 | 1.770736 | [
"s156963971",
"s293514073"
] |
u670180528 | p03798 | python | s392423347 | s407954432 | 211 | 112 | 7,680 | 6,920 | Accepted | Accepted | 46.92 | n,s=open(0);n=int(n)
for a,b in ([0,0],[0,1],[1,0],[1,1]):
r=[a,b]
for i in range(n):a,b=b,s[-~i%n]=="xo"[a==b];r+=[b]
if r[:2]==r[-2:]:print(*("WS"[i]for i in r[:-2]),sep="");exit()
print(-1)
| def solve():
n=int(input())
s=[c=="o"for c in input()]
for a,b in ([0,0],[0,1],[1,0],[1,1]):
r=[a,b]
for i in range(n):a,b=b,s[-~i%n]==(a==b);r+=[b]
if r[:2]==r[-2:]:print("".join("WS"[i]for i in r[:-2]),sep="");exit()
print(-1)
if __name__=="__main__":
solve()
| 6 | 11 | 200 | 284 | n, s = open(0)
n = int(n)
for a, b in ([0, 0], [0, 1], [1, 0], [1, 1]):
r = [a, b]
for i in range(n):
a, b = b, s[-~i % n] == "xo"[a == b]
r += [b]
if r[:2] == r[-2:]:
print(*("WS"[i] for i in r[:-2]), sep="")
exit()
print(-1)
| def solve():
n = int(input())
s = [c == "o" for c in input()]
for a, b in ([0, 0], [0, 1], [1, 0], [1, 1]):
r = [a, b]
for i in range(n):
a, b = b, s[-~i % n] == (a == b)
r += [b]
if r[:2] == r[-2:]:
print("".join("WS"[i] for i in r[:-2]), sep="")
exit()
print(-1)
if __name__ == "__main__":
solve()
| false | 45.454545 | [
"-n, s = open(0)",
"-n = int(n)",
"-for a, b in ([0, 0], [0, 1], [1, 0], [1, 1]):",
"- r = [a, b]",
"- for i in range(n):",
"- a, b = b, s[-~i % n] == \"xo\"[a == b]",
"- r += [b]",
"- if r[:2] == r[-2:]:",
"- print(*(\"WS\"[i] for i in r[:-2]), sep=\"\")",
"- exit()",
"-print(-1)",
"+def solve():",
"+ n = int(input())",
"+ s = [c == \"o\" for c in input()]",
"+ for a, b in ([0, 0], [0, 1], [1, 0], [1, 1]):",
"+ r = [a, b]",
"+ for i in range(n):",
"+ a, b = b, s[-~i % n] == (a == b)",
"+ r += [b]",
"+ if r[:2] == r[-2:]:",
"+ print(\"\".join(\"WS\"[i] for i in r[:-2]), sep=\"\")",
"+ exit()",
"+ print(-1)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.006979 | 0.055845 | 0.124978 | [
"s392423347",
"s407954432"
] |
u493520238 | p02756 | python | s922186041 | s193401325 | 670 | 341 | 4,468 | 101,516 | Accepted | Accepted | 49.1 | s = str(eval(input()))
q = int(eval(input()))
front_s = ''
back_s = ''
rev_flg = False
for i in range(q):
query = list(map(str, input().split()))
if query[0] == '1':
rev_flg = not rev_flg
else:
if not rev_flg:
if query[1] == '1':
front_s += query[2]
else:
back_s += query[2]
else:
if query[1] == '1':
back_s += query[2]
else:
front_s += query[2]
res = front_s[::-1] + s + back_s
if rev_flg: res = res[::-1]
print(res) | from collections import deque
s = list(eval(input()))
Q = int(eval(input()))
r = False
q = deque(s)
for _ in range(Q):
query = list(map(str, input().split()))
if query[0] == '1':
r = not r
else:
f,c = query[1],query[2]
if f == '1':
if not r:
q.appendleft(c)
else:
q.append(c)
else:
if not r:
q.append(c)
else:
q.appendleft(c)
ans = list(q)
if r: ans = ans[::-1]
print((''.join(ans)))
| 26 | 27 | 587 | 555 | s = str(eval(input()))
q = int(eval(input()))
front_s = ""
back_s = ""
rev_flg = False
for i in range(q):
query = list(map(str, input().split()))
if query[0] == "1":
rev_flg = not rev_flg
else:
if not rev_flg:
if query[1] == "1":
front_s += query[2]
else:
back_s += query[2]
else:
if query[1] == "1":
back_s += query[2]
else:
front_s += query[2]
res = front_s[::-1] + s + back_s
if rev_flg:
res = res[::-1]
print(res)
| from collections import deque
s = list(eval(input()))
Q = int(eval(input()))
r = False
q = deque(s)
for _ in range(Q):
query = list(map(str, input().split()))
if query[0] == "1":
r = not r
else:
f, c = query[1], query[2]
if f == "1":
if not r:
q.appendleft(c)
else:
q.append(c)
else:
if not r:
q.append(c)
else:
q.appendleft(c)
ans = list(q)
if r:
ans = ans[::-1]
print(("".join(ans)))
| false | 3.703704 | [
"-s = str(eval(input()))",
"-q = int(eval(input()))",
"-front_s = \"\"",
"-back_s = \"\"",
"-rev_flg = False",
"-for i in range(q):",
"+from collections import deque",
"+",
"+s = list(eval(input()))",
"+Q = int(eval(input()))",
"+r = False",
"+q = deque(s)",
"+for _ in range(Q):",
"- rev_flg = not rev_flg",
"+ r = not r",
"- if not rev_flg:",
"- if query[1] == \"1\":",
"- front_s += query[2]",
"+ f, c = query[1], query[2]",
"+ if f == \"1\":",
"+ if not r:",
"+ q.appendleft(c)",
"- back_s += query[2]",
"+ q.append(c)",
"- if query[1] == \"1\":",
"- back_s += query[2]",
"+ if not r:",
"+ q.append(c)",
"- front_s += query[2]",
"-res = front_s[::-1] + s + back_s",
"-if rev_flg:",
"- res = res[::-1]",
"-print(res)",
"+ q.appendleft(c)",
"+ans = list(q)",
"+if r:",
"+ ans = ans[::-1]",
"+print((\"\".join(ans)))"
] | false | 0.041235 | 0.035828 | 1.150901 | [
"s922186041",
"s193401325"
] |
u791170614 | p02388 | python | s726874222 | s075227314 | 30 | 20 | 7,528 | 7,580 | Accepted | Accepted | 33.33 | x = int(eval(input()))
print((x ** 3)) | print((int(eval(input()))**3)) | 2 | 1 | 31 | 22 | x = int(eval(input()))
print((x**3))
| print((int(eval(input())) ** 3))
| false | 50 | [
"-x = int(eval(input()))",
"-print((x**3))",
"+print((int(eval(input())) ** 3))"
] | false | 0.041507 | 0.037883 | 1.095648 | [
"s726874222",
"s075227314"
] |
u923668099 | p02317 | python | s164643786 | s031248293 | 350 | 290 | 12,424 | 12,472 | Accepted | Accepted | 17.14 | import sys
import bisect
inf = float('inf')
def solve():
n = int(input())
A = [int(input()) for i in range(n)]
dp = [inf] * n
max_ = 1
for a in A:
j = bisect.bisect_left(dp, a, lo=0, hi=max_)
max_ = max(max_, j + 1)
dp[j] = a
# print(dp)
ans = max_
print(ans)
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
if __name__ == '__main__':
solve()
| import sys
import bisect
inf = float('inf')
def solve():
n = int(input())
A = [int(input()) for i in range(n)]
dp = [inf] * n
# max_ = 1
for a in A:
j = bisect.bisect_left(dp, a)
# max_ = max(max_, j + 1)
dp[j] = a
# print(dp)
ans = 1
for i, v in enumerate(dp):
if v == inf:
ans = i
break
else:
ans = n
print(ans)
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
if __name__ == '__main__':
solve()
| 29 | 37 | 562 | 682 | import sys
import bisect
inf = float("inf")
def solve():
n = int(input())
A = [int(input()) for i in range(n)]
dp = [inf] * n
max_ = 1
for a in A:
j = bisect.bisect_left(dp, a, lo=0, hi=max_)
max_ = max(max_, j + 1)
dp[j] = a
# print(dp)
ans = max_
print(ans)
def debug(x, table):
for name, val in table.items():
if x is val:
print("DEBUG:{} -> {}".format(name, val), file=sys.stderr)
return None
if __name__ == "__main__":
solve()
| import sys
import bisect
inf = float("inf")
def solve():
n = int(input())
A = [int(input()) for i in range(n)]
dp = [inf] * n
# max_ = 1
for a in A:
j = bisect.bisect_left(dp, a)
# max_ = max(max_, j + 1)
dp[j] = a
# print(dp)
ans = 1
for i, v in enumerate(dp):
if v == inf:
ans = i
break
else:
ans = n
print(ans)
def debug(x, table):
for name, val in table.items():
if x is val:
print("DEBUG:{} -> {}".format(name, val), file=sys.stderr)
return None
if __name__ == "__main__":
solve()
| false | 21.621622 | [
"- max_ = 1",
"+ # max_ = 1",
"- j = bisect.bisect_left(dp, a, lo=0, hi=max_)",
"- max_ = max(max_, j + 1)",
"+ j = bisect.bisect_left(dp, a)",
"+ # max_ = max(max_, j + 1)",
"- ans = max_",
"+ ans = 1",
"+ for i, v in enumerate(dp):",
"+ if v == inf:",
"+ ans = i",
"+ break",
"+ else:",
"+ ans = n"
] | false | 0.086046 | 0.062129 | 1.384959 | [
"s164643786",
"s031248293"
] |
u621935300 | p03329 | python | s870277313 | s867817918 | 155 | 123 | 34,156 | 33,256 | Accepted | Accepted | 20.65 | N=eval(input())
dp=[ float("inf") for i in range(N+1) ]
dp[0]=0
i=1
for i in range(1,8):
for n in range(N):
if n+ 9**i <=N: dp[ n+ 9**i ]=min( dp[n]+1, dp[ n+9**i ] )
if n+ 6**i <=N: dp[ n+ 6**i ]=min( dp[n]+1, dp[ n+6**i ] )
if n+ 1 <=N: dp[ n+ 1 ]=min( dp[n]+1, dp[ n+1 ] )
print(dp[N]) | N=eval(input()) #N=a+b
ans=float("inf")
for a in range(N+1):
b=N-a
cnt=0
for i in range(8,-1,-1):
t=6**i
if a>=t:
cnt+=(a/t)
a=a%t
for i in range(8,-1,-1):
t=9**i
if b>=t:
cnt+=(b/t)
b=b%t
ans=min(ans,cnt)
print(ans)
| 15 | 21 | 312 | 260 | N = eval(input())
dp = [float("inf") for i in range(N + 1)]
dp[0] = 0
i = 1
for i in range(1, 8):
for n in range(N):
if n + 9**i <= N:
dp[n + 9**i] = min(dp[n] + 1, dp[n + 9**i])
if n + 6**i <= N:
dp[n + 6**i] = min(dp[n] + 1, dp[n + 6**i])
if n + 1 <= N:
dp[n + 1] = min(dp[n] + 1, dp[n + 1])
print(dp[N])
| N = eval(input()) # N=a+b
ans = float("inf")
for a in range(N + 1):
b = N - a
cnt = 0
for i in range(8, -1, -1):
t = 6**i
if a >= t:
cnt += a / t
a = a % t
for i in range(8, -1, -1):
t = 9**i
if b >= t:
cnt += b / t
b = b % t
ans = min(ans, cnt)
print(ans)
| false | 28.571429 | [
"-N = eval(input())",
"-dp = [float(\"inf\") for i in range(N + 1)]",
"-dp[0] = 0",
"-i = 1",
"-for i in range(1, 8):",
"- for n in range(N):",
"- if n + 9**i <= N:",
"- dp[n + 9**i] = min(dp[n] + 1, dp[n + 9**i])",
"- if n + 6**i <= N:",
"- dp[n + 6**i] = min(dp[n] + 1, dp[n + 6**i])",
"- if n + 1 <= N:",
"- dp[n + 1] = min(dp[n] + 1, dp[n + 1])",
"-print(dp[N])",
"+N = eval(input()) # N=a+b",
"+ans = float(\"inf\")",
"+for a in range(N + 1):",
"+ b = N - a",
"+ cnt = 0",
"+ for i in range(8, -1, -1):",
"+ t = 6**i",
"+ if a >= t:",
"+ cnt += a / t",
"+ a = a % t",
"+ for i in range(8, -1, -1):",
"+ t = 9**i",
"+ if b >= t:",
"+ cnt += b / t",
"+ b = b % t",
"+ ans = min(ans, cnt)",
"+print(ans)"
] | false | 0.314754 | 0.485353 | 0.648505 | [
"s870277313",
"s867817918"
] |
u910358825 | p02577 | python | s519817108 | s764118377 | 204 | 70 | 9,192 | 10,488 | Accepted | Accepted | 65.69 | n=int(eval(input()))
if n%9==0:
print("Yes")
else:
print("No") | n=eval(input())
li=list(map(int, n))
sum=0
for i in range(len(li)):
sum+=li[i]
if sum%9==0:
print("Yes")
else:
print("No") | 5 | 9 | 68 | 136 | n = int(eval(input()))
if n % 9 == 0:
print("Yes")
else:
print("No")
| n = eval(input())
li = list(map(int, n))
sum = 0
for i in range(len(li)):
sum += li[i]
if sum % 9 == 0:
print("Yes")
else:
print("No")
| false | 44.444444 | [
"-n = int(eval(input()))",
"-if n % 9 == 0:",
"+n = eval(input())",
"+li = list(map(int, n))",
"+sum = 0",
"+for i in range(len(li)):",
"+ sum += li[i]",
"+if sum % 9 == 0:"
] | false | 0.038696 | 0.038248 | 1.011721 | [
"s519817108",
"s764118377"
] |
u883048396 | p03329 | python | s727318294 | s983310563 | 585 | 434 | 3,064 | 3,064 | Accepted | Accepted | 25.81 | #公式解法見て書いた
iN = int(eval(input()))
a6 = [0]*7
for i in range(7):
a6[i] = 6 ** i
a6.reverse()
a9 = [0]*6
for i in range(6):
a9[i] = 9 ** i
a9.reverse()
iAns = iN
for i in range(iN+1):
iD = iN - i
iC = 0
for j in range(7):
if i:
iG = a6[j]
if i >= iG:
iC += (i // iG)
i %=iG
for j in range(6):
if iD :
iG = a9[j]
if iD >= iG:
iC += (iD // iG)
iD %= iG
if iAns > iC:
iAns = iC
print(iAns)
| #公式解法見て書いた
iN = int(eval(input()))
a6 = [0]*7
for i in range(7):
a6[i] = 6 ** i
a6.reverse()
a9 = [0]*6
for i in range(6):
a9[i] = 9 ** i
a9.reverse()
iAns = iN
for i in range(iN+1):
iD = iN - i
iC = 0
for j in range(7):
if i:
iG = a6[j]
if i >= iG:
iC += (i // iG)
i %=iG
if iAns <= iC:
continue
for j in range(6):
if iD :
iG = a9[j]
if iD >= iG:
iC += (iD // iG)
iD %= iG
if iAns > iC:
iAns = iC
print(iAns)
| 31 | 33 | 576 | 614 | # 公式解法見て書いた
iN = int(eval(input()))
a6 = [0] * 7
for i in range(7):
a6[i] = 6**i
a6.reverse()
a9 = [0] * 6
for i in range(6):
a9[i] = 9**i
a9.reverse()
iAns = iN
for i in range(iN + 1):
iD = iN - i
iC = 0
for j in range(7):
if i:
iG = a6[j]
if i >= iG:
iC += i // iG
i %= iG
for j in range(6):
if iD:
iG = a9[j]
if iD >= iG:
iC += iD // iG
iD %= iG
if iAns > iC:
iAns = iC
print(iAns)
| # 公式解法見て書いた
iN = int(eval(input()))
a6 = [0] * 7
for i in range(7):
a6[i] = 6**i
a6.reverse()
a9 = [0] * 6
for i in range(6):
a9[i] = 9**i
a9.reverse()
iAns = iN
for i in range(iN + 1):
iD = iN - i
iC = 0
for j in range(7):
if i:
iG = a6[j]
if i >= iG:
iC += i // iG
i %= iG
if iAns <= iC:
continue
for j in range(6):
if iD:
iG = a9[j]
if iD >= iG:
iC += iD // iG
iD %= iG
if iAns > iC:
iAns = iC
print(iAns)
| false | 6.060606 | [
"+ if iAns <= iC:",
"+ continue"
] | false | 0.15527 | 0.121329 | 1.279743 | [
"s727318294",
"s983310563"
] |
u057109575 | p02923 | python | s138609546 | s703390626 | 228 | 90 | 71,228 | 84,804 | Accepted | Accepted | 60.53 | N, *H = list(map(int, open(0).read().split()))
diff = [H[i + 1] - H[i] <= 0 for i in range(N - 1)]
ans = 0
tmp = 0
for v in diff:
if v:
tmp += 1
else:
ans = max(ans, tmp)
tmp = 0
print((max(ans, tmp)))
|
N = int(eval(input()))
X = list(map(int, input().split()))
ans = 0
cnt = 0
cur = X[0]
for i in range(1, N):
if cur < X[i]:
ans = max(ans, cnt)
cnt = 0
else:
cnt += 1
cur = X[i]
print((max(ans, cnt)))
| 14 | 16 | 250 | 246 | N, *H = list(map(int, open(0).read().split()))
diff = [H[i + 1] - H[i] <= 0 for i in range(N - 1)]
ans = 0
tmp = 0
for v in diff:
if v:
tmp += 1
else:
ans = max(ans, tmp)
tmp = 0
print((max(ans, tmp)))
| N = int(eval(input()))
X = list(map(int, input().split()))
ans = 0
cnt = 0
cur = X[0]
for i in range(1, N):
if cur < X[i]:
ans = max(ans, cnt)
cnt = 0
else:
cnt += 1
cur = X[i]
print((max(ans, cnt)))
| false | 12.5 | [
"-N, *H = list(map(int, open(0).read().split()))",
"-diff = [H[i + 1] - H[i] <= 0 for i in range(N - 1)]",
"+N = int(eval(input()))",
"+X = list(map(int, input().split()))",
"-tmp = 0",
"-for v in diff:",
"- if v:",
"- tmp += 1",
"+cnt = 0",
"+cur = X[0]",
"+for i in range(1, N):",
"+ if cur < X[i]:",
"+ ans = max(ans, cnt)",
"+ cnt = 0",
"- ans = max(ans, tmp)",
"- tmp = 0",
"-print((max(ans, tmp)))",
"+ cnt += 1",
"+ cur = X[i]",
"+print((max(ans, cnt)))"
] | false | 0.1079 | 0.07603 | 1.419184 | [
"s138609546",
"s703390626"
] |
u423925725 | p03339 | python | s900489839 | s894748546 | 98 | 69 | 3,672 | 3,672 | Accepted | Accepted | 29.59 | def main():
N = int(eval(input()))
S = eval(input())
ec = S.count('E')
tec = ec
for k in S:
if k == 'E':
tec -= 1
else:
tec += 1
ec = min(ec, tec)
print(ec)
if __name__ == '__main__':
main() | def main():
N = int(eval(input()))
S = eval(input())
ec = S.count('E')
wc = 0
min = ec
for k in S:
if k == 'E':
ec -= 1
else:
wc += 1
if min > ec + wc: min = ec + wc
print(min)
if __name__ == '__main__':
main() | 15 | 16 | 269 | 294 | def main():
N = int(eval(input()))
S = eval(input())
ec = S.count("E")
tec = ec
for k in S:
if k == "E":
tec -= 1
else:
tec += 1
ec = min(ec, tec)
print(ec)
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
S = eval(input())
ec = S.count("E")
wc = 0
min = ec
for k in S:
if k == "E":
ec -= 1
else:
wc += 1
if min > ec + wc:
min = ec + wc
print(min)
if __name__ == "__main__":
main()
| false | 6.25 | [
"- tec = ec",
"+ wc = 0",
"+ min = ec",
"- tec -= 1",
"+ ec -= 1",
"- tec += 1",
"- ec = min(ec, tec)",
"- print(ec)",
"+ wc += 1",
"+ if min > ec + wc:",
"+ min = ec + wc",
"+ print(min)"
] | false | 0.043776 | 0.078803 | 0.555516 | [
"s900489839",
"s894748546"
] |
u155908073 | p03623 | python | s635089791 | s303676011 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | Sunuke, A ,B = list(map(int,input().split()))
if abs(Sunuke-A) < abs(Sunuke-B):
print("A")
else:
print("B") | Sunuke, A ,B = list(map(int,input().split()))
print(("A"if abs(Sunuke-A) < abs(Sunuke-B) else "B")) | 5 | 2 | 113 | 92 | Sunuke, A, B = list(map(int, input().split()))
if abs(Sunuke - A) < abs(Sunuke - B):
print("A")
else:
print("B")
| Sunuke, A, B = list(map(int, input().split()))
print(("A" if abs(Sunuke - A) < abs(Sunuke - B) else "B"))
| false | 60 | [
"-if abs(Sunuke - A) < abs(Sunuke - B):",
"- print(\"A\")",
"-else:",
"- print(\"B\")",
"+print((\"A\" if abs(Sunuke - A) < abs(Sunuke - B) else \"B\"))"
] | false | 0.039367 | 0.037836 | 1.040459 | [
"s635089791",
"s303676011"
] |
u911537358 | p03175 | python | s170138467 | s771751860 | 899 | 481 | 133,340 | 88,156 | Accepted | Accepted | 46.5 | # @author
import sys
class PIndependentSet:
def solve(self):
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 5)
MOD = 10 ** 9 + 7
def dfs(s):
done[s] = 1
dp[s][0] = 1
dp[s][1] = 1
for x in adj[s]:
if done[x]:
continue
dfs(x)
dp[s][0] = (dp[s][0] * dp[x][1]) % MOD
dp[s][1] = (dp[s][1] * (dp[x][0] + dp[x][1])) % MOD
n = int(eval(input()))
adj = defaultdict(list)
for i in range(n - 1):
x, y = [int(_) for _ in input().split()]
x -= 1
y -= 1
adj[x].append(y)
adj[y].append(x)
dp = [[0, 0] for _ in range(n)]
done = [0] * n
dfs(0)
print(((dp[0][0] + dp[0][1]) % MOD))
solver = PIndependentSet()
input = sys.stdin.readline
solver.solve()
| # @author
import sys
class PIndependentSet:
def solve(self):
from collections import defaultdict
MOD = 10 ** 9 + 7
def dfs(s):
st = [s]
par = [-1] * n
done = [0] * n
o = []
while st:
u = st.pop()
if done[u]: continue
o.append(u)
done[u] = 1
for x in adj[u]:
par[x] = u
st.append(x)
done = [0] * n
o.reverse()
for u in o:
dp[u][0] = 1
dp[u][1] = 1
done[u] = 1
for x in adj[u]:
if not done[x]:
continue
dp[u][0] = (dp[u][0] * dp[x][1]) % MOD
dp[u][1] = (dp[u][1] * (dp[x][0] + dp[x][1])) % MOD
n = int(eval(input()))
adj = defaultdict(list)
for i in range(n - 1):
x, y = [int(_) for _ in input().split()]
x -= 1
y -= 1
adj[x].append(y)
adj[y].append(x)
dp = [[0, 0] for _ in range(n)]
dfs(0)
print(((dp[0][0] + dp[0][1]) % MOD))
solver = PIndependentSet()
input = sys.stdin.readline
solver.solve()
| 43 | 53 | 1,003 | 1,350 | # @author
import sys
class PIndependentSet:
def solve(self):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**5 + 5)
MOD = 10**9 + 7
def dfs(s):
done[s] = 1
dp[s][0] = 1
dp[s][1] = 1
for x in adj[s]:
if done[x]:
continue
dfs(x)
dp[s][0] = (dp[s][0] * dp[x][1]) % MOD
dp[s][1] = (dp[s][1] * (dp[x][0] + dp[x][1])) % MOD
n = int(eval(input()))
adj = defaultdict(list)
for i in range(n - 1):
x, y = [int(_) for _ in input().split()]
x -= 1
y -= 1
adj[x].append(y)
adj[y].append(x)
dp = [[0, 0] for _ in range(n)]
done = [0] * n
dfs(0)
print(((dp[0][0] + dp[0][1]) % MOD))
solver = PIndependentSet()
input = sys.stdin.readline
solver.solve()
| # @author
import sys
class PIndependentSet:
def solve(self):
from collections import defaultdict
MOD = 10**9 + 7
def dfs(s):
st = [s]
par = [-1] * n
done = [0] * n
o = []
while st:
u = st.pop()
if done[u]:
continue
o.append(u)
done[u] = 1
for x in adj[u]:
par[x] = u
st.append(x)
done = [0] * n
o.reverse()
for u in o:
dp[u][0] = 1
dp[u][1] = 1
done[u] = 1
for x in adj[u]:
if not done[x]:
continue
dp[u][0] = (dp[u][0] * dp[x][1]) % MOD
dp[u][1] = (dp[u][1] * (dp[x][0] + dp[x][1])) % MOD
n = int(eval(input()))
adj = defaultdict(list)
for i in range(n - 1):
x, y = [int(_) for _ in input().split()]
x -= 1
y -= 1
adj[x].append(y)
adj[y].append(x)
dp = [[0, 0] for _ in range(n)]
dfs(0)
print(((dp[0][0] + dp[0][1]) % MOD))
solver = PIndependentSet()
input = sys.stdin.readline
solver.solve()
| false | 18.867925 | [
"- import sys",
"- sys.setrecursionlimit(10**5 + 5)",
"- done[s] = 1",
"- dp[s][0] = 1",
"- dp[s][1] = 1",
"- for x in adj[s]:",
"- if done[x]:",
"+ st = [s]",
"+ par = [-1] * n",
"+ done = [0] * n",
"+ o = []",
"+ while st:",
"+ u = st.pop()",
"+ if done[u]:",
"- dfs(x)",
"- dp[s][0] = (dp[s][0] * dp[x][1]) % MOD",
"- dp[s][1] = (dp[s][1] * (dp[x][0] + dp[x][1])) % MOD",
"+ o.append(u)",
"+ done[u] = 1",
"+ for x in adj[u]:",
"+ par[x] = u",
"+ st.append(x)",
"+ done = [0] * n",
"+ o.reverse()",
"+ for u in o:",
"+ dp[u][0] = 1",
"+ dp[u][1] = 1",
"+ done[u] = 1",
"+ for x in adj[u]:",
"+ if not done[x]:",
"+ continue",
"+ dp[u][0] = (dp[u][0] * dp[x][1]) % MOD",
"+ dp[u][1] = (dp[u][1] * (dp[x][0] + dp[x][1])) % MOD",
"- done = [0] * n"
] | false | 0.035286 | 0.035052 | 1.006677 | [
"s170138467",
"s771751860"
] |
u197955752 | p03073 | python | s935299991 | s322448560 | 240 | 130 | 3,444 | 3,316 | Accepted | Accepted | 45.83 | S = eval(input())
N = len(S) # タイルの数
a = sum((1 << i) for i in range(0, N, 2)) # 0b ...0101
b = sum((1 << i) for i in range(1, N, 2)) # 0b ...1010
a_flip = bin(a ^ int(S, base = 2))
b_flip = bin(b ^ int(S, base = 2))
print((min(a_flip[2:].count('1'), b_flip[2:].count('1')))) | S = eval(input())
N = len(S) # タイルの数
a = sum((1 << i) for i in range(0, N, 2)) # 0b ...0101
a_flip = bin(a ^ int(S, base = 2))[2:].count('1')
print((min(a_flip, N - a_flip)))
| 10 | 7 | 279 | 175 | S = eval(input())
N = len(S) # タイルの数
a = sum((1 << i) for i in range(0, N, 2)) # 0b ...0101
b = sum((1 << i) for i in range(1, N, 2)) # 0b ...1010
a_flip = bin(a ^ int(S, base=2))
b_flip = bin(b ^ int(S, base=2))
print((min(a_flip[2:].count("1"), b_flip[2:].count("1"))))
| S = eval(input())
N = len(S) # タイルの数
a = sum((1 << i) for i in range(0, N, 2)) # 0b ...0101
a_flip = bin(a ^ int(S, base=2))[2:].count("1")
print((min(a_flip, N - a_flip)))
| false | 30 | [
"-b = sum((1 << i) for i in range(1, N, 2)) # 0b ...1010",
"-a_flip = bin(a ^ int(S, base=2))",
"-b_flip = bin(b ^ int(S, base=2))",
"-print((min(a_flip[2:].count(\"1\"), b_flip[2:].count(\"1\"))))",
"+a_flip = bin(a ^ int(S, base=2))[2:].count(\"1\")",
"+print((min(a_flip, N - a_flip)))"
] | false | 0.038105 | 0.057109 | 0.667245 | [
"s935299991",
"s322448560"
] |
u545368057 | p03734 | python | s152948879 | s627801295 | 549 | 161 | 31,720 | 100,932 | Accepted | Accepted | 70.67 | N,W = list(map(int, input().split()))
ws = []
vs = []
for i in range(N):
w,v = list(map(int, input().split()))
ws.append(w)
vs.append(v)
ws_m = [w-ws[0] for w in ws]
"""
i番目まで見て、n個選んでいて、重さがwのときのvの最大値
ただし、wはN個選んだときにW-N*[w[0]]となっているので、そこをmaxとする
dp[i][n][w]
"""
dp = [[[-1]*(3*N+1) for i in range(N+1)] for j in range(N+1)]
dp[0][0][0] = 0
for i,(w,v) in enumerate(zip(ws_m,vs)):
for n in range(i+1):
for j in range(3*N):
if dp[i][n][j] == -1:continue
dp[i+1][n+1][j+w] = max(dp[i][n][j] + v, dp[i][n][j+w])
dp[i+1][n][j] = max(dp[i+1][n][j], dp[i][n][j])
ans = 0
for i,a in enumerate(dp[N]):
w = W - i*ws[0]
if w >= 0:
ans = max(ans,max(a[:w+1]))
print(ans)
| N,W = list(map(int, input().split()))
wvs = []
for i in range(N):
w,v = list(map(int, input().split()))
wvs.append((w,v))
# dp : n個入っていて、合計がwのときの最大値
w0 = wvs[0][0]
dp = [[[-1]*(330) for i in range(110)] for k in range(110)]
dp[0][0][0] = 0
for i in range(N):
w, v = wvs[i]
dw = w-w0
for j in range(i+1):
for k in range(310):
# if k - dw >= 0:
if dp[i][j][j] == -1:continue
dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k])
dp[i+1][j+1][k+dw] = max(dp[i][j][k]+v, dp[i+1][j+1][k+dw])
d = dp[N]
ans = 0
for j in range(N+1):
if W-j*w0 >= 0:
a = max(d[j][:W-j*w0+1])
ans = max(ans, a)
print(ans) | 30 | 26 | 757 | 699 | N, W = list(map(int, input().split()))
ws = []
vs = []
for i in range(N):
w, v = list(map(int, input().split()))
ws.append(w)
vs.append(v)
ws_m = [w - ws[0] for w in ws]
"""
i番目まで見て、n個選んでいて、重さがwのときのvの最大値
ただし、wはN個選んだときにW-N*[w[0]]となっているので、そこをmaxとする
dp[i][n][w]
"""
dp = [[[-1] * (3 * N + 1) for i in range(N + 1)] for j in range(N + 1)]
dp[0][0][0] = 0
for i, (w, v) in enumerate(zip(ws_m, vs)):
for n in range(i + 1):
for j in range(3 * N):
if dp[i][n][j] == -1:
continue
dp[i + 1][n + 1][j + w] = max(dp[i][n][j] + v, dp[i][n][j + w])
dp[i + 1][n][j] = max(dp[i + 1][n][j], dp[i][n][j])
ans = 0
for i, a in enumerate(dp[N]):
w = W - i * ws[0]
if w >= 0:
ans = max(ans, max(a[: w + 1]))
print(ans)
| N, W = list(map(int, input().split()))
wvs = []
for i in range(N):
w, v = list(map(int, input().split()))
wvs.append((w, v))
# dp : n個入っていて、合計がwのときの最大値
w0 = wvs[0][0]
dp = [[[-1] * (330) for i in range(110)] for k in range(110)]
dp[0][0][0] = 0
for i in range(N):
w, v = wvs[i]
dw = w - w0
for j in range(i + 1):
for k in range(310):
# if k - dw >= 0:
if dp[i][j][j] == -1:
continue
dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k])
dp[i + 1][j + 1][k + dw] = max(dp[i][j][k] + v, dp[i + 1][j + 1][k + dw])
d = dp[N]
ans = 0
for j in range(N + 1):
if W - j * w0 >= 0:
a = max(d[j][: W - j * w0 + 1])
ans = max(ans, a)
print(ans)
| false | 13.333333 | [
"-ws = []",
"-vs = []",
"+wvs = []",
"- ws.append(w)",
"- vs.append(v)",
"-ws_m = [w - ws[0] for w in ws]",
"-\"\"\"",
"-i番目まで見て、n個選んでいて、重さがwのときのvの最大値",
"-ただし、wはN個選んだときにW-N*[w[0]]となっているので、そこをmaxとする",
"-dp[i][n][w]",
"-\"\"\"",
"-dp = [[[-1] * (3 * N + 1) for i in range(N + 1)] for j in range(N + 1)]",
"+ wvs.append((w, v))",
"+# dp : n個入っていて、合計がwのときの最大値",
"+w0 = wvs[0][0]",
"+dp = [[[-1] * (330) for i in range(110)] for k in range(110)]",
"-for i, (w, v) in enumerate(zip(ws_m, vs)):",
"- for n in range(i + 1):",
"- for j in range(3 * N):",
"- if dp[i][n][j] == -1:",
"+for i in range(N):",
"+ w, v = wvs[i]",
"+ dw = w - w0",
"+ for j in range(i + 1):",
"+ for k in range(310):",
"+ # if k - dw >= 0:",
"+ if dp[i][j][j] == -1:",
"- dp[i + 1][n + 1][j + w] = max(dp[i][n][j] + v, dp[i][n][j + w])",
"- dp[i + 1][n][j] = max(dp[i + 1][n][j], dp[i][n][j])",
"+ dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k])",
"+ dp[i + 1][j + 1][k + dw] = max(dp[i][j][k] + v, dp[i + 1][j + 1][k + dw])",
"+d = dp[N]",
"-for i, a in enumerate(dp[N]):",
"- w = W - i * ws[0]",
"- if w >= 0:",
"- ans = max(ans, max(a[: w + 1]))",
"+for j in range(N + 1):",
"+ if W - j * w0 >= 0:",
"+ a = max(d[j][: W - j * w0 + 1])",
"+ ans = max(ans, a)"
] | false | 0.036146 | 0.19156 | 0.188693 | [
"s152948879",
"s627801295"
] |
u116002573 | p02682 | python | s350607424 | s308239098 | 21 | 19 | 9,164 | 9,164 | Accepted | Accepted | 9.52 | def main():
A, B, C, K = list(map(int, input().split()))
v = 0
if K <= A:
return K
elif K <= A+B:
return A
else:
return A - (K-A-B)
if __name__ == '__main__':
print((main()))
| def main():
A, B, C, K = list(map(int, input().split()))
if K <= A:
return K
elif K <= A+B:
return A
else:
return A - (K-A-B)
if __name__ == '__main__':
print((main()))
| 13 | 13 | 229 | 220 | def main():
A, B, C, K = list(map(int, input().split()))
v = 0
if K <= A:
return K
elif K <= A + B:
return A
else:
return A - (K - A - B)
if __name__ == "__main__":
print((main()))
| def main():
A, B, C, K = list(map(int, input().split()))
if K <= A:
return K
elif K <= A + B:
return A
else:
return A - (K - A - B)
if __name__ == "__main__":
print((main()))
| false | 0 | [
"- v = 0"
] | false | 0.042231 | 0.042189 | 1.001 | [
"s350607424",
"s308239098"
] |
u340781749 | p03343 | python | s824565782 | s221081032 | 1,394 | 934 | 3,316 | 3,316 | Accepted | Accepted | 33 | def add_list(buf, new_lists, removals):
l = len(buf)
if l >= k:
sbf = sorted(buf)
removals.extend(sbf[:l - k + 1])
new_lists.append(buf)
n, k, q = list(map(int, input().split()))
aaa = list(map(int, input().split()))
srt = sorted(set(aaa))
lists = [aaa]
ans = float('inf')
for a in srt:
new_lists = []
removals = []
for lst in lists:
buf = []
for b in lst:
if a > b:
add_list(buf, new_lists, removals)
buf = []
else:
buf.append(b)
add_list(buf, new_lists, removals)
if len(removals) < q:
break
removals.sort()
ans = min(ans, removals[q - 1] - a)
print(ans)
| def add_list(buf, new_lists, removals):
l = len(buf)
if l >= k:
sbf = sorted(buf)
removals.extend(sbf[:l - k + 1])
new_lists.append(buf)
n, k, q = list(map(int, input().split()))
aaa = list(map(int, input().split()))
srt = sorted(set(aaa))
lists = [aaa]
ans = float('inf')
for a in srt:
new_lists = []
removals = []
for lst in lists:
buf = []
for b in lst:
if a > b:
add_list(buf, new_lists, removals)
buf = []
else:
buf.append(b)
add_list(buf, new_lists, removals)
if len(removals) < q:
break
removals.sort()
ans = min(ans, removals[q - 1] - a)
lists = new_lists
print(ans)
| 31 | 32 | 744 | 767 | def add_list(buf, new_lists, removals):
l = len(buf)
if l >= k:
sbf = sorted(buf)
removals.extend(sbf[: l - k + 1])
new_lists.append(buf)
n, k, q = list(map(int, input().split()))
aaa = list(map(int, input().split()))
srt = sorted(set(aaa))
lists = [aaa]
ans = float("inf")
for a in srt:
new_lists = []
removals = []
for lst in lists:
buf = []
for b in lst:
if a > b:
add_list(buf, new_lists, removals)
buf = []
else:
buf.append(b)
add_list(buf, new_lists, removals)
if len(removals) < q:
break
removals.sort()
ans = min(ans, removals[q - 1] - a)
print(ans)
| def add_list(buf, new_lists, removals):
l = len(buf)
if l >= k:
sbf = sorted(buf)
removals.extend(sbf[: l - k + 1])
new_lists.append(buf)
n, k, q = list(map(int, input().split()))
aaa = list(map(int, input().split()))
srt = sorted(set(aaa))
lists = [aaa]
ans = float("inf")
for a in srt:
new_lists = []
removals = []
for lst in lists:
buf = []
for b in lst:
if a > b:
add_list(buf, new_lists, removals)
buf = []
else:
buf.append(b)
add_list(buf, new_lists, removals)
if len(removals) < q:
break
removals.sort()
ans = min(ans, removals[q - 1] - a)
lists = new_lists
print(ans)
| false | 3.125 | [
"+ lists = new_lists"
] | false | 0.073446 | 0.039887 | 1.841348 | [
"s824565782",
"s221081032"
] |
u493520238 | p03044 | python | s560922578 | s096230736 | 585 | 377 | 81,592 | 95,588 | Accepted | Accepted | 35.56 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def dfs(curr_v, pare_v, curr_sum, visited, g):
if curr_sum%2 == 0:
visited[curr_v] = 0
else:
visited[curr_v] = 1
for neib_vw in g[curr_v]:
if neib_vw[0] == pare_v: continue
dfs(neib_vw[0], curr_v, curr_sum+neib_vw[1], visited, g)
N = int(eval(input()))
g = [ [] for _ in range(N+1)]
visited = [-1] * (N+1)
for _ in range(N-1):
u, v, w = list(map(int, input().split()))
w%=2
g[u].append((v,w))
g[v].append((u,w))
dfs(1, -1, 0, visited, g)
for p in visited[1:]:
print(p)
| from collections import deque
def bfs(start, g, visited):
q = deque([start])
visited[start] = 0
while q:
curr_node = q.popleft()
for next_node, w in g[curr_node]:
if visited[next_node] >= 0: continue
visited[next_node] = (visited[curr_node] + w)%2
q.append(next_node)
n = int(eval(input()))
gl = [ [] for _ in range(n+1)]
for _ in range(n-1):
u,v,w = list(map(int, input().split()))
gl[u].append((v,w))
gl[v].append((u,w))
visited = [-1] * (n+1)
bfs(1, gl, visited)
for v in visited[1:]:
if v%2 == 0: print((0))
else: print((1)) | 29 | 25 | 632 | 624 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def dfs(curr_v, pare_v, curr_sum, visited, g):
if curr_sum % 2 == 0:
visited[curr_v] = 0
else:
visited[curr_v] = 1
for neib_vw in g[curr_v]:
if neib_vw[0] == pare_v:
continue
dfs(neib_vw[0], curr_v, curr_sum + neib_vw[1], visited, g)
N = int(eval(input()))
g = [[] for _ in range(N + 1)]
visited = [-1] * (N + 1)
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
w %= 2
g[u].append((v, w))
g[v].append((u, w))
dfs(1, -1, 0, visited, g)
for p in visited[1:]:
print(p)
| from collections import deque
def bfs(start, g, visited):
q = deque([start])
visited[start] = 0
while q:
curr_node = q.popleft()
for next_node, w in g[curr_node]:
if visited[next_node] >= 0:
continue
visited[next_node] = (visited[curr_node] + w) % 2
q.append(next_node)
n = int(eval(input()))
gl = [[] for _ in range(n + 1)]
for _ in range(n - 1):
u, v, w = list(map(int, input().split()))
gl[u].append((v, w))
gl[v].append((u, w))
visited = [-1] * (n + 1)
bfs(1, gl, visited)
for v in visited[1:]:
if v % 2 == 0:
print((0))
else:
print((1))
| false | 13.793103 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**6)",
"+from collections import deque",
"-def dfs(curr_v, pare_v, curr_sum, visited, g):",
"- if curr_sum % 2 == 0:",
"- visited[curr_v] = 0",
"- else:",
"- visited[curr_v] = 1",
"- for neib_vw in g[curr_v]:",
"- if neib_vw[0] == pare_v:",
"- continue",
"- dfs(neib_vw[0], curr_v, curr_sum + neib_vw[1], visited, g)",
"+def bfs(start, g, visited):",
"+ q = deque([start])",
"+ visited[start] = 0",
"+ while q:",
"+ curr_node = q.popleft()",
"+ for next_node, w in g[curr_node]:",
"+ if visited[next_node] >= 0:",
"+ continue",
"+ visited[next_node] = (visited[curr_node] + w) % 2",
"+ q.append(next_node)",
"-N = int(eval(input()))",
"-g = [[] for _ in range(N + 1)]",
"-visited = [-1] * (N + 1)",
"-for _ in range(N - 1):",
"+n = int(eval(input()))",
"+gl = [[] for _ in range(n + 1)]",
"+for _ in range(n - 1):",
"- w %= 2",
"- g[u].append((v, w))",
"- g[v].append((u, w))",
"-dfs(1, -1, 0, visited, g)",
"-for p in visited[1:]:",
"- print(p)",
"+ gl[u].append((v, w))",
"+ gl[v].append((u, w))",
"+visited = [-1] * (n + 1)",
"+bfs(1, gl, visited)",
"+for v in visited[1:]:",
"+ if v % 2 == 0:",
"+ print((0))",
"+ else:",
"+ print((1))"
] | false | 0.038018 | 0.079186 | 0.480107 | [
"s560922578",
"s096230736"
] |
u721407235 | p02779 | python | s005272815 | s460630452 | 194 | 98 | 40,136 | 25,172 | Accepted | Accepted | 49.48 | from collections import Counter
N=int(eval(input()))
A=list(map(int,input().split()))
c = Counter(A).most_common()
for i in range(len(c)):
if c[i][1]>1:
print("NO")
exit()
print("YES")
| N = int(eval(input()))
A = [int(a) for a in input().split()]
B = set(A)
if len(A)==len(B):
print("YES")
else:
print("NO") | 13 | 8 | 206 | 127 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
c = Counter(A).most_common()
for i in range(len(c)):
if c[i][1] > 1:
print("NO")
exit()
print("YES")
| N = int(eval(input()))
A = [int(a) for a in input().split()]
B = set(A)
if len(A) == len(B):
print("YES")
else:
print("NO")
| false | 38.461538 | [
"-from collections import Counter",
"-",
"-A = list(map(int, input().split()))",
"-c = Counter(A).most_common()",
"-for i in range(len(c)):",
"- if c[i][1] > 1:",
"- print(\"NO\")",
"- exit()",
"-print(\"YES\")",
"+A = [int(a) for a in input().split()]",
"+B = set(A)",
"+if len(A) == len(B):",
"+ print(\"YES\")",
"+else:",
"+ print(\"NO\")"
] | false | 0.085631 | 0.174063 | 0.491956 | [
"s005272815",
"s460630452"
] |
u513081876 | p03730 | python | s979552433 | s223750162 | 41 | 18 | 6,900 | 2,940 | Accepted | Accepted | 56.1 | A, B, C = list(map(int, input().split()))
lis = list(range(1, 100000))
AA =0
for i in lis:
AA = A*i
if AA%B == C:
print('YES')
break
else:
print('NO') | A, B, C = list(map(int, input().split()))
for i in range(1, 500):
if (A * i) % B == C:
print('YES')
break
else:
print('NO') | 10 | 7 | 181 | 147 | A, B, C = list(map(int, input().split()))
lis = list(range(1, 100000))
AA = 0
for i in lis:
AA = A * i
if AA % B == C:
print("YES")
break
else:
print("NO")
| A, B, C = list(map(int, input().split()))
for i in range(1, 500):
if (A * i) % B == C:
print("YES")
break
else:
print("NO")
| false | 30 | [
"-lis = list(range(1, 100000))",
"-AA = 0",
"-for i in lis:",
"- AA = A * i",
"- if AA % B == C:",
"+for i in range(1, 500):",
"+ if (A * i) % B == C:"
] | false | 0.117396 | 0.076454 | 1.535521 | [
"s979552433",
"s223750162"
] |
u029000441 | p03450 | python | s160182155 | s237341125 | 647 | 347 | 121,264 | 84,104 | Accepted | Accepted | 46.37 | n,m=map(int,input().split())
edge=[[]for _ in range(n)]
for _ in range(m):
l,r,d=map(int,input().split())
l-=1
r-=1
edge[l].append((r,d))
edge[r].append((l,-d))
ans=[10**20]*n
inf=10**20
for i in range(n):
if ans[i]!=inf:continue
stack=[i]
visited={i}
ans[i]=0
for node in stack:
for mode,d in edge[node]:
if ans[node]+d!=ans[mode]!=inf:exit(print("No")) #ans[node]+d!=ans[mode] and ans[mode]!=inf
if mode in visited:continue
visited.add(mode)
stack.append(mode)
if ans[mode]==inf:
ans[mode]=ans[node]+d
#if ans[node]+d!=ans[mode]:exit(print("No"))
print("Yes")
| #float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
class WeightedUnionfind():
def __init__(self,n):
self.par =[i for i in range(n+1)]
self.rank =[0]*(n+1)
self.weight =[0]*(n+1)
def find(self,x):
if self.par[x]==x:
return x
else:
y =self.find(self.par[x])
self.weight[x]+=self.weight[self.par[x]]
self.par[x]=y
return y
def union(self,x,y,w):
rx=self.find(x)
ry=self.find(y)
if self.rank[rx]<self.rank[ry]:
self.par[rx]=ry
self.weight[rx]=w-self.weight[x]+self.weight[y]
else:
self.par[ry]=rx
self.weight[ry]=-w-self.weight[y]+self.weight[x]
if self.rank[rx]==self.rank[ry]:
self.rank[rx]+=1
def same(self,x,y):
return self.find(x)==self.find(y)
def diff(self,x,y):
return self.weight[x]-self.weight[y]
n,m=MI()
wuf=WeightedUnionfind(n)
for i in range(m):
l,r,d=MI()
#print(l,r,d,end=" ")
#print(wuf.same(l,r))
if wuf.same(l,r):
#print(wuf.diff(l,r))
if wuf.diff(l,r)!=d:
print("No")
sys.exit()
else:
wuf.union(l,r,d)
print("Yes")
| 27 | 112 | 660 | 2,247 | n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
l, r, d = map(int, input().split())
l -= 1
r -= 1
edge[l].append((r, d))
edge[r].append((l, -d))
ans = [10**20] * n
inf = 10**20
for i in range(n):
if ans[i] != inf:
continue
stack = [i]
visited = {i}
ans[i] = 0
for node in stack:
for mode, d in edge[node]:
if ans[node] + d != ans[mode] != inf:
exit(print("No")) # ans[node]+d!=ans[mode] and ans[mode]!=inf
if mode in visited:
continue
visited.add(mode)
stack.append(mode)
if ans[mode] == inf:
ans[mode] = ans[node] + d
# if ans[node]+d!=ans[mode]:exit(print("No"))
print("Yes")
| # float型を許すな
# numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi, factorial
from operator import itemgetter
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def LI2():
return [int(eval(input())) for i in range(n)]
def MXI():
return [[LI()] for i in range(n)]
def SI():
return input().rstrip()
def printns(x):
print(("\n".join(x)))
def printni(x):
print(("\n".join(list(map(str, x)))))
inf = 10**17
mod = 10**9 + 7
class WeightedUnionfind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
self.weight = [0] * (n + 1)
def find(self, x):
if self.par[x] == x:
return x
else:
y = self.find(self.par[x])
self.weight[x] += self.weight[self.par[x]]
self.par[x] = y
return y
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if self.rank[rx] < self.rank[ry]:
self.par[rx] = ry
self.weight[rx] = w - self.weight[x] + self.weight[y]
else:
self.par[ry] = rx
self.weight[ry] = -w - self.weight[y] + self.weight[x]
if self.rank[rx] == self.rank[ry]:
self.rank[rx] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
def diff(self, x, y):
return self.weight[x] - self.weight[y]
n, m = MI()
wuf = WeightedUnionfind(n)
for i in range(m):
l, r, d = MI()
# print(l,r,d,end=" ")
# print(wuf.same(l,r))
if wuf.same(l, r):
# print(wuf.diff(l,r))
if wuf.diff(l, r) != d:
print("No")
sys.exit()
else:
wuf.union(l, r, d)
print("Yes")
| false | 75.892857 | [
"-n, m = map(int, input().split())",
"-edge = [[] for _ in range(n)]",
"-for _ in range(m):",
"- l, r, d = map(int, input().split())",
"- l -= 1",
"- r -= 1",
"- edge[l].append((r, d))",
"- edge[r].append((l, -d))",
"-ans = [10**20] * n",
"-inf = 10**20",
"-for i in range(n):",
"- if ans[i] != inf:",
"- continue",
"- stack = [i]",
"- visited = {i}",
"- ans[i] = 0",
"- for node in stack:",
"- for mode, d in edge[node]:",
"- if ans[node] + d != ans[mode] != inf:",
"- exit(print(\"No\")) # ans[node]+d!=ans[mode] and ans[mode]!=inf",
"- if mode in visited:",
"- continue",
"- visited.add(mode)",
"- stack.append(mode)",
"- if ans[mode] == inf:",
"- ans[mode] = ans[node] + d",
"- # if ans[node]+d!=ans[mode]:exit(print(\"No\"))",
"+# float型を許すな",
"+# numpyはpythonで",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**7)",
"+from collections import Counter, deque",
"+from collections import defaultdict",
"+from itertools import combinations, permutations, accumulate, groupby, product",
"+from bisect import bisect_left, bisect_right",
"+from heapq import heapify, heappop, heappush",
"+from math import floor, ceil, pi, factorial",
"+from operator import itemgetter",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI2():",
"+ return [int(eval(input())) for i in range(n)]",
"+",
"+",
"+def MXI():",
"+ return [[LI()] for i in range(n)]",
"+",
"+",
"+def SI():",
"+ return input().rstrip()",
"+",
"+",
"+def printns(x):",
"+ print((\"\\n\".join(x)))",
"+",
"+",
"+def printni(x):",
"+ print((\"\\n\".join(list(map(str, x)))))",
"+",
"+",
"+inf = 10**17",
"+mod = 10**9 + 7",
"+",
"+",
"+class WeightedUnionfind:",
"+ def __init__(self, n):",
"+ self.par = [i for i in range(n + 1)]",
"+ self.rank = [0] * (n + 1)",
"+ self.weight = [0] * (n + 1)",
"+",
"+ def find(self, x):",
"+ if self.par[x] == x:",
"+ return x",
"+ else:",
"+ y = self.find(self.par[x])",
"+ self.weight[x] += self.weight[self.par[x]]",
"+ self.par[x] = y",
"+ return y",
"+",
"+ def union(self, x, y, w):",
"+ rx = self.find(x)",
"+ ry = self.find(y)",
"+ if self.rank[rx] < self.rank[ry]:",
"+ self.par[rx] = ry",
"+ self.weight[rx] = w - self.weight[x] + self.weight[y]",
"+ else:",
"+ self.par[ry] = rx",
"+ self.weight[ry] = -w - self.weight[y] + self.weight[x]",
"+ if self.rank[rx] == self.rank[ry]:",
"+ self.rank[rx] += 1",
"+",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ def diff(self, x, y):",
"+ return self.weight[x] - self.weight[y]",
"+",
"+",
"+n, m = MI()",
"+wuf = WeightedUnionfind(n)",
"+for i in range(m):",
"+ l, r, d = MI()",
"+ # print(l,r,d,end=\" \")",
"+ # print(wuf.same(l,r))",
"+ if wuf.same(l, r):",
"+ # print(wuf.diff(l,r))",
"+ if wuf.diff(l, r) != d:",
"+ print(\"No\")",
"+ sys.exit()",
"+ else:",
"+ wuf.union(l, r, d)"
] | false | 0.238528 | 0.080373 | 2.967768 | [
"s160182155",
"s237341125"
] |
u539692012 | p02690 | python | s955604538 | s260510169 | 1,497 | 873 | 731,276 | 417,380 | Accepted | Accepted | 41.68 | c=24000
exec(c*2*f'i,j=c%200,c//200;i**5-j**5-{input()}or exit(print(i,j));c-=1;') | M=120
c=M*M
exec(c*2*f'i,j=c%M,c//M;c-=i**5-j**5!={input()}or exit(print(i,j));') | 2 | 3 | 83 | 83 | c = 24000
exec(c * 2 * f"i,j=c%200,c//200;i**5-j**5-{input()}or exit(print(i,j));c-=1;")
| M = 120
c = M * M
exec(c * 2 * f"i,j=c%M,c//M;c-=i**5-j**5!={input()}or exit(print(i,j));")
| false | 33.333333 | [
"-c = 24000",
"-exec(c * 2 * f\"i,j=c%200,c//200;i**5-j**5-{input()}or exit(print(i,j));c-=1;\")",
"+M = 120",
"+c = M * M",
"+exec(c * 2 * f\"i,j=c%M,c//M;c-=i**5-j**5!={input()}or exit(print(i,j));\")"
] | false | 1.703107 | 1.316537 | 1.293626 | [
"s955604538",
"s260510169"
] |
u748241164 | p03607 | python | s229782656 | s403323395 | 215 | 173 | 16,624 | 21,024 | Accepted | Accepted | 19.53 | import collections
N = int(eval(input()))
x = [0] * N
for i in range(N):
x[i] = int(eval(input()))
q = collections.Counter(x)
value = list(q.values())
count = 0
for i in value:
if i % 2 == 1:
count += 1
print(count)
| import collections
N = int(eval(input()))
ans = [0] * N
for i in range(N):
ans[i] = int(eval(input()))
C = collections.Counter(ans)
count = 0
for i in list(C.values()):
if i % 2 == 1:
count += 1
print(count) | 15 | 14 | 225 | 217 | import collections
N = int(eval(input()))
x = [0] * N
for i in range(N):
x[i] = int(eval(input()))
q = collections.Counter(x)
value = list(q.values())
count = 0
for i in value:
if i % 2 == 1:
count += 1
print(count)
| import collections
N = int(eval(input()))
ans = [0] * N
for i in range(N):
ans[i] = int(eval(input()))
C = collections.Counter(ans)
count = 0
for i in list(C.values()):
if i % 2 == 1:
count += 1
print(count)
| false | 6.666667 | [
"-x = [0] * N",
"+ans = [0] * N",
"- x[i] = int(eval(input()))",
"-q = collections.Counter(x)",
"-value = list(q.values())",
"+ ans[i] = int(eval(input()))",
"+C = collections.Counter(ans)",
"-for i in value:",
"+for i in list(C.values()):"
] | false | 0.037191 | 0.037634 | 0.988245 | [
"s229782656",
"s403323395"
] |
u905203728 | p02937 | python | s087550373 | s319577888 | 131 | 116 | 85,112 | 79,388 | Accepted | Accepted | 11.45 | from collections import defaultdict
from bisect import bisect_right
s,t=eval(input()),eval(input())
m=len(s)
if set(s)&set(t)!=set(t):print((-1));exit()
dict=defaultdict(list)
for i,j in enumerate(s):
dict[j] +=[i+1]
ans,index=0,0
for i in t:
point=bisect_right(dict[i],index)
if point==len(dict[i]):num=dict[i][0]
else:num=dict[i][point]
if index>=num:
ans +=m
index=num
print((ans+index)) | from collections import defaultdict
from bisect import bisect_right
s,t=eval(input()),eval(input())
m=len(s)
dictionary=defaultdict(list)
for i,j in enumerate(s):
dictionary[j] +=[i+1]
index,ans=0,0
for i in t:
try:
point=bisect_right(dictionary[i],index)
if point==len(dictionary[i]):num=dictionary[i][0]
else:num=dictionary[i][point]
if index>=num:
ans +=m
index=num
except:print((-1));exit()
print((ans+index)) | 23 | 22 | 434 | 486 | from collections import defaultdict
from bisect import bisect_right
s, t = eval(input()), eval(input())
m = len(s)
if set(s) & set(t) != set(t):
print((-1))
exit()
dict = defaultdict(list)
for i, j in enumerate(s):
dict[j] += [i + 1]
ans, index = 0, 0
for i in t:
point = bisect_right(dict[i], index)
if point == len(dict[i]):
num = dict[i][0]
else:
num = dict[i][point]
if index >= num:
ans += m
index = num
print((ans + index))
| from collections import defaultdict
from bisect import bisect_right
s, t = eval(input()), eval(input())
m = len(s)
dictionary = defaultdict(list)
for i, j in enumerate(s):
dictionary[j] += [i + 1]
index, ans = 0, 0
for i in t:
try:
point = bisect_right(dictionary[i], index)
if point == len(dictionary[i]):
num = dictionary[i][0]
else:
num = dictionary[i][point]
if index >= num:
ans += m
index = num
except:
print((-1))
exit()
print((ans + index))
| false | 4.347826 | [
"-if set(s) & set(t) != set(t):",
"- print((-1))",
"- exit()",
"-dict = defaultdict(list)",
"+dictionary = defaultdict(list)",
"- dict[j] += [i + 1]",
"-ans, index = 0, 0",
"+ dictionary[j] += [i + 1]",
"+index, ans = 0, 0",
"- point = bisect_right(dict[i], index)",
"- if point == len(dict[i]):",
"- num = dict[i][0]",
"- else:",
"- num = dict[i][point]",
"- if index >= num:",
"- ans += m",
"- index = num",
"+ try:",
"+ point = bisect_right(dictionary[i], index)",
"+ if point == len(dictionary[i]):",
"+ num = dictionary[i][0]",
"+ else:",
"+ num = dictionary[i][point]",
"+ if index >= num:",
"+ ans += m",
"+ index = num",
"+ except:",
"+ print((-1))",
"+ exit()"
] | false | 0.0342 | 0.041423 | 0.825634 | [
"s087550373",
"s319577888"
] |
u576432509 | p03805 | python | s730445514 | s755311366 | 65 | 27 | 3,064 | 3,064 | Accepted | Accepted | 58.46 | n,m=list(map(int,input().split()))
a=[]
for i in range(m):
ai,bi=list(map(int,input().split()))
a.append([ai,bi])
ni=[0]*n
nii=[]
def pathm(n,a,bi,pcnt,ni):
if n==1:
pcnt=pcnt+1
# print("2:","n:",n,"bi:",bi,"pcnt:",pcnt)
return pcnt
else:
n=n-1
nii.append(bi)
for mm in range(m):
if a[mm][0]==bi and not a[mm][1] in nii:
# if a[mm][0]==bi :
ni[a[mm][1]-1]=1
# print("1:","n:",n,"mm:",mm,"a[mm][1]:",a[mm][1],"pcnt:",pcnt)
pcnt=pathm(n,a,a[mm][1],pcnt,ni)
if a[mm][1]==bi and not a[mm][0] in nii:
# if a[mm][1]==bi and ni[a[mm][0]-1]==0 :
ni[a[mm][0]-1]=1
# ni[mm]=1
# print("1:","n:",n,"mm:",mm,"a[mm][0]:",a[mm][0],"pcnt:",pcnt)
pcnt=pathm(n,a,a[mm][0],pcnt,ni)
nii.pop()
return pcnt
pcnt=0
pcnt1=pathm(n,a,1,pcnt,ni)
print(pcnt1)
| q=[]
qq=[]
def dfs(j,q,icnt,count,n,qq):
if len(qq)==n:
count+=1
# print("1",n,j,icnt,count,q[j],qq)
return count
icnt+=1
for j2 in q[j]:
if not j2 in qq:
qq.append(j2)
# print("2",n,j,icnt,count,q[j],qq)
count=dfs(j2,q,icnt,count,n,qq)
qq.pop()
# print("3",n,j,icnt,count,q[j],qq)
return count
n,m=list(map(int,input().split()))
ab=[[0]*2 for i in range(m)]
for i in range(m):
ab[i]=list(map(int,input().split()))
#n=3
#m=3
#ab=[[1,2],[1,3],[2,3]]
#n=7
#m=7
#ab=[[1,3],[2,7],[3,4],[4,5],[4,6],[5,6],[6,7]]
q=[[]*2 for i in range(n)]
for i in range(m):
if not q[ab[i][1]-1] in q[ab[i][0]-1]:
q[ab[i][0]-1].append(ab[i][1]-1)
if not q[ab[i][0]-1] in q[ab[i][1]-1]:
q[ab[i][1]-1].append(ab[i][0]-1)
#print(q)
count=0
j=0
qq=[j]
icnt=1
count=dfs(j,q,icnt,count,n,qq)
print(count) | 36 | 45 | 1,035 | 965 | n, m = list(map(int, input().split()))
a = []
for i in range(m):
ai, bi = list(map(int, input().split()))
a.append([ai, bi])
ni = [0] * n
nii = []
def pathm(n, a, bi, pcnt, ni):
if n == 1:
pcnt = pcnt + 1
# print("2:","n:",n,"bi:",bi,"pcnt:",pcnt)
return pcnt
else:
n = n - 1
nii.append(bi)
for mm in range(m):
if a[mm][0] == bi and not a[mm][1] in nii:
# if a[mm][0]==bi :
ni[a[mm][1] - 1] = 1
# print("1:","n:",n,"mm:",mm,"a[mm][1]:",a[mm][1],"pcnt:",pcnt)
pcnt = pathm(n, a, a[mm][1], pcnt, ni)
if a[mm][1] == bi and not a[mm][0] in nii:
# if a[mm][1]==bi and ni[a[mm][0]-1]==0 :
ni[a[mm][0] - 1] = 1
# ni[mm]=1
# print("1:","n:",n,"mm:",mm,"a[mm][0]:",a[mm][0],"pcnt:",pcnt)
pcnt = pathm(n, a, a[mm][0], pcnt, ni)
nii.pop()
return pcnt
pcnt = 0
pcnt1 = pathm(n, a, 1, pcnt, ni)
print(pcnt1)
| q = []
qq = []
def dfs(j, q, icnt, count, n, qq):
if len(qq) == n:
count += 1
# print("1",n,j,icnt,count,q[j],qq)
return count
icnt += 1
for j2 in q[j]:
if not j2 in qq:
qq.append(j2)
# print("2",n,j,icnt,count,q[j],qq)
count = dfs(j2, q, icnt, count, n, qq)
qq.pop()
# print("3",n,j,icnt,count,q[j],qq)
return count
n, m = list(map(int, input().split()))
ab = [[0] * 2 for i in range(m)]
for i in range(m):
ab[i] = list(map(int, input().split()))
# n=3
# m=3
# ab=[[1,2],[1,3],[2,3]]
# n=7
# m=7
# ab=[[1,3],[2,7],[3,4],[4,5],[4,6],[5,6],[6,7]]
q = [[] * 2 for i in range(n)]
for i in range(m):
if not q[ab[i][1] - 1] in q[ab[i][0] - 1]:
q[ab[i][0] - 1].append(ab[i][1] - 1)
if not q[ab[i][0] - 1] in q[ab[i][1] - 1]:
q[ab[i][1] - 1].append(ab[i][0] - 1)
# print(q)
count = 0
j = 0
qq = [j]
icnt = 1
count = dfs(j, q, icnt, count, n, qq)
print(count)
| false | 20 | [
"-n, m = list(map(int, input().split()))",
"-a = []",
"-for i in range(m):",
"- ai, bi = list(map(int, input().split()))",
"- a.append([ai, bi])",
"-ni = [0] * n",
"-nii = []",
"+q = []",
"+qq = []",
"-def pathm(n, a, bi, pcnt, ni):",
"- if n == 1:",
"- pcnt = pcnt + 1",
"- # print(\"2:\",\"n:\",n,\"bi:\",bi,\"pcnt:\",pcnt)",
"- return pcnt",
"- else:",
"- n = n - 1",
"- nii.append(bi)",
"- for mm in range(m):",
"- if a[mm][0] == bi and not a[mm][1] in nii:",
"- # if a[mm][0]==bi :",
"- ni[a[mm][1] - 1] = 1",
"- # print(\"1:\",\"n:\",n,\"mm:\",mm,\"a[mm][1]:\",a[mm][1],\"pcnt:\",pcnt)",
"- pcnt = pathm(n, a, a[mm][1], pcnt, ni)",
"- if a[mm][1] == bi and not a[mm][0] in nii:",
"- # if a[mm][1]==bi and ni[a[mm][0]-1]==0 :",
"- ni[a[mm][0] - 1] = 1",
"- # ni[mm]=1",
"- # print(\"1:\",\"n:\",n,\"mm:\",mm,\"a[mm][0]:\",a[mm][0],\"pcnt:\",pcnt)",
"- pcnt = pathm(n, a, a[mm][0], pcnt, ni)",
"- nii.pop()",
"- return pcnt",
"+def dfs(j, q, icnt, count, n, qq):",
"+ if len(qq) == n:",
"+ count += 1",
"+ # print(\"1\",n,j,icnt,count,q[j],qq)",
"+ return count",
"+ icnt += 1",
"+ for j2 in q[j]:",
"+ if not j2 in qq:",
"+ qq.append(j2)",
"+ # print(\"2\",n,j,icnt,count,q[j],qq)",
"+ count = dfs(j2, q, icnt, count, n, qq)",
"+ qq.pop()",
"+ # print(\"3\",n,j,icnt,count,q[j],qq)",
"+ return count",
"-pcnt = 0",
"-pcnt1 = pathm(n, a, 1, pcnt, ni)",
"-print(pcnt1)",
"+n, m = list(map(int, input().split()))",
"+ab = [[0] * 2 for i in range(m)]",
"+for i in range(m):",
"+ ab[i] = list(map(int, input().split()))",
"+# n=3",
"+# m=3",
"+# ab=[[1,2],[1,3],[2,3]]",
"+# n=7",
"+# m=7",
"+# ab=[[1,3],[2,7],[3,4],[4,5],[4,6],[5,6],[6,7]]",
"+q = [[] * 2 for i in range(n)]",
"+for i in range(m):",
"+ if not q[ab[i][1] - 1] in q[ab[i][0] - 1]:",
"+ q[ab[i][0] - 1].append(ab[i][1] - 1)",
"+ if not q[ab[i][0] - 1] in q[ab[i][1] - 1]:",
"+ q[ab[i][1] - 1].append(ab[i][0] - 1)",
"+# print(q)",
"+count = 0",
"+j = 0",
"+qq = [j]",
"+icnt = 1",
"+count = dfs(j, q, icnt, count, n, qq)",
"+print(count)"
] | false | 0.094544 | 0.04493 | 2.104262 | [
"s730445514",
"s755311366"
] |
u077291787 | p02803 | python | s398681385 | s599050440 | 450 | 295 | 3,316 | 3,444 | Accepted | Accepted | 34.44 | # D - Maze Master
from collections import deque, defaultdict
INF = 1 << 30
MOD = 10 ** 9 + 7
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0)]
def bfs(sx: int, sy: int):
queue = deque([(sx, sy)])
dist = defaultdict(lambda: INF)
dist[sx * MOD + sy] = 0
while queue:
x, y = queue.popleft()
for dx, dy in dxy:
nx, ny = x + dx, y + dy
if S[nx][ny] == "." and dist[x * MOD + y] + 1 < dist[nx * MOD + ny]:
dist[nx * MOD + ny] = dist[x * MOD + y] + 1
queue.append((nx, ny))
return max(dist.values())
def main():
global S
H, W, *S = open(0).read().split()
H, W = int(H) + 2, int(W) + 2
S = ["#" * W] + ["#" + s + "#" for s in S] + ["#" * W] # put sentinels
ans = max(bfs(i, j) for i, s in enumerate(S) for j, c in enumerate(s) if c == ".")
print(ans)
if __name__ == "__main__":
main()
| # D - Maze Master
from collections import deque, defaultdict
INF = 1 << 30
MOD = 10 ** 9 + 7
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0)]
def bfs(sx: int, sy: int):
queue = deque([(sx, sy)])
dist = defaultdict(lambda: INF)
dist[sx * MOD + sy] = 0
while queue:
x, y = queue.popleft()
for dx, dy in dxy:
nx, ny = x + dx, y + dy
if S[nx][ny] == ".":
if nx * MOD + ny not in dist:
dist[nx * MOD + ny] = dist[x * MOD + y] + 1
queue.append((nx, ny))
return max(dist.values())
def main():
global S
H, W, *S = open(0).read().split()
H, W = int(H) + 2, int(W) + 2
S = ["#" * W] + ["#" + s + "#" for s in S] + ["#" * W] # put sentinels
ans = max(bfs(i, j) for i, s in enumerate(S) for j, c in enumerate(s) if c == ".")
print(ans)
if __name__ == "__main__":
main()
| 33 | 34 | 928 | 935 | # D - Maze Master
from collections import deque, defaultdict
INF = 1 << 30
MOD = 10**9 + 7
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0)]
def bfs(sx: int, sy: int):
queue = deque([(sx, sy)])
dist = defaultdict(lambda: INF)
dist[sx * MOD + sy] = 0
while queue:
x, y = queue.popleft()
for dx, dy in dxy:
nx, ny = x + dx, y + dy
if S[nx][ny] == "." and dist[x * MOD + y] + 1 < dist[nx * MOD + ny]:
dist[nx * MOD + ny] = dist[x * MOD + y] + 1
queue.append((nx, ny))
return max(dist.values())
def main():
global S
H, W, *S = open(0).read().split()
H, W = int(H) + 2, int(W) + 2
S = ["#" * W] + ["#" + s + "#" for s in S] + ["#" * W] # put sentinels
ans = max(bfs(i, j) for i, s in enumerate(S) for j, c in enumerate(s) if c == ".")
print(ans)
if __name__ == "__main__":
main()
| # D - Maze Master
from collections import deque, defaultdict
INF = 1 << 30
MOD = 10**9 + 7
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0)]
def bfs(sx: int, sy: int):
queue = deque([(sx, sy)])
dist = defaultdict(lambda: INF)
dist[sx * MOD + sy] = 0
while queue:
x, y = queue.popleft()
for dx, dy in dxy:
nx, ny = x + dx, y + dy
if S[nx][ny] == ".":
if nx * MOD + ny not in dist:
dist[nx * MOD + ny] = dist[x * MOD + y] + 1
queue.append((nx, ny))
return max(dist.values())
def main():
global S
H, W, *S = open(0).read().split()
H, W = int(H) + 2, int(W) + 2
S = ["#" * W] + ["#" + s + "#" for s in S] + ["#" * W] # put sentinels
ans = max(bfs(i, j) for i, s in enumerate(S) for j, c in enumerate(s) if c == ".")
print(ans)
if __name__ == "__main__":
main()
| false | 2.941176 | [
"- if S[nx][ny] == \".\" and dist[x * MOD + y] + 1 < dist[nx * MOD + ny]:",
"- dist[nx * MOD + ny] = dist[x * MOD + y] + 1",
"- queue.append((nx, ny))",
"+ if S[nx][ny] == \".\":",
"+ if nx * MOD + ny not in dist:",
"+ dist[nx * MOD + ny] = dist[x * MOD + y] + 1",
"+ queue.append((nx, ny))"
] | false | 0.043637 | 0.041123 | 1.061115 | [
"s398681385",
"s599050440"
] |
u172035535 | p03073 | python | s528229403 | s227083972 | 52 | 46 | 4,476 | 3,188 | Accepted | Accepted | 11.54 | S = eval(input())
def func():
from collections import Counter as c
ev,od = [],[]
for i in range(len(S)):
ev.append(S[i]) if i%2 == 0 else 0
od.append(S[i]) if i%2 == 1 else 0
ev = c(ev).most_common()
od = c(od).most_common()
if len(od) == 0:
return 0
if ev[0][0] != od[0][0]:
return len(S)-ev[0][1]-od[0][1]
else:
if len(ev) == len(od) == 1:
return len(S)//2
else:
return min(len(S)-ev[0][1]-od[-1][1],len(S)-ev[-1][1]-od[0][1])
print((func())) | S = eval(input())
ans0 = 0
ans1 = 0
for i in range(len(S)):
if i%2 == 0:
if S[i] == '0':
ans1 += 1
else:
ans0 += 1
else:
if S[i] == '1':
ans1 += 1
else:
ans0 += 1
print((min(ans0,ans1))) | 19 | 15 | 558 | 280 | S = eval(input())
def func():
from collections import Counter as c
ev, od = [], []
for i in range(len(S)):
ev.append(S[i]) if i % 2 == 0 else 0
od.append(S[i]) if i % 2 == 1 else 0
ev = c(ev).most_common()
od = c(od).most_common()
if len(od) == 0:
return 0
if ev[0][0] != od[0][0]:
return len(S) - ev[0][1] - od[0][1]
else:
if len(ev) == len(od) == 1:
return len(S) // 2
else:
return min(len(S) - ev[0][1] - od[-1][1], len(S) - ev[-1][1] - od[0][1])
print((func()))
| S = eval(input())
ans0 = 0
ans1 = 0
for i in range(len(S)):
if i % 2 == 0:
if S[i] == "0":
ans1 += 1
else:
ans0 += 1
else:
if S[i] == "1":
ans1 += 1
else:
ans0 += 1
print((min(ans0, ans1)))
| false | 21.052632 | [
"-",
"-",
"-def func():",
"- from collections import Counter as c",
"-",
"- ev, od = [], []",
"- for i in range(len(S)):",
"- ev.append(S[i]) if i % 2 == 0 else 0",
"- od.append(S[i]) if i % 2 == 1 else 0",
"- ev = c(ev).most_common()",
"- od = c(od).most_common()",
"- if len(od) == 0:",
"- return 0",
"- if ev[0][0] != od[0][0]:",
"- return len(S) - ev[0][1] - od[0][1]",
"+ans0 = 0",
"+ans1 = 0",
"+for i in range(len(S)):",
"+ if i % 2 == 0:",
"+ if S[i] == \"0\":",
"+ ans1 += 1",
"+ else:",
"+ ans0 += 1",
"- if len(ev) == len(od) == 1:",
"- return len(S) // 2",
"+ if S[i] == \"1\":",
"+ ans1 += 1",
"- return min(len(S) - ev[0][1] - od[-1][1], len(S) - ev[-1][1] - od[0][1])",
"-",
"-",
"-print((func()))",
"+ ans0 += 1",
"+print((min(ans0, ans1)))"
] | false | 0.035307 | 0.056276 | 0.627391 | [
"s528229403",
"s227083972"
] |
u010072501 | p03423 | python | s090728074 | s742527801 | 31 | 24 | 9,004 | 9,072 | Accepted | Accepted | 22.58 | # A - Grouping 2
# ある学校に N 人の生徒がいる
# なるべく多く 3人 以上のグループにしたい!
# 3人以上のグループを 最大で x 個 作れるときの x の値を出力する
# 生徒数 N (整数) を入力
N = int(eval(input()))
# print(N)
# N を 3 で割った余りで 計算する
if N % 3 == 0:
# print('amari0')
answer = int(N / 3)
elif N % 3 == 1:
# print('amari1')
answer = int((N - 1) / 3)
else:
# print('amari2')
answer = int((N - 2) / 3)
# 結果の表示
print(answer)
| # A - Grouping 2
# ある学校に N 人の生徒がいる
# なるべく多く 3人 以上のグループにしたい!
# 3人以上のグループを 最大で x 個 作れるときの x の値を出力する
# 生徒数 N (整数) を入力
N = int(eval(input()))
# print(N)
# # N を 3 で割った余りで 計算する
# if 及び % を使わずに再現
answer = int(N / 3)
# 結果の表示
print(answer)
| 23 | 16 | 400 | 245 | # A - Grouping 2
# ある学校に N 人の生徒がいる
# なるべく多く 3人 以上のグループにしたい!
# 3人以上のグループを 最大で x 個 作れるときの x の値を出力する
# 生徒数 N (整数) を入力
N = int(eval(input()))
# print(N)
# N を 3 で割った余りで 計算する
if N % 3 == 0:
# print('amari0')
answer = int(N / 3)
elif N % 3 == 1:
# print('amari1')
answer = int((N - 1) / 3)
else:
# print('amari2')
answer = int((N - 2) / 3)
# 結果の表示
print(answer)
| # A - Grouping 2
# ある学校に N 人の生徒がいる
# なるべく多く 3人 以上のグループにしたい!
# 3人以上のグループを 最大で x 個 作れるときの x の値を出力する
# 生徒数 N (整数) を入力
N = int(eval(input()))
# print(N)
# # N を 3 で割った余りで 計算する
# if 及び % を使わずに再現
answer = int(N / 3)
# 結果の表示
print(answer)
| false | 30.434783 | [
"-# N を 3 で割った余りで 計算する",
"-if N % 3 == 0:",
"- # print('amari0')",
"- answer = int(N / 3)",
"-elif N % 3 == 1:",
"- # print('amari1')",
"- answer = int((N - 1) / 3)",
"-else:",
"- # print('amari2')",
"- answer = int((N - 2) / 3)",
"+# # N を 3 で割った余りで 計算する",
"+# if 及び % を使わずに再現",
"+answer = int(N / 3)"
] | false | 0.041861 | 0.043325 | 0.966192 | [
"s090728074",
"s742527801"
] |
u077291787 | p02900 | python | s820700523 | s597024560 | 136 | 98 | 5,844 | 5,048 | Accepted | Accepted | 27.94 | # ABC142D - Disjoint Set of Common Divisors
from fractions import gcd
def divisors(n: int) -> set:
div = set()
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
div.add(i), div.add(n // i)
return sorted(div)
def main():
A, B = list(map(int, input().split()))
divs, groups = divisors(gcd(A, B)), set()
for i in divs[1:]:
if all(i % x for x in groups):
groups.add(i) # coprime to all numbers in "groups"
ans = len(groups) + 1
print(ans)
if __name__ == "__main__":
main() | # ABC142D - Disjoint Set of Common Divisors
from fractions import gcd
# cf. AtCoder ARC067C, Euler 012
def prime_factorization(x: int) -> dict:
"""
Prime factorization of a number (trial division)
Args: x (int): a number to be resolved
Return: ret (dict): {prime factor: power}
e.g., n = 2^a * 3^b -> {2: a, 3: b}
"""
max_prime = 0
ret = {}
# Divide x by 2 as much as possible
cnt = 0
while x % 2 == 0:
x //= 2
cnt += 1
if cnt > 0:
max_prime = 2
ret[max_prime] = cnt
# x must be odd -> skip even numbers
cnt = 0
for i in range(3, int(x ** 0.5) + 1, 2):
cnt = 0
while x % i == 0:
x //= i
max_prime = i
cnt += 1
if cnt > 0:
ret[max_prime] = cnt
# To handle the case when x is prime greater than 2
if x > 2:
max_prime = x
ret[max_prime] = 1
return ret
def main():
A, B = list(map(int, input().split()))
g = gcd(A, B)
ans = len(list(prime_factorization(g).keys())) + 1
print(ans)
if __name__ == "__main__":
main() | 24 | 53 | 571 | 1,180 | # ABC142D - Disjoint Set of Common Divisors
from fractions import gcd
def divisors(n: int) -> set:
div = set()
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
div.add(i), div.add(n // i)
return sorted(div)
def main():
A, B = list(map(int, input().split()))
divs, groups = divisors(gcd(A, B)), set()
for i in divs[1:]:
if all(i % x for x in groups):
groups.add(i) # coprime to all numbers in "groups"
ans = len(groups) + 1
print(ans)
if __name__ == "__main__":
main()
| # ABC142D - Disjoint Set of Common Divisors
from fractions import gcd
# cf. AtCoder ARC067C, Euler 012
def prime_factorization(x: int) -> dict:
"""
Prime factorization of a number (trial division)
Args: x (int): a number to be resolved
Return: ret (dict): {prime factor: power}
e.g., n = 2^a * 3^b -> {2: a, 3: b}
"""
max_prime = 0
ret = {}
# Divide x by 2 as much as possible
cnt = 0
while x % 2 == 0:
x //= 2
cnt += 1
if cnt > 0:
max_prime = 2
ret[max_prime] = cnt
# x must be odd -> skip even numbers
cnt = 0
for i in range(3, int(x**0.5) + 1, 2):
cnt = 0
while x % i == 0:
x //= i
max_prime = i
cnt += 1
if cnt > 0:
ret[max_prime] = cnt
# To handle the case when x is prime greater than 2
if x > 2:
max_prime = x
ret[max_prime] = 1
return ret
def main():
A, B = list(map(int, input().split()))
g = gcd(A, B)
ans = len(list(prime_factorization(g).keys())) + 1
print(ans)
if __name__ == "__main__":
main()
| false | 54.716981 | [
"-",
"-def divisors(n: int) -> set:",
"- div = set()",
"- for i in range(1, int(n**0.5) + 1):",
"- if n % i == 0:",
"- div.add(i), div.add(n // i)",
"- return sorted(div)",
"+# cf. AtCoder ARC067C, Euler 012",
"+def prime_factorization(x: int) -> dict:",
"+ \"\"\"",
"+ Prime factorization of a number (trial division)",
"+ Args: x (int): a number to be resolved",
"+ Return: ret (dict): {prime factor: power}",
"+ e.g., n = 2^a * 3^b -> {2: a, 3: b}",
"+ \"\"\"",
"+ max_prime = 0",
"+ ret = {}",
"+ # Divide x by 2 as much as possible",
"+ cnt = 0",
"+ while x % 2 == 0:",
"+ x //= 2",
"+ cnt += 1",
"+ if cnt > 0:",
"+ max_prime = 2",
"+ ret[max_prime] = cnt",
"+ # x must be odd -> skip even numbers",
"+ cnt = 0",
"+ for i in range(3, int(x**0.5) + 1, 2):",
"+ cnt = 0",
"+ while x % i == 0:",
"+ x //= i",
"+ max_prime = i",
"+ cnt += 1",
"+ if cnt > 0:",
"+ ret[max_prime] = cnt",
"+ # To handle the case when x is prime greater than 2",
"+ if x > 2:",
"+ max_prime = x",
"+ ret[max_prime] = 1",
"+ return ret",
"- divs, groups = divisors(gcd(A, B)), set()",
"- for i in divs[1:]:",
"- if all(i % x for x in groups):",
"- groups.add(i) # coprime to all numbers in \"groups\"",
"- ans = len(groups) + 1",
"+ g = gcd(A, B)",
"+ ans = len(list(prime_factorization(g).keys())) + 1"
] | false | 0.039982 | 0.046508 | 0.85967 | [
"s820700523",
"s597024560"
] |
u953311536 | p03845 | python | s174680143 | s204229837 | 186 | 31 | 38,416 | 3,444 | Accepted | Accepted | 83.33 | N = int(eval(input()))
T = list(map(int, input().split()))
T = [0] + T
M = int(eval(input()))
for _ in range(M):
p, x = list(map(int, input().split()))
val = T[p]-x
print((sum(T)-val))
| import copy
N = int(eval(input()))
T = list(map(int, input().split()))
T = [0] + T
M = int(eval(input()))
for _ in range(M):
p, x = list(map(int, input().split()))
tmp = copy.deepcopy(T)
tmp[p] = x
print((sum(tmp)))
| 9 | 11 | 192 | 229 | N = int(eval(input()))
T = list(map(int, input().split()))
T = [0] + T
M = int(eval(input()))
for _ in range(M):
p, x = list(map(int, input().split()))
val = T[p] - x
print((sum(T) - val))
| import copy
N = int(eval(input()))
T = list(map(int, input().split()))
T = [0] + T
M = int(eval(input()))
for _ in range(M):
p, x = list(map(int, input().split()))
tmp = copy.deepcopy(T)
tmp[p] = x
print((sum(tmp)))
| false | 18.181818 | [
"+import copy",
"+",
"- val = T[p] - x",
"- print((sum(T) - val))",
"+ tmp = copy.deepcopy(T)",
"+ tmp[p] = x",
"+ print((sum(tmp)))"
] | false | 0.040807 | 0.078579 | 0.519308 | [
"s174680143",
"s204229837"
] |
u366959492 | p03546 | python | s251076054 | s873470006 | 214 | 194 | 40,796 | 40,284 | Accepted | Accepted | 9.35 | h,w=list(map(int,input().split()))
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]
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=10
warshall_floyd(c)
ans=0
for i in range(h):
for j in range(w):
if a[i][j]==-1:
continue
else:
ans+=c[a[i][j]][1]
print(ans)
| h,w=list(map(int,input().split()))
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(10):
for i in range(10):
for j in range(10):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
inf=1<<32
d = [[inf for i in range(10)] for _ in range(10)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(10):
for j in range(10):
d[i][j]=c[i][j]
for i in range(10):
d[i][i] = 0 #自身のところに行くコストは0
x=warshall_floyd(d)
ans=0
for i in range(h):
for j in range(w):
if a[i][j]==-1:
continue
ans+=x[a[i][j]][1]
print(ans)
| 25 | 28 | 536 | 730 | h, w = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]
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 = 10
warshall_floyd(c)
ans = 0
for i in range(h):
for j in range(w):
if a[i][j] == -1:
continue
else:
ans += c[a[i][j]][1]
print(ans)
| h, w = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]
def warshall_floyd(d):
# d[i][j]: iからjへの最短距離
for k in range(10):
for i in range(10):
for j in range(10):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
inf = 1 << 32
d = [[inf for i in range(10)] for _ in range(10)]
# d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(10):
for j in range(10):
d[i][j] = c[i][j]
for i in range(10):
d[i][i] = 0 # 自身のところに行くコストは0
x = warshall_floyd(d)
ans = 0
for i in range(h):
for j in range(w):
if a[i][j] == -1:
continue
ans += x[a[i][j]][1]
print(ans)
| false | 10.714286 | [
"- for k in range(n):",
"- for i in range(n):",
"- for j in range(n):",
"+ for k in range(10):",
"+ for i in range(10):",
"+ for j in range(10):",
"-n = 10",
"-warshall_floyd(c)",
"+inf = 1 << 32",
"+d = [[inf for i in range(10)] for _ in range(10)]",
"+# d[u][v] : 辺uvのコスト(存在しないときはinf)",
"+for i in range(10):",
"+ for j in range(10):",
"+ d[i][j] = c[i][j]",
"+for i in range(10):",
"+ d[i][i] = 0 # 自身のところに行くコストは0",
"+x = warshall_floyd(d)",
"- else:",
"- ans += c[a[i][j]][1]",
"+ ans += x[a[i][j]][1]"
] | false | 0.041809 | 0.040092 | 1.042808 | [
"s251076054",
"s873470006"
] |
u367130284 | p03319 | python | s736939880 | s735182503 | 39 | 17 | 13,940 | 3,060 | Accepted | Accepted | 56.41 | n,k,*a=list(map(int,open(0).read().split()))
print((((n-1)-1)//(k-1)+1)) | n,k=list(map(int,input().split()));print(((~-n-1)//~-k+1)) | 2 | 1 | 65 | 50 | n, k, *a = list(map(int, open(0).read().split()))
print((((n - 1) - 1) // (k - 1) + 1))
| n, k = list(map(int, input().split()))
print(((~-n - 1) // ~-k + 1))
| false | 50 | [
"-n, k, *a = list(map(int, open(0).read().split()))",
"-print((((n - 1) - 1) // (k - 1) + 1))",
"+n, k = list(map(int, input().split()))",
"+print(((~-n - 1) // ~-k + 1))"
] | false | 0.070237 | 0.040568 | 1.73137 | [
"s736939880",
"s735182503"
] |
u745223262 | p03835 | python | s995042916 | s258399689 | 1,701 | 1,523 | 3,060 | 3,060 | Accepted | Accepted | 10.46 | inputs= list(map(int,input().split()))
k = inputs[0]
s = inputs[1]
answer = 0
for i in range(k+1):
x = i
for l in range(k+1):
y = l
z = s-x-y
if z >= 0 and z <= k :
answer += 1
print(answer) | a = list(map(int,input().split()))
k = a[0]
s = a[1]
num=0
for l in range(k+1):
for m in range(k+1):
n = s-l-m
if(n <= k and n >= 0):
num+=1
print(num) | 12 | 11 | 223 | 194 | inputs = list(map(int, input().split()))
k = inputs[0]
s = inputs[1]
answer = 0
for i in range(k + 1):
x = i
for l in range(k + 1):
y = l
z = s - x - y
if z >= 0 and z <= k:
answer += 1
print(answer)
| a = list(map(int, input().split()))
k = a[0]
s = a[1]
num = 0
for l in range(k + 1):
for m in range(k + 1):
n = s - l - m
if n <= k and n >= 0:
num += 1
print(num)
| false | 8.333333 | [
"-inputs = list(map(int, input().split()))",
"-k = inputs[0]",
"-s = inputs[1]",
"-answer = 0",
"-for i in range(k + 1):",
"- x = i",
"- for l in range(k + 1):",
"- y = l",
"- z = s - x - y",
"- if z >= 0 and z <= k:",
"- answer += 1",
"-print(answer)",
"+a = list(map(int, input().split()))",
"+k = a[0]",
"+s = a[1]",
"+num = 0",
"+for l in range(k + 1):",
"+ for m in range(k + 1):",
"+ n = s - l - m",
"+ if n <= k and n >= 0:",
"+ num += 1",
"+print(num)"
] | false | 0.046578 | 0.045495 | 1.02381 | [
"s995042916",
"s258399689"
] |
u068112689 | p03078 | python | s727181994 | s929390363 | 635 | 104 | 8,712 | 8,708 | Accepted | Accepted | 83.62 | x,y,z,k = list(map(int, 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()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
x = 0
y = 0
z = 0
cakes = []
for x, a in enumerate(A):
for y, b in enumerate(B):
for z, c in enumerate(C):
if (x+1)*(y+1)*(z+1) > k:
break
cakes.append(a+b+c)
cakes.sort(reverse=True)
for cake in cakes[:k]:
print(cake) | x,y,z,k = list(map(int, 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()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
x = 0
y = 0
z = 0
cakes = []
for x, a in enumerate(A):
if x+1 > k: break
for y, b in enumerate(B):
if (x+1)*(y+1) > k: break
for z, c in enumerate(C):
if (x+1)*(y+1)*(z+1) > k: break
cakes.append(a+b+c)
cakes.sort(reverse=True)
for cake in cakes[:k]:
print(cake) | 25 | 27 | 554 | 605 | x, y, z, k = list(map(int, 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()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
x = 0
y = 0
z = 0
cakes = []
for x, a in enumerate(A):
for y, b in enumerate(B):
for z, c in enumerate(C):
if (x + 1) * (y + 1) * (z + 1) > k:
break
cakes.append(a + b + c)
cakes.sort(reverse=True)
for cake in cakes[:k]:
print(cake)
| x, y, z, k = list(map(int, 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()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
x = 0
y = 0
z = 0
cakes = []
for x, a in enumerate(A):
if x + 1 > k:
break
for y, b in enumerate(B):
if (x + 1) * (y + 1) > k:
break
for z, c in enumerate(C):
if (x + 1) * (y + 1) * (z + 1) > k:
break
cakes.append(a + b + c)
cakes.sort(reverse=True)
for cake in cakes[:k]:
print(cake)
| false | 7.407407 | [
"+ if x + 1 > k:",
"+ break",
"+ if (x + 1) * (y + 1) > k:",
"+ break"
] | false | 0.046078 | 0.039302 | 1.172402 | [
"s727181994",
"s929390363"
] |
u548624367 | p03260 | python | s168613947 | s552683517 | 19 | 17 | 3,316 | 2,940 | Accepted | Accepted | 10.53 | a,b=list(map(int,input().split()))
print(("Yes" if (a*b)%2 else "No"))
| print((["No","Yes"][(lambda a:(a[0]*a[1])%2)(list(map(int,input().split())))])) | 2 | 1 | 64 | 77 | a, b = list(map(int, input().split()))
print(("Yes" if (a * b) % 2 else "No"))
| print((["No", "Yes"][(lambda a: (a[0] * a[1]) % 2)(list(map(int, input().split())))]))
| false | 50 | [
"-a, b = list(map(int, input().split()))",
"-print((\"Yes\" if (a * b) % 2 else \"No\"))",
"+print(([\"No\", \"Yes\"][(lambda a: (a[0] * a[1]) % 2)(list(map(int, input().split())))]))"
] | false | 0.073867 | 0.076224 | 0.96908 | [
"s168613947",
"s552683517"
] |
u762420987 | p02755 | python | s707904856 | s734321316 | 49 | 20 | 3,060 | 2,940 | Accepted | Accepted | 59.18 | A, B = list(map(int, input().split()))
for i in range(100000):
if int(i*0.08)==A and int(i*0.1)==B:
print(i)
break
else:
print((-1)) | A, B = list(map(int, input().split()))
for i in range(10**4+100):
if int(i*0.08)==A and int(i*0.1)==B:
print(i)
break
else:
print((-1))
| 7 | 7 | 154 | 158 | A, B = list(map(int, input().split()))
for i in range(100000):
if int(i * 0.08) == A and int(i * 0.1) == B:
print(i)
break
else:
print((-1))
| A, B = list(map(int, input().split()))
for i in range(10**4 + 100):
if int(i * 0.08) == A and int(i * 0.1) == B:
print(i)
break
else:
print((-1))
| false | 0 | [
"-for i in range(100000):",
"+for i in range(10**4 + 100):"
] | false | 0.045746 | 0.035624 | 1.284157 | [
"s707904856",
"s734321316"
] |
u186426563 | p03495 | python | s781158126 | s284718585 | 120 | 102 | 32,288 | 35,712 | Accepted | Accepted | 15 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = {}
for i in a:
if i in b:
b[i] += 1
else:
b[i] = 1
b = sorted(b.values())
print((sum(b[:-k]))) | n, k = list(map(int, input().split()))
b = {}
for i in input().split():
if i in b:
b[i] += 1
else:
b[i] = 1
b = sorted(b.values())
print((sum(b[:-k]))) | 10 | 9 | 198 | 175 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = {}
for i in a:
if i in b:
b[i] += 1
else:
b[i] = 1
b = sorted(b.values())
print((sum(b[:-k])))
| n, k = list(map(int, input().split()))
b = {}
for i in input().split():
if i in b:
b[i] += 1
else:
b[i] = 1
b = sorted(b.values())
print((sum(b[:-k])))
| false | 10 | [
"-a = list(map(int, input().split()))",
"-for i in a:",
"+for i in input().split():"
] | false | 0.039104 | 0.040696 | 0.96087 | [
"s781158126",
"s284718585"
] |
u555649269 | p02690 | python | s507998704 | s462026273 | 33 | 25 | 9,188 | 9,048 | Accepted | Accepted | 24.24 | l=[]
for i in range(0,1001):
l.append(i**5)
n=int(eval(input()))
for i in range(0,1001):
if((l[i]-n) in l):
print((i,l.index(l[i]-n)))
break
elif((n-l[i]) in l):
print((i,-l.index(-l[i]+n)))
break
| l=[]
for i in range(0,120):
l.append(i**5)
n=int(eval(input()))
for i in range(0,120):
if((l[i]-n) in l):
print((i,l.index(l[i]-n)))
break
elif((n-l[i]) in l):
print((i,-l.index(-l[i]+n)))
break
| 14 | 14 | 258 | 256 | l = []
for i in range(0, 1001):
l.append(i**5)
n = int(eval(input()))
for i in range(0, 1001):
if (l[i] - n) in l:
print((i, l.index(l[i] - n)))
break
elif (n - l[i]) in l:
print((i, -l.index(-l[i] + n)))
break
| l = []
for i in range(0, 120):
l.append(i**5)
n = int(eval(input()))
for i in range(0, 120):
if (l[i] - n) in l:
print((i, l.index(l[i] - n)))
break
elif (n - l[i]) in l:
print((i, -l.index(-l[i] + n)))
break
| false | 0 | [
"-for i in range(0, 1001):",
"+for i in range(0, 120):",
"-for i in range(0, 1001):",
"+for i in range(0, 120):"
] | false | 0.037603 | 0.039461 | 0.952915 | [
"s507998704",
"s462026273"
] |
u499381410 | p02868 | python | s496487151 | s808747348 | 1,068 | 614 | 91,868 | 80,592 | Accepted | Accepted | 42.51 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
class SegmentTree:
def __init__(self, n, ide_ele, op, init_val=[]):
self.n = 2 ** (n - 1).bit_length()
self.ide_ele = ide_ele
self.op = op
self.seg = [ide_ele] * 2 * self.n
if init_val:
for i in range(n):
self.seg[i + self.n - 1] = init_val[i]
for i in range(self.n - 2, -1, -1):
self.seg[i] = self.op(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.n - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.op(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
# qは含まない
if q <= p:
return self.ide_ele
p += self.n - 1
q += self.n - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.op(res, self.seg[p])
if q & 1 == 1:
res = self.op(res, self.seg[q])
p = p // 2
q = (q - 2) // 2
if p == q:
res = self.op(res, self.seg[p])
else:
res = self.op(self.seg[p], self.op(res, self.seg[q]))
return res
def display(self):
return self.seg[self.n - 1: -1]
def query_point(self, p):
return self.seg[p + self.n - 1]
n, m = LI()
lrc_list = sorted(LIR(m))
st = SegmentTree(n, INF, min)
st.update(0, 0)
for l, r, c in lrc_list:
l_dist = st.query(l - 1, r)
st.update(r - 1, min(st.query_point(r - 1), l_dist + c))
# dis = st.display()
if st.query_point(n - 1) == INF:
print((-1))
else:
print((st.query_point(n - 1)))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, m = LI()
G = [[] for _ in range(n)]
for _ in range(m):
l, r, c = LI()
G[l - 1] += [(r - 1, c)]
for i in range(n - 1):
G[i + 1] += [(i, 0)]
def dijkstra(G, s=0):
hq = [(0, s)]
dist = [INF] * n
dist[s] = 0
checked = [0] * n
while hq:
min_dist, u = heappop(hq)
if checked[u]:
continue
checked[u] = 1
for v, c in G[u]:
if checked[v]:
continue
elif dist[u] + c < dist[v]:
dist[v] = dist[u] + c
heappush(hq, (dist[u] + c, v))
return dist
ans = dijkstra(G)[-1]
if ans == INF:
print((-1))
else:
print(ans)
| 91 | 64 | 2,721 | 1,723 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10**18
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
class SegmentTree:
def __init__(self, n, ide_ele, op, init_val=[]):
self.n = 2 ** (n - 1).bit_length()
self.ide_ele = ide_ele
self.op = op
self.seg = [ide_ele] * 2 * self.n
if init_val:
for i in range(n):
self.seg[i + self.n - 1] = init_val[i]
for i in range(self.n - 2, -1, -1):
self.seg[i] = self.op(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.n - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.op(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
# qは含まない
if q <= p:
return self.ide_ele
p += self.n - 1
q += self.n - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.op(res, self.seg[p])
if q & 1 == 1:
res = self.op(res, self.seg[q])
p = p // 2
q = (q - 2) // 2
if p == q:
res = self.op(res, self.seg[p])
else:
res = self.op(self.seg[p], self.op(res, self.seg[q]))
return res
def display(self):
return self.seg[self.n - 1 : -1]
def query_point(self, p):
return self.seg[p + self.n - 1]
n, m = LI()
lrc_list = sorted(LIR(m))
st = SegmentTree(n, INF, min)
st.update(0, 0)
for l, r, c in lrc_list:
l_dist = st.query(l - 1, r)
st.update(r - 1, min(st.query_point(r - 1), l_dist + c))
# dis = st.display()
if st.query_point(n - 1) == INF:
print((-1))
else:
print((st.query_point(n - 1)))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, m = LI()
G = [[] for _ in range(n)]
for _ in range(m):
l, r, c = LI()
G[l - 1] += [(r - 1, c)]
for i in range(n - 1):
G[i + 1] += [(i, 0)]
def dijkstra(G, s=0):
hq = [(0, s)]
dist = [INF] * n
dist[s] = 0
checked = [0] * n
while hq:
min_dist, u = heappop(hq)
if checked[u]:
continue
checked[u] = 1
for v, c in G[u]:
if checked[v]:
continue
elif dist[u] + c < dist[v]:
dist[v] = dist[u] + c
heappush(hq, (dist[u] + c, v))
return dist
ans = dijkstra(G)[-1]
if ans == INF:
print((-1))
else:
print(ans)
| false | 29.67033 | [
"+from operator import mul",
"-INF = 10**18",
"+INF = 10**20",
"-mod = 998244353",
"+mod = 1000000007",
"+n, m = LI()",
"+G = [[] for _ in range(n)]",
"+for _ in range(m):",
"+ l, r, c = LI()",
"+ G[l - 1] += [(r - 1, c)]",
"+for i in range(n - 1):",
"+ G[i + 1] += [(i, 0)]",
"-class SegmentTree:",
"- def __init__(self, n, ide_ele, op, init_val=[]):",
"- self.n = 2 ** (n - 1).bit_length()",
"- self.ide_ele = ide_ele",
"- self.op = op",
"- self.seg = [ide_ele] * 2 * self.n",
"- if init_val:",
"- for i in range(n):",
"- self.seg[i + self.n - 1] = init_val[i]",
"- for i in range(self.n - 2, -1, -1):",
"- self.seg[i] = self.op(self.seg[2 * i + 1], self.seg[2 * i + 2])",
"-",
"- def update(self, k, x):",
"- k += self.n - 1",
"- self.seg[k] = x",
"- while k:",
"- k = (k - 1) // 2",
"- self.seg[k] = self.op(self.seg[k * 2 + 1], self.seg[k * 2 + 2])",
"-",
"- def query(self, p, q):",
"- # qは含まない",
"- if q <= p:",
"- return self.ide_ele",
"- p += self.n - 1",
"- q += self.n - 2",
"- res = self.ide_ele",
"- while q - p > 1:",
"- if p & 1 == 0:",
"- res = self.op(res, self.seg[p])",
"- if q & 1 == 1:",
"- res = self.op(res, self.seg[q])",
"- p = p // 2",
"- q = (q - 2) // 2",
"- if p == q:",
"- res = self.op(res, self.seg[p])",
"- else:",
"- res = self.op(self.seg[p], self.op(res, self.seg[q]))",
"- return res",
"-",
"- def display(self):",
"- return self.seg[self.n - 1 : -1]",
"-",
"- def query_point(self, p):",
"- return self.seg[p + self.n - 1]",
"+def dijkstra(G, s=0):",
"+ hq = [(0, s)]",
"+ dist = [INF] * n",
"+ dist[s] = 0",
"+ checked = [0] * n",
"+ while hq:",
"+ min_dist, u = heappop(hq)",
"+ if checked[u]:",
"+ continue",
"+ checked[u] = 1",
"+ for v, c in G[u]:",
"+ if checked[v]:",
"+ continue",
"+ elif dist[u] + c < dist[v]:",
"+ dist[v] = dist[u] + c",
"+ heappush(hq, (dist[u] + c, v))",
"+ return dist",
"-n, m = LI()",
"-lrc_list = sorted(LIR(m))",
"-st = SegmentTree(n, INF, min)",
"-st.update(0, 0)",
"-for l, r, c in lrc_list:",
"- l_dist = st.query(l - 1, r)",
"- st.update(r - 1, min(st.query_point(r - 1), l_dist + c))",
"- # dis = st.display()",
"-if st.query_point(n - 1) == INF:",
"+ans = dijkstra(G)[-1]",
"+if ans == INF:",
"- print((st.query_point(n - 1)))",
"+ print(ans)"
] | false | 0.08361 | 0.095578 | 0.874778 | [
"s496487151",
"s808747348"
] |
u508405635 | p03308 | python | s040913587 | s447376048 | 21 | 17 | 3,060 | 2,940 | Accepted | Accepted | 19.05 | N = int(eval(input()))
L = list(map(int, input().split()))
diff = 0
maxNum = 0
maxDiffArray = []
for i in range(len(L)):
diffArray = []
for j in range(len(L)):
if i != j:
diff = abs(L[i] - L[j])
diffArray.append(diff)
maxDiffArray.append(max(diffArray))
print((max(maxDiffArray)))
| N = int(eval(input()))
L = list(map(int, input().split()))
# diff = 0
# maxNum = 0
# maxDiffArray = []
# for i in range(len(L)):
# diffArray = []
# for j in range(len(L)):
# if i != j:
# diff = abs(L[i] - L[j])
# diffArray.append(diff)
# maxDiffArray.append(max(diffArray))
# print(max(maxDiffArray))
# 別解:数列の最大値と最小値の差が要素間の差の最大値となることを利用
print((max(L) - min(L)))
| 14 | 17 | 331 | 416 | N = int(eval(input()))
L = list(map(int, input().split()))
diff = 0
maxNum = 0
maxDiffArray = []
for i in range(len(L)):
diffArray = []
for j in range(len(L)):
if i != j:
diff = abs(L[i] - L[j])
diffArray.append(diff)
maxDiffArray.append(max(diffArray))
print((max(maxDiffArray)))
| N = int(eval(input()))
L = list(map(int, input().split()))
# diff = 0
# maxNum = 0
# maxDiffArray = []
# for i in range(len(L)):
# diffArray = []
# for j in range(len(L)):
# if i != j:
# diff = abs(L[i] - L[j])
# diffArray.append(diff)
# maxDiffArray.append(max(diffArray))
# print(max(maxDiffArray))
# 別解:数列の最大値と最小値の差が要素間の差の最大値となることを利用
print((max(L) - min(L)))
| false | 17.647059 | [
"-diff = 0",
"-maxNum = 0",
"-maxDiffArray = []",
"-for i in range(len(L)):",
"- diffArray = []",
"- for j in range(len(L)):",
"- if i != j:",
"- diff = abs(L[i] - L[j])",
"- diffArray.append(diff)",
"- maxDiffArray.append(max(diffArray))",
"-print((max(maxDiffArray)))",
"+# diff = 0",
"+# maxNum = 0",
"+# maxDiffArray = []",
"+# for i in range(len(L)):",
"+# diffArray = []",
"+# for j in range(len(L)):",
"+# if i != j:",
"+# diff = abs(L[i] - L[j])",
"+# diffArray.append(diff)",
"+# maxDiffArray.append(max(diffArray))",
"+# print(max(maxDiffArray))",
"+# 別解:数列の最大値と最小値の差が要素間の差の最大値となることを利用",
"+print((max(L) - min(L)))"
] | false | 0.042139 | 0.045059 | 0.935201 | [
"s040913587",
"s447376048"
] |
u507456172 | p03611 | python | s930253002 | s877560328 | 105 | 89 | 20,628 | 20,604 | Accepted | Accepted | 15.24 | N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
A.sort()
a=0
b=0
c=1
for i in range(N-1):
if A[i] == A[i+1]:
a += 1
b += 1
c += 1
elif A[i]+1 == A[i+1]:
if ans < a:
ans = a
a = b
a += 1
b = c
b += 1
c = 1
elif A[i]+2 == A[i+1]:
if ans < a:
ans = a
if ans < b:
ans = b
a = c
a += 1
b = 1
c = 1
else:
if ans < a:
ans = a
if ans < b:
ans = b
if ans < c:
ans = c
a = 1
b = 1
c = 1
if ans < a:
ans = a
if ans < b:
ans = b
if ans < c:
ans = c
print(ans) | N = int(eval(input()))
A = list(map(int,input().split()))
nums = [0]*100000
ans_list=[]
for i in range(N):
nums[A[i]] += 1
for j in range(1,99999):
ans_list.append(nums[j-1]+nums[j]+nums[j+1])
print((max(ans_list))) | 48 | 12 | 654 | 225 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
A.sort()
a = 0
b = 0
c = 1
for i in range(N - 1):
if A[i] == A[i + 1]:
a += 1
b += 1
c += 1
elif A[i] + 1 == A[i + 1]:
if ans < a:
ans = a
a = b
a += 1
b = c
b += 1
c = 1
elif A[i] + 2 == A[i + 1]:
if ans < a:
ans = a
if ans < b:
ans = b
a = c
a += 1
b = 1
c = 1
else:
if ans < a:
ans = a
if ans < b:
ans = b
if ans < c:
ans = c
a = 1
b = 1
c = 1
if ans < a:
ans = a
if ans < b:
ans = b
if ans < c:
ans = c
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
nums = [0] * 100000
ans_list = []
for i in range(N):
nums[A[i]] += 1
for j in range(1, 99999):
ans_list.append(nums[j - 1] + nums[j] + nums[j + 1])
print((max(ans_list)))
| false | 75 | [
"-ans = 0",
"-A.sort()",
"-a = 0",
"-b = 0",
"-c = 1",
"-for i in range(N - 1):",
"- if A[i] == A[i + 1]:",
"- a += 1",
"- b += 1",
"- c += 1",
"- elif A[i] + 1 == A[i + 1]:",
"- if ans < a:",
"- ans = a",
"- a = b",
"- a += 1",
"- b = c",
"- b += 1",
"- c = 1",
"- elif A[i] + 2 == A[i + 1]:",
"- if ans < a:",
"- ans = a",
"- if ans < b:",
"- ans = b",
"- a = c",
"- a += 1",
"- b = 1",
"- c = 1",
"- else:",
"- if ans < a:",
"- ans = a",
"- if ans < b:",
"- ans = b",
"- if ans < c:",
"- ans = c",
"- a = 1",
"- b = 1",
"- c = 1",
"-if ans < a:",
"- ans = a",
"-if ans < b:",
"- ans = b",
"-if ans < c:",
"- ans = c",
"-print(ans)",
"+nums = [0] * 100000",
"+ans_list = []",
"+for i in range(N):",
"+ nums[A[i]] += 1",
"+for j in range(1, 99999):",
"+ ans_list.append(nums[j - 1] + nums[j] + nums[j + 1])",
"+print((max(ans_list)))"
] | false | 0.037345 | 0.104546 | 0.357212 | [
"s930253002",
"s877560328"
] |
u359358631 | p02861 | python | s750500007 | s592910555 | 282 | 111 | 11,964 | 74,812 | Accepted | Accepted | 60.64 | import itertools
import math
import statistics
def main():
N = int(eval(input()))
city_lst = [list(map(int, input().split())) for _ in range(N)]
d_lst = [0] * math.factorial(N)
for i, route in enumerate(itertools.permutations(list(range(N)))):
for j in range(len(route) - 1):
d = math.sqrt((city_lst[route[j + 1]][0] - city_lst[route[j]][0])
** 2 + (city_lst[route[j + 1]][1] - city_lst[route[j]][1]) ** 2)
d_lst[i] += d
print(f"{statistics.mean(d_lst):.10f}")
if __name__ == "__main__":
main()
| from itertools import permutations
from math import factorial
def main():
n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for p in permutations(list(range(n)), n):
dist = 0
for i in range(len(p) - 1):
dist += (abs(xy[p[i]][0] - xy[p[i + 1]][0]) ** 2 +
abs(xy[p[i]][1] - xy[p[i + 1]][1]) ** 2) ** 0.5
ans += dist
ans /= factorial(n)
print(f"{ans:.12f}")
if __name__ == "__main__":
main()
| 21 | 23 | 591 | 529 | import itertools
import math
import statistics
def main():
N = int(eval(input()))
city_lst = [list(map(int, input().split())) for _ in range(N)]
d_lst = [0] * math.factorial(N)
for i, route in enumerate(itertools.permutations(list(range(N)))):
for j in range(len(route) - 1):
d = math.sqrt(
(city_lst[route[j + 1]][0] - city_lst[route[j]][0]) ** 2
+ (city_lst[route[j + 1]][1] - city_lst[route[j]][1]) ** 2
)
d_lst[i] += d
print(f"{statistics.mean(d_lst):.10f}")
if __name__ == "__main__":
main()
| from itertools import permutations
from math import factorial
def main():
n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for p in permutations(list(range(n)), n):
dist = 0
for i in range(len(p) - 1):
dist += (
abs(xy[p[i]][0] - xy[p[i + 1]][0]) ** 2
+ abs(xy[p[i]][1] - xy[p[i + 1]][1]) ** 2
) ** 0.5
ans += dist
ans /= factorial(n)
print(f"{ans:.12f}")
if __name__ == "__main__":
main()
| false | 8.695652 | [
"-import itertools",
"-import math",
"-import statistics",
"+from itertools import permutations",
"+from math import factorial",
"- N = int(eval(input()))",
"- city_lst = [list(map(int, input().split())) for _ in range(N)]",
"- d_lst = [0] * math.factorial(N)",
"- for i, route in enumerate(itertools.permutations(list(range(N)))):",
"- for j in range(len(route) - 1):",
"- d = math.sqrt(",
"- (city_lst[route[j + 1]][0] - city_lst[route[j]][0]) ** 2",
"- + (city_lst[route[j + 1]][1] - city_lst[route[j]][1]) ** 2",
"- )",
"- d_lst[i] += d",
"- print(f\"{statistics.mean(d_lst):.10f}\")",
"+ n = int(eval(input()))",
"+ xy = [list(map(int, input().split())) for _ in range(n)]",
"+ ans = 0",
"+ for p in permutations(list(range(n)), n):",
"+ dist = 0",
"+ for i in range(len(p) - 1):",
"+ dist += (",
"+ abs(xy[p[i]][0] - xy[p[i + 1]][0]) ** 2",
"+ + abs(xy[p[i]][1] - xy[p[i + 1]][1]) ** 2",
"+ ) ** 0.5",
"+ ans += dist",
"+ ans /= factorial(n)",
"+ print(f\"{ans:.12f}\")"
] | false | 0.050992 | 0.056352 | 0.904895 | [
"s750500007",
"s592910555"
] |
u226155577 | p03677 | python | s712451768 | s652146175 | 654 | 243 | 18,500 | 17,356 | Accepted | Accepted | 62.84 | n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
S = 0
for i in range(n-1):
S += (m + A[i+1] - A[i]) % m
T = 2*m
D = [0]*(T+10)
data = [0]*(T+1)
def get(i):
s = 0
while i:
s += data[i]
i -= i & -i
return s
def add(i, x):
while i <= T:
data[i] += x
i += i & -i
for i in range(n-1):
x = A[i]; y = A[i+1]
if y < x:
y += m
k = y-x
if k > 1:
D[x+2] += 1
D[y+1] -= k
D[y+2] += k-1
for i in range(1, 2*m+5):
D[i] += D[i-1]
add(i, D[i])
res = min(S - (get(a) + get(a+m)) for a in A)
print(res)
| n,m,*A=list(map(int,open(0).read().split()))
D=[0]*(2*m+2)
cur = 0
S = 0
for a,b in zip(A,A[1:]):
S += (b-a)%m
b += m*(b<a)
k = b-a
if k>1:
D[a+2] += 1
D[b+1] -= k
D[b+2] += k-1
for i in range(1,2*m+2):
D[i]+=D[i-1]
for i in range(1,2*m+2):
D[i]+=D[i-1]
print((S-max(D[a]+D[a+m]for a in A)))
| 34 | 17 | 653 | 348 | n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
S = 0
for i in range(n - 1):
S += (m + A[i + 1] - A[i]) % m
T = 2 * m
D = [0] * (T + 10)
data = [0] * (T + 1)
def get(i):
s = 0
while i:
s += data[i]
i -= i & -i
return s
def add(i, x):
while i <= T:
data[i] += x
i += i & -i
for i in range(n - 1):
x = A[i]
y = A[i + 1]
if y < x:
y += m
k = y - x
if k > 1:
D[x + 2] += 1
D[y + 1] -= k
D[y + 2] += k - 1
for i in range(1, 2 * m + 5):
D[i] += D[i - 1]
add(i, D[i])
res = min(S - (get(a) + get(a + m)) for a in A)
print(res)
| n, m, *A = list(map(int, open(0).read().split()))
D = [0] * (2 * m + 2)
cur = 0
S = 0
for a, b in zip(A, A[1:]):
S += (b - a) % m
b += m * (b < a)
k = b - a
if k > 1:
D[a + 2] += 1
D[b + 1] -= k
D[b + 2] += k - 1
for i in range(1, 2 * m + 2):
D[i] += D[i - 1]
for i in range(1, 2 * m + 2):
D[i] += D[i - 1]
print((S - max(D[a] + D[a + m] for a in A)))
| false | 50 | [
"-n, m = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"+n, m, *A = list(map(int, open(0).read().split()))",
"+D = [0] * (2 * m + 2)",
"+cur = 0",
"-for i in range(n - 1):",
"- S += (m + A[i + 1] - A[i]) % m",
"-T = 2 * m",
"-D = [0] * (T + 10)",
"-data = [0] * (T + 1)",
"-",
"-",
"-def get(i):",
"- s = 0",
"- while i:",
"- s += data[i]",
"- i -= i & -i",
"- return s",
"-",
"-",
"-def add(i, x):",
"- while i <= T:",
"- data[i] += x",
"- i += i & -i",
"-",
"-",
"-for i in range(n - 1):",
"- x = A[i]",
"- y = A[i + 1]",
"- if y < x:",
"- y += m",
"- k = y - x",
"+for a, b in zip(A, A[1:]):",
"+ S += (b - a) % m",
"+ b += m * (b < a)",
"+ k = b - a",
"- D[x + 2] += 1",
"- D[y + 1] -= k",
"- D[y + 2] += k - 1",
"-for i in range(1, 2 * m + 5):",
"+ D[a + 2] += 1",
"+ D[b + 1] -= k",
"+ D[b + 2] += k - 1",
"+for i in range(1, 2 * m + 2):",
"- add(i, D[i])",
"-res = min(S - (get(a) + get(a + m)) for a in A)",
"-print(res)",
"+for i in range(1, 2 * m + 2):",
"+ D[i] += D[i - 1]",
"+print((S - max(D[a] + D[a + m] for a in A)))"
] | false | 0.007251 | 0.036529 | 0.198488 | [
"s712451768",
"s652146175"
] |
u376420711 | p03681 | python | s889291461 | s272857154 | 703 | 32 | 5,184 | 3,060 | Accepted | Accepted | 95.45 | from math import factorial
n, m = list(map(int, input().split()))
if n == m:
print((2 * factorial(n)**2 % 1000000007))
elif abs(n - m) < 2:
print((factorial(n) * factorial(m) % 1000000007))
else:
print((0))
| n, m = sorted(map(int, input().split()))
mod = 10**9 + 7
def factorial(n):
ans = 1
for i in range(1, n + 1):
ans *= i
ans %= mod
return ans
if n == m:
ans = factorial(n)
print((ans ** 2 * 2 % mod))
elif m - n == 1:
ans = factorial(n)
print((ans ** 2 * m % mod))
else:
print((0))
| 9 | 18 | 216 | 340 | from math import factorial
n, m = list(map(int, input().split()))
if n == m:
print((2 * factorial(n) ** 2 % 1000000007))
elif abs(n - m) < 2:
print((factorial(n) * factorial(m) % 1000000007))
else:
print((0))
| n, m = sorted(map(int, input().split()))
mod = 10**9 + 7
def factorial(n):
ans = 1
for i in range(1, n + 1):
ans *= i
ans %= mod
return ans
if n == m:
ans = factorial(n)
print((ans**2 * 2 % mod))
elif m - n == 1:
ans = factorial(n)
print((ans**2 * m % mod))
else:
print((0))
| false | 50 | [
"-from math import factorial",
"+n, m = sorted(map(int, input().split()))",
"+mod = 10**9 + 7",
"-n, m = list(map(int, input().split()))",
"+",
"+def factorial(n):",
"+ ans = 1",
"+ for i in range(1, n + 1):",
"+ ans *= i",
"+ ans %= mod",
"+ return ans",
"+",
"+",
"- print((2 * factorial(n) ** 2 % 1000000007))",
"-elif abs(n - m) < 2:",
"- print((factorial(n) * factorial(m) % 1000000007))",
"+ ans = factorial(n)",
"+ print((ans**2 * 2 % mod))",
"+elif m - n == 1:",
"+ ans = factorial(n)",
"+ print((ans**2 * m % mod))"
] | false | 0.083636 | 0.039362 | 2.124769 | [
"s889291461",
"s272857154"
] |
u562016607 | p03098 | python | s628727171 | s023823663 | 1,003 | 851 | 38,728 | 42,684 | Accepted | Accepted | 15.15 | N,K=list(map(int,input().split()));p=[int(i)-1 for i in input().split()];q=[int(i)-1 for i in input().split()]
def I(s):
r=[0 for i in range(N)]
for i in range(N):r[s[i]]=i
return r
def T(s,t):
r=[0 for i in range(N)]
for i in range(N):r[i]=s[t[i]]
return r
m=[[0 for i in range(N)] for i in range(6)];A=T(T(T(q,I(p)),I(q)),p);X=(K-1)//6
for i in range(N):m[0][i]=p[i];m[1][i]=q[i]
for i in range(2,6):m[i]=T(m[i-1],I(m[i-2]))
def E(s,k):
if k==0:
return [i for i in range(N)]
elif k==1:
return s
elif k%2==0:
return E(T(s,s),k//2)
else:
return T(E(T(s,s),k//2),s)
t=E(A,X);a=T(T(t,m[(K-1)%6]),I(t));print((" ".join([str(i+1) for i in a]))) | N,K=list(map(int,input().split()));p=[int(i)-1 for i in input().split()];q=[int(i)-1 for i in input().split()]
def I(s):
r=[0]*N
for i in range(N):r[s[i]]=i
return r
def T(s,t):return [s[t[i]] for i in range(N)]
m=[[0 for i in [0]*N] for i in [0]*6]
for i in range(N):m[0][i]=p[i];m[1][i]=q[i]
for i in range(4):m[i+2]=T(m[i+1],I(m[i]))
def E(s,k):
if k%2==0:
return E(T(s,s),k//2) if k!=0 else list(range(N))
else:
return T(E(T(s,s),k//2),s)
t=E(T(T(T(q,I(p)),I(q)),p),~-K//6);print((" ".join([str(i+1) for i in T(T(t,m[~-K%6]),I(t))]))) | 22 | 15 | 671 | 553 | N, K = list(map(int, input().split()))
p = [int(i) - 1 for i in input().split()]
q = [int(i) - 1 for i in input().split()]
def I(s):
r = [0 for i in range(N)]
for i in range(N):
r[s[i]] = i
return r
def T(s, t):
r = [0 for i in range(N)]
for i in range(N):
r[i] = s[t[i]]
return r
m = [[0 for i in range(N)] for i in range(6)]
A = T(T(T(q, I(p)), I(q)), p)
X = (K - 1) // 6
for i in range(N):
m[0][i] = p[i]
m[1][i] = q[i]
for i in range(2, 6):
m[i] = T(m[i - 1], I(m[i - 2]))
def E(s, k):
if k == 0:
return [i for i in range(N)]
elif k == 1:
return s
elif k % 2 == 0:
return E(T(s, s), k // 2)
else:
return T(E(T(s, s), k // 2), s)
t = E(A, X)
a = T(T(t, m[(K - 1) % 6]), I(t))
print((" ".join([str(i + 1) for i in a])))
| N, K = list(map(int, input().split()))
p = [int(i) - 1 for i in input().split()]
q = [int(i) - 1 for i in input().split()]
def I(s):
r = [0] * N
for i in range(N):
r[s[i]] = i
return r
def T(s, t):
return [s[t[i]] for i in range(N)]
m = [[0 for i in [0] * N] for i in [0] * 6]
for i in range(N):
m[0][i] = p[i]
m[1][i] = q[i]
for i in range(4):
m[i + 2] = T(m[i + 1], I(m[i]))
def E(s, k):
if k % 2 == 0:
return E(T(s, s), k // 2) if k != 0 else list(range(N))
else:
return T(E(T(s, s), k // 2), s)
t = E(T(T(T(q, I(p)), I(q)), p), ~-K // 6)
print((" ".join([str(i + 1) for i in T(T(t, m[~-K % 6]), I(t))])))
| false | 31.818182 | [
"- r = [0 for i in range(N)]",
"+ r = [0] * N",
"- r = [0 for i in range(N)]",
"- for i in range(N):",
"- r[i] = s[t[i]]",
"- return r",
"+ return [s[t[i]] for i in range(N)]",
"-m = [[0 for i in range(N)] for i in range(6)]",
"-A = T(T(T(q, I(p)), I(q)), p)",
"-X = (K - 1) // 6",
"+m = [[0 for i in [0] * N] for i in [0] * 6]",
"-for i in range(2, 6):",
"- m[i] = T(m[i - 1], I(m[i - 2]))",
"+for i in range(4):",
"+ m[i + 2] = T(m[i + 1], I(m[i]))",
"- if k == 0:",
"- return [i for i in range(N)]",
"- elif k == 1:",
"- return s",
"- elif k % 2 == 0:",
"- return E(T(s, s), k // 2)",
"+ if k % 2 == 0:",
"+ return E(T(s, s), k // 2) if k != 0 else list(range(N))",
"-t = E(A, X)",
"-a = T(T(t, m[(K - 1) % 6]), I(t))",
"-print((\" \".join([str(i + 1) for i in a])))",
"+t = E(T(T(T(q, I(p)), I(q)), p), ~-K // 6)",
"+print((\" \".join([str(i + 1) for i in T(T(t, m[~-K % 6]), I(t))])))"
] | false | 0.036904 | 0.043077 | 0.85671 | [
"s628727171",
"s023823663"
] |
u753803401 | p03331 | python | s017858153 | s744027273 | 408 | 225 | 3,060 | 41,452 | Accepted | Accepted | 44.85 | def slove():
import sys
input = sys.stdin.readline
n = int(input().rstrip('\n'))
m_t = 10 ** 10
for i in range(1, n):
a = list(map(int, list(str(i))))
b = list(map(int, list(str(n-i))))
m_t = min(m_t, sum(a) + sum(b))
print(m_t)
if __name__ == '__main__':
slove()
| def slove():
import sys
input = sys.stdin.readline
n = int(input().rstrip('\n'))
mt = 10 ** 20
for i in range(1, n // 2 + 1):
sa = str(i)
sb = str(n - i)
t = 0
for j in range(len(sa)):
t += int(sa[j])
for j in range(len(sb)):
t += int(sb[j])
mt = min(mt, t)
print(mt)
if __name__ == '__main__':
slove()
| 14 | 19 | 331 | 423 | def slove():
import sys
input = sys.stdin.readline
n = int(input().rstrip("\n"))
m_t = 10**10
for i in range(1, n):
a = list(map(int, list(str(i))))
b = list(map(int, list(str(n - i))))
m_t = min(m_t, sum(a) + sum(b))
print(m_t)
if __name__ == "__main__":
slove()
| def slove():
import sys
input = sys.stdin.readline
n = int(input().rstrip("\n"))
mt = 10**20
for i in range(1, n // 2 + 1):
sa = str(i)
sb = str(n - i)
t = 0
for j in range(len(sa)):
t += int(sa[j])
for j in range(len(sb)):
t += int(sb[j])
mt = min(mt, t)
print(mt)
if __name__ == "__main__":
slove()
| false | 26.315789 | [
"- m_t = 10**10",
"- for i in range(1, n):",
"- a = list(map(int, list(str(i))))",
"- b = list(map(int, list(str(n - i))))",
"- m_t = min(m_t, sum(a) + sum(b))",
"- print(m_t)",
"+ mt = 10**20",
"+ for i in range(1, n // 2 + 1):",
"+ sa = str(i)",
"+ sb = str(n - i)",
"+ t = 0",
"+ for j in range(len(sa)):",
"+ t += int(sa[j])",
"+ for j in range(len(sb)):",
"+ t += int(sb[j])",
"+ mt = min(mt, t)",
"+ print(mt)"
] | false | 0.131227 | 0.170227 | 0.770894 | [
"s017858153",
"s744027273"
] |
u867826040 | p02619 | python | s824536373 | s099770329 | 244 | 35 | 9,660 | 9,448 | Accepted | Accepted | 85.66 | import bisect
import random
import sys
input = sys.stdin.readline
class score:
def __init__(self, t):
self.t = t
def first_score(self):
last = [0]*26
score = 0
for i,ti in enumerate(self.t):
score += S[i][ti - 1]
last[ti-1] = i + 1
for j in range(26):
score -= C[j] * ((i+1) - last[j])
self.score = score
return score
D = int(eval(input()))
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
#T = [int(input()) for i in range(D)]
T = []
for i in range(D):
T.append(int(eval(input())))
s = score(T)
print((s.first_score())) | from bisect import bisect_left
class score:
def __init__(self,t) -> None:
self.t = t
score = 0
last = [[] for i in range(26)]
for i,ti in enumerate(t):
score += s[i][ti-1]
last[ti-1].append(i+1)
for tj in range(26):
if last[tj-1] == []:
score -= c[tj-1]*(i+1)
else:
#print(last)
score -= c[tj-1]*((i+1)-last[tj-1][-1])
print(score)
self.score = score
def a__init__(self,t) -> None:
score = 0
last = [[] for i in range(26)]
for i,ti in enumerate(t):
# 開催分を加算
score += s[i][ti-1]
# 減らす
if last[ti-1] == []:
score -= c[i]*i+1
else:
score -= c[i]*((i+1)-last[ti-1][-1])
last[ti-1].append(i+1)
print(score)
for i in range(26):
if last[i] == []:
score -= c[i]*D
else:
score -= c[i]*(D-last[i][-1])
self.score = score
self.t = t
D = int(eval(input()))
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
t = [int(eval(input())) for i in range(D)]
sc = score(t)
#print(sc.score) | 33 | 48 | 708 | 1,356 | import bisect
import random
import sys
input = sys.stdin.readline
class score:
def __init__(self, t):
self.t = t
def first_score(self):
last = [0] * 26
score = 0
for i, ti in enumerate(self.t):
score += S[i][ti - 1]
last[ti - 1] = i + 1
for j in range(26):
score -= C[j] * ((i + 1) - last[j])
self.score = score
return score
D = int(eval(input()))
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
# T = [int(input()) for i in range(D)]
T = []
for i in range(D):
T.append(int(eval(input())))
s = score(T)
print((s.first_score()))
| from bisect import bisect_left
class score:
def __init__(self, t) -> None:
self.t = t
score = 0
last = [[] for i in range(26)]
for i, ti in enumerate(t):
score += s[i][ti - 1]
last[ti - 1].append(i + 1)
for tj in range(26):
if last[tj - 1] == []:
score -= c[tj - 1] * (i + 1)
else:
# print(last)
score -= c[tj - 1] * ((i + 1) - last[tj - 1][-1])
print(score)
self.score = score
def a__init__(self, t) -> None:
score = 0
last = [[] for i in range(26)]
for i, ti in enumerate(t):
# 開催分を加算
score += s[i][ti - 1]
# 減らす
if last[ti - 1] == []:
score -= c[i] * i + 1
else:
score -= c[i] * ((i + 1) - last[ti - 1][-1])
last[ti - 1].append(i + 1)
print(score)
for i in range(26):
if last[i] == []:
score -= c[i] * D
else:
score -= c[i] * (D - last[i][-1])
self.score = score
self.t = t
D = int(eval(input()))
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [int(eval(input())) for i in range(D)]
sc = score(t)
# print(sc.score)
| false | 31.25 | [
"-import bisect",
"-import random",
"-import sys",
"-",
"-input = sys.stdin.readline",
"+from bisect import bisect_left",
"- def __init__(self, t):",
"+ def __init__(self, t) -> None:",
"+ score = 0",
"+ last = [[] for i in range(26)]",
"+ for i, ti in enumerate(t):",
"+ score += s[i][ti - 1]",
"+ last[ti - 1].append(i + 1)",
"+ for tj in range(26):",
"+ if last[tj - 1] == []:",
"+ score -= c[tj - 1] * (i + 1)",
"+ else:",
"+ # print(last)",
"+ score -= c[tj - 1] * ((i + 1) - last[tj - 1][-1])",
"+ print(score)",
"+ self.score = score",
"- def first_score(self):",
"- last = [0] * 26",
"+ def a__init__(self, t) -> None:",
"- for i, ti in enumerate(self.t):",
"- score += S[i][ti - 1]",
"- last[ti - 1] = i + 1",
"- for j in range(26):",
"- score -= C[j] * ((i + 1) - last[j])",
"+ last = [[] for i in range(26)]",
"+ for i, ti in enumerate(t):",
"+ # 開催分を加算",
"+ score += s[i][ti - 1]",
"+ # 減らす",
"+ if last[ti - 1] == []:",
"+ score -= c[i] * i + 1",
"+ else:",
"+ score -= c[i] * ((i + 1) - last[ti - 1][-1])",
"+ last[ti - 1].append(i + 1)",
"+ print(score)",
"+ for i in range(26):",
"+ if last[i] == []:",
"+ score -= c[i] * D",
"+ else:",
"+ score -= c[i] * (D - last[i][-1])",
"- return score",
"+ self.t = t",
"-C = list(map(int, input().split()))",
"-S = [list(map(int, input().split())) for i in range(D)]",
"-# T = [int(input()) for i in range(D)]",
"-T = []",
"-for i in range(D):",
"- T.append(int(eval(input())))",
"- s = score(T)",
"- print((s.first_score()))",
"+c = list(map(int, input().split()))",
"+s = [list(map(int, input().split())) for i in range(D)]",
"+t = [int(eval(input())) for i in range(D)]",
"+sc = score(t)",
"+# print(sc.score)"
] | false | 0.038407 | 0.038327 | 1.002081 | [
"s824536373",
"s099770329"
] |
u852517668 | p03478 | python | s393784219 | s974758794 | 207 | 180 | 42,604 | 40,048 | Accepted | Accepted | 13.04 | N, A, B = list(map(int, input().split()))
ret = 0
for i in range(N + 1):
v = sum(map(int, list(str(i))))
if v >= A and v <= B:
ret += i
print(ret) | def find_sum(n):
ret = 0
while(n > 0):
ret += n % 10
n = int((n - n % 10) / 10)
return ret
N, A, B = list(map(int, input().split()))
ret = 0
for i in range(N + 1):
#v = sum(map(int, list(str(i))))
v = find_sum(i)
if v >= A and v <= B:
ret += i
print(ret) | 7 | 15 | 154 | 287 | N, A, B = list(map(int, input().split()))
ret = 0
for i in range(N + 1):
v = sum(map(int, list(str(i))))
if v >= A and v <= B:
ret += i
print(ret)
| def find_sum(n):
ret = 0
while n > 0:
ret += n % 10
n = int((n - n % 10) / 10)
return ret
N, A, B = list(map(int, input().split()))
ret = 0
for i in range(N + 1):
# v = sum(map(int, list(str(i))))
v = find_sum(i)
if v >= A and v <= B:
ret += i
print(ret)
| false | 53.333333 | [
"+def find_sum(n):",
"+ ret = 0",
"+ while n > 0:",
"+ ret += n % 10",
"+ n = int((n - n % 10) / 10)",
"+ return ret",
"+",
"+",
"- v = sum(map(int, list(str(i))))",
"+ # v = sum(map(int, list(str(i))))",
"+ v = find_sum(i)"
] | false | 0.038868 | 0.078016 | 0.498212 | [
"s393784219",
"s974758794"
] |
u407160848 | p02838 | python | s718967101 | s035148132 | 1,217 | 600 | 156,168 | 156,044 | Accepted | Accepted | 50.7 | import sys
import time
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return map(int, open(0).read().split())
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
def int_to_bits(x):
return [ 1 if 2**i & x != 0 else 0 for i in range(60) ]
def inv(x, MOD):
return pow(x, MOD-2, MOD)
start = time.time()
MOD = 10**9+7
debug = False
if debug:
n = 30 * 10000
A = list(range(n))
else:
n,*A = get_all_int()
# ビットごとの出現回数 2**i
bits = [0] * 60
for a in A:
for i in range(60):
if 2**i & a != 0:
bits[i] += 1
# log("bits:", bits)
# log("bits.", time.time() - start)
# ans = 0
ans = sum(( pow(2, i, MOD) * bits[i] * (n-bits[i]) for i in range(60))) % MOD
# for a in A:
# # a_bits = [ 1 if 2**i & a != 0 else 0 for i in range(60) ]
# for i in range(60):
# ans += 2**i * abs(bits[i] - (1 if 2**i & a != 0 else 0) *n)
# # a_dash = list(map(lambda a: a*(n-1), a_bits))
# # log("a_dash", a_dash)
# # bits_dash = [ bits[i] - a_bits[i] for i in range(60)]
# # log("bits_dash", bits_dash)
# # ans += sum( ( 2**i * abs(bits_dash[i]-2*a_dash[i])) for i in range(60) )
# # ans += sum( ( 2**i * abs(bits[i]-2*a_dash[i])) for i in range(60) )
# # for i in range(60):
# # ans = (ans + 2**i * abs(bits_dash[i] - a_dash[i])) % MOD
# # log(a, ans)
# print(ans//2 % MOD)
print(ans)
# log("end.", time.time() - start)
| # 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return list(map(int, open(0).read().split()))
MOD = 10**9+7
n,*A = get_all_int()
pow2 = [1] * 61
for i in range(1,61):
pow2[i] = pow2[i-1] * 2
# ビットごとの出現回数 2**i
bits = [0] * 60
for a in A:
for i in range(60):
if pow2[i] & a != 0:
bits[i] += 1
# その位のビットの1の個数*0の個数 が、そのビットがansに足される回数
ans = sum(( pow(2, i, MOD) * bits[i] * (n-bits[i]) for i in range(60))) % MOD
print(ans)
| 66 | 24 | 1,494 | 484 | import sys
import time
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return map(int, open(0).read().split())
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
def int_to_bits(x):
return [1 if 2**i & x != 0 else 0 for i in range(60)]
def inv(x, MOD):
return pow(x, MOD - 2, MOD)
start = time.time()
MOD = 10**9 + 7
debug = False
if debug:
n = 30 * 10000
A = list(range(n))
else:
n, *A = get_all_int()
# ビットごとの出現回数 2**i
bits = [0] * 60
for a in A:
for i in range(60):
if 2**i & a != 0:
bits[i] += 1
# log("bits:", bits)
# log("bits.", time.time() - start)
# ans = 0
ans = sum((pow(2, i, MOD) * bits[i] * (n - bits[i]) for i in range(60))) % MOD
# for a in A:
# # a_bits = [ 1 if 2**i & a != 0 else 0 for i in range(60) ]
# for i in range(60):
# ans += 2**i * abs(bits[i] - (1 if 2**i & a != 0 else 0) *n)
# # a_dash = list(map(lambda a: a*(n-1), a_bits))
# # log("a_dash", a_dash)
# # bits_dash = [ bits[i] - a_bits[i] for i in range(60)]
# # log("bits_dash", bits_dash)
# # ans += sum( ( 2**i * abs(bits_dash[i]-2*a_dash[i])) for i in range(60) )
# # ans += sum( ( 2**i * abs(bits[i]-2*a_dash[i])) for i in range(60) )
# # for i in range(60):
# # ans = (ans + 2**i * abs(bits_dash[i] - a_dash[i])) % MOD
# # log(a, ans)
# print(ans//2 % MOD)
print(ans)
# log("end.", time.time() - start)
| # 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return list(map(int, open(0).read().split()))
MOD = 10**9 + 7
n, *A = get_all_int()
pow2 = [1] * 61
for i in range(1, 61):
pow2[i] = pow2[i - 1] * 2
# ビットごとの出現回数 2**i
bits = [0] * 60
for a in A:
for i in range(60):
if pow2[i] & a != 0:
bits[i] += 1
# その位のビットの1の個数*0の個数 が、そのビットがansに足される回数
ans = sum((pow(2, i, MOD) * bits[i] * (n - bits[i]) for i in range(60))) % MOD
print(ans)
| false | 63.636364 | [
"-import sys",
"-import time",
"-",
"- return map(int, open(0).read().split())",
"+ return list(map(int, open(0).read().split()))",
"-def log(*args):",
"- print(\"DEBUG:\", *args, file=sys.stderr)",
"-",
"-",
"-def int_to_bits(x):",
"- return [1 if 2**i & x != 0 else 0 for i in range(60)]",
"-",
"-",
"-def inv(x, MOD):",
"- return pow(x, MOD - 2, MOD)",
"-",
"-",
"-start = time.time()",
"-debug = False",
"-if debug:",
"- n = 30 * 10000",
"- A = list(range(n))",
"-else:",
"- n, *A = get_all_int()",
"+n, *A = get_all_int()",
"+pow2 = [1] * 61",
"+for i in range(1, 61):",
"+ pow2[i] = pow2[i - 1] * 2",
"- if 2**i & a != 0:",
"+ if pow2[i] & a != 0:",
"-# log(\"bits:\", bits)",
"-# log(\"bits.\", time.time() - start)",
"-# ans = 0",
"+# その位のビットの1の個数*0の個数 が、そのビットがansに足される回数",
"-# for a in A:",
"-# # a_bits = [ 1 if 2**i & a != 0 else 0 for i in range(60) ]",
"-# for i in range(60):",
"-# ans += 2**i * abs(bits[i] - (1 if 2**i & a != 0 else 0) *n)",
"-# # a_dash = list(map(lambda a: a*(n-1), a_bits))",
"-# # log(\"a_dash\", a_dash)",
"-# # bits_dash = [ bits[i] - a_bits[i] for i in range(60)]",
"-# # log(\"bits_dash\", bits_dash)",
"-# # ans += sum( ( 2**i * abs(bits_dash[i]-2*a_dash[i])) for i in range(60) )",
"-# # ans += sum( ( 2**i * abs(bits[i]-2*a_dash[i])) for i in range(60) )",
"-# # for i in range(60):",
"-# # ans = (ans + 2**i * abs(bits_dash[i] - a_dash[i])) % MOD",
"-# # log(a, ans)",
"-# print(ans//2 % MOD)",
"-# log(\"end.\", time.time() - start)"
] | false | 0.042959 | 0.154823 | 0.277472 | [
"s718967101",
"s035148132"
] |
u586662847 | p02897 | python | s786707707 | s705570966 | 19 | 17 | 3,064 | 2,940 | Accepted | Accepted | 10.53 | def solve(N):
odd_count = 0
for x in range(1, N + 1)[::-1]:
if x % 2 == 1:
odd_count += 1
if N == 1:
return 1
return odd_count / N
N = int(eval(input()))
print((solve(N)))
| def filter_odd(x):
return x % 2 == 1
def solve(N):
odd_list = list(
filter(filter_odd, list(range(1, N + 1))[::-1])
)
return len(odd_list) / N
N = int(eval(input()))
print((solve(N)))
| 16 | 14 | 229 | 212 | def solve(N):
odd_count = 0
for x in range(1, N + 1)[::-1]:
if x % 2 == 1:
odd_count += 1
if N == 1:
return 1
return odd_count / N
N = int(eval(input()))
print((solve(N)))
| def filter_odd(x):
return x % 2 == 1
def solve(N):
odd_list = list(filter(filter_odd, list(range(1, N + 1))[::-1]))
return len(odd_list) / N
N = int(eval(input()))
print((solve(N)))
| false | 12.5 | [
"+def filter_odd(x):",
"+ return x % 2 == 1",
"+",
"+",
"- odd_count = 0",
"- for x in range(1, N + 1)[::-1]:",
"- if x % 2 == 1:",
"- odd_count += 1",
"- if N == 1:",
"- return 1",
"- return odd_count / N",
"+ odd_list = list(filter(filter_odd, list(range(1, N + 1))[::-1]))",
"+ return len(odd_list) / N"
] | false | 0.041694 | 0.042598 | 0.978798 | [
"s786707707",
"s705570966"
] |
u116002573 | p02954 | python | s186996037 | s840135498 | 103 | 82 | 10,564 | 10,492 | Accepted | Accepted | 20.39 | def main():
S = eval(input())
n = len(S)
i = 0
res = []
while i < len(S):
countL, countR = 0, 0
while i < n and S[i] == "R":
countR += 1
i += 1
while i < n and S[i] == "L":
countL += 1
i += 1
if (countL+countR) % 2 == 0:
half = (countL+countR) // 2
res += [0]*(countR-1) + [half]*2 + [0]*(countL-1)
else:
half1 = (countR+countL+1)//2
half2 = (countR+countL) - half1
if countR > countL:
if (countR-1) % 2 == 0:
res += [0]*(countR-1) + [half1, half2] + [0]*(countL-1)
else:
res += [0]*(countR-1) + [half2, half1] + [0]*(countL-1)
else:
if (countL-1) % 2 == 0:
res += [0]*(countR-1) + [half2, half1] + [0]*(countL-1)
else:
res += [0]*(countR-1) + [half1, half2] + [0]*(countL-1)
return res
if __name__ == '__main__':
output = main()
print((" ".join(map(str, output)))) | def main():
S = eval(input())
n = len(S)
i = 0
ans = [0 for _ in range(n)]
while i < n:
countL, countR = 0, 0
while i < n and S[i] == 'R':
countR += 1
i += 1
while i < n and S[i] == 'L':
countL += 1
i += 1
if(abs(countL-countR) % 2 == 0):
cL, cR = (countL + countR) // 2, (countL + countR) // 2
else:
c = (countL + countR + 1) // 2
if(countR > countL):
if(countR % 2 == 1): cR, cL = c, c-1
else: cR, cL = c-1, c
else:
if(countL % 2 == 1) : cR, cL = c-1, c
else: cR, cL = c, c-1
ans[i-countL] = cL
ans[i-countL-1] = cR
return " ".join(map(str, ans))
if __name__ == '__main__':
print((main())) | 34 | 31 | 1,127 | 860 | def main():
S = eval(input())
n = len(S)
i = 0
res = []
while i < len(S):
countL, countR = 0, 0
while i < n and S[i] == "R":
countR += 1
i += 1
while i < n and S[i] == "L":
countL += 1
i += 1
if (countL + countR) % 2 == 0:
half = (countL + countR) // 2
res += [0] * (countR - 1) + [half] * 2 + [0] * (countL - 1)
else:
half1 = (countR + countL + 1) // 2
half2 = (countR + countL) - half1
if countR > countL:
if (countR - 1) % 2 == 0:
res += [0] * (countR - 1) + [half1, half2] + [0] * (countL - 1)
else:
res += [0] * (countR - 1) + [half2, half1] + [0] * (countL - 1)
else:
if (countL - 1) % 2 == 0:
res += [0] * (countR - 1) + [half2, half1] + [0] * (countL - 1)
else:
res += [0] * (countR - 1) + [half1, half2] + [0] * (countL - 1)
return res
if __name__ == "__main__":
output = main()
print((" ".join(map(str, output))))
| def main():
S = eval(input())
n = len(S)
i = 0
ans = [0 for _ in range(n)]
while i < n:
countL, countR = 0, 0
while i < n and S[i] == "R":
countR += 1
i += 1
while i < n and S[i] == "L":
countL += 1
i += 1
if abs(countL - countR) % 2 == 0:
cL, cR = (countL + countR) // 2, (countL + countR) // 2
else:
c = (countL + countR + 1) // 2
if countR > countL:
if countR % 2 == 1:
cR, cL = c, c - 1
else:
cR, cL = c - 1, c
else:
if countL % 2 == 1:
cR, cL = c - 1, c
else:
cR, cL = c, c - 1
ans[i - countL] = cL
ans[i - countL - 1] = cR
return " ".join(map(str, ans))
if __name__ == "__main__":
print((main()))
| false | 8.823529 | [
"- res = []",
"- while i < len(S):",
"+ ans = [0 for _ in range(n)]",
"+ while i < n:",
"- if (countL + countR) % 2 == 0:",
"- half = (countL + countR) // 2",
"- res += [0] * (countR - 1) + [half] * 2 + [0] * (countL - 1)",
"+ if abs(countL - countR) % 2 == 0:",
"+ cL, cR = (countL + countR) // 2, (countL + countR) // 2",
"- half1 = (countR + countL + 1) // 2",
"- half2 = (countR + countL) - half1",
"+ c = (countL + countR + 1) // 2",
"- if (countR - 1) % 2 == 0:",
"- res += [0] * (countR - 1) + [half1, half2] + [0] * (countL - 1)",
"+ if countR % 2 == 1:",
"+ cR, cL = c, c - 1",
"- res += [0] * (countR - 1) + [half2, half1] + [0] * (countL - 1)",
"+ cR, cL = c - 1, c",
"- if (countL - 1) % 2 == 0:",
"- res += [0] * (countR - 1) + [half2, half1] + [0] * (countL - 1)",
"+ if countL % 2 == 1:",
"+ cR, cL = c - 1, c",
"- res += [0] * (countR - 1) + [half1, half2] + [0] * (countL - 1)",
"- return res",
"+ cR, cL = c, c - 1",
"+ ans[i - countL] = cL",
"+ ans[i - countL - 1] = cR",
"+ return \" \".join(map(str, ans))",
"- output = main()",
"- print((\" \".join(map(str, output))))",
"+ print((main()))"
] | false | 0.042023 | 0.099617 | 0.421848 | [
"s186996037",
"s840135498"
] |
u953110527 | p02802 | python | s416388399 | s260357046 | 308 | 204 | 4,732 | 85,808 | Accepted | Accepted | 33.77 | n,m = list(map(int,input().split()))
ac=[0 for i in range (n)]
wa=[0 for i in range (n)]
grid = []
for i in range(m):
a,b = input().split()
if ac[int(a)-1] == 1:
continue
if b == 'AC':
ac[int(a)-1] = 1
elif b == 'WA':
wa[int(a)-1] += 1
ac_con,wa_con = 0,0
for i in range(n):
if ac[i] == 0:
continue
else:
ac_con+=1
wa_con+=wa[i]
print((ac_con,wa_con)) | n,m = list(map(int,input().split()))
memo2 = [False for i in range(n)]
memo = [0 for i in range(n)]
count1,count2 = 0,0
for i in range(m):
p,l = input().split()
p = int(p)-1
if memo2[p]:
continue
else:
if l == 'WA':
memo[p]+=1
else:
memo2[p] = True
count2 += 1
count1+=memo[p]
print((count2,count1)) | 20 | 17 | 435 | 395 | n, m = list(map(int, input().split()))
ac = [0 for i in range(n)]
wa = [0 for i in range(n)]
grid = []
for i in range(m):
a, b = input().split()
if ac[int(a) - 1] == 1:
continue
if b == "AC":
ac[int(a) - 1] = 1
elif b == "WA":
wa[int(a) - 1] += 1
ac_con, wa_con = 0, 0
for i in range(n):
if ac[i] == 0:
continue
else:
ac_con += 1
wa_con += wa[i]
print((ac_con, wa_con))
| n, m = list(map(int, input().split()))
memo2 = [False for i in range(n)]
memo = [0 for i in range(n)]
count1, count2 = 0, 0
for i in range(m):
p, l = input().split()
p = int(p) - 1
if memo2[p]:
continue
else:
if l == "WA":
memo[p] += 1
else:
memo2[p] = True
count2 += 1
count1 += memo[p]
print((count2, count1))
| false | 15 | [
"-ac = [0 for i in range(n)]",
"-wa = [0 for i in range(n)]",
"-grid = []",
"+memo2 = [False for i in range(n)]",
"+memo = [0 for i in range(n)]",
"+count1, count2 = 0, 0",
"- a, b = input().split()",
"- if ac[int(a) - 1] == 1:",
"- continue",
"- if b == \"AC\":",
"- ac[int(a) - 1] = 1",
"- elif b == \"WA\":",
"- wa[int(a) - 1] += 1",
"-ac_con, wa_con = 0, 0",
"-for i in range(n):",
"- if ac[i] == 0:",
"+ p, l = input().split()",
"+ p = int(p) - 1",
"+ if memo2[p]:",
"- ac_con += 1",
"- wa_con += wa[i]",
"-print((ac_con, wa_con))",
"+ if l == \"WA\":",
"+ memo[p] += 1",
"+ else:",
"+ memo2[p] = True",
"+ count2 += 1",
"+ count1 += memo[p]",
"+print((count2, count1))"
] | false | 0.112599 | 0.079417 | 1.417816 | [
"s416388399",
"s260357046"
] |
u968166680 | p02586 | python | s151050560 | s790978427 | 536 | 475 | 199,388 | 200,220 | Accepted | Accepted | 11.38 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
R, C, K, *RCV = list(map(int, read().split()))
item = [[0] * C for _ in range(R)]
for r, c, v in zip(*[iter(RCV)] * 3):
item[r - 1][c - 1] = v
dp = [0] * (C + 1)
for i in range(R):
dp, dp_prev = [0] * (C + 1), dp
v = [0] * 4
for j in range(C):
for k in range(4):
if v[k] < dp_prev[j + 1]:
v[k] = dp_prev[j + 1]
else:
break
if item[i][j] > 0:
for k in range(2, -1, -1):
if v[k + 1] < v[k] + item[i][j]:
v[k + 1] = v[k] + item[i][j]
dp[j + 1] = v[3]
print((dp[C]))
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
R, C, K, *RCV = list(map(int, read().split()))
item = [[0] * C for _ in range(R)]
for r, c, v in zip(*[iter(RCV)] * 3):
item[r - 1][c - 1] = v
dp = [0] * (C + 1)
for i in range(R):
value = [0] * 4
for j in range(C):
for k in range(4):
if value[k] < dp[j + 1]:
value[k] = dp[j + 1]
else:
break
if item[i][j] > 0:
for k in range(2, -1, -1):
if value[k + 1] < value[k] + item[i][j]:
value[k + 1] = value[k] + item[i][j]
dp[j + 1] = value[3]
print((dp[C]))
return
if __name__ == '__main__':
main()
| 40 | 39 | 945 | 926 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
R, C, K, *RCV = list(map(int, read().split()))
item = [[0] * C for _ in range(R)]
for r, c, v in zip(*[iter(RCV)] * 3):
item[r - 1][c - 1] = v
dp = [0] * (C + 1)
for i in range(R):
dp, dp_prev = [0] * (C + 1), dp
v = [0] * 4
for j in range(C):
for k in range(4):
if v[k] < dp_prev[j + 1]:
v[k] = dp_prev[j + 1]
else:
break
if item[i][j] > 0:
for k in range(2, -1, -1):
if v[k + 1] < v[k] + item[i][j]:
v[k + 1] = v[k] + item[i][j]
dp[j + 1] = v[3]
print((dp[C]))
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
R, C, K, *RCV = list(map(int, read().split()))
item = [[0] * C for _ in range(R)]
for r, c, v in zip(*[iter(RCV)] * 3):
item[r - 1][c - 1] = v
dp = [0] * (C + 1)
for i in range(R):
value = [0] * 4
for j in range(C):
for k in range(4):
if value[k] < dp[j + 1]:
value[k] = dp[j + 1]
else:
break
if item[i][j] > 0:
for k in range(2, -1, -1):
if value[k + 1] < value[k] + item[i][j]:
value[k + 1] = value[k] + item[i][j]
dp[j + 1] = value[3]
print((dp[C]))
return
if __name__ == "__main__":
main()
| false | 2.5 | [
"- dp, dp_prev = [0] * (C + 1), dp",
"- v = [0] * 4",
"+ value = [0] * 4",
"- if v[k] < dp_prev[j + 1]:",
"- v[k] = dp_prev[j + 1]",
"+ if value[k] < dp[j + 1]:",
"+ value[k] = dp[j + 1]",
"- if v[k + 1] < v[k] + item[i][j]:",
"- v[k + 1] = v[k] + item[i][j]",
"- dp[j + 1] = v[3]",
"+ if value[k + 1] < value[k] + item[i][j]:",
"+ value[k + 1] = value[k] + item[i][j]",
"+ dp[j + 1] = value[3]"
] | false | 0.050402 | 0.04165 | 1.21011 | [
"s151050560",
"s790978427"
] |
u785205215 | p03579 | python | s458367481 | s582684899 | 539 | 423 | 43,248 | 43,340 | Accepted | Accepted | 21.52 | from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))
def is_biparate(links):
'''
0=white,1=blackとする
2部グラフなら黒に塗られている頂点の数を返す
2部グラフでないなら-1を返す。
'''
colors = [-1] * n
colors[0] = 0
q = [(0, 0)] #0=white, 1=blackとする
visited = set()
while q:
v, c = q.pop()
if v in visited:
if colors[v] != c: #最初に塗られた色とは反対の色が塗られるなら
return -1
continue
visited.add(v)
colors[v] = c
for u in links[v]:
q.append((u, c ^ 1)) #0^0=1 1^1=0 vとは反対の色を塗る
return sum(colors) #1の数 = blackの数
n, m = readLine_int_list()
g = [set() for _ in range(n)]
def main():
for _ in range(m):
a, b = readLine_int_list()
a -= 1
b -= 1
g[a].add(b)
g[b].add(a)
bp1 = is_biparate(g)
if bp1 == -1:
'''
2部グラフではない場合
結論:完全グラフになるまで辺を追加できる
→why
奇サイクル上のある点をvとする
s → v → tが偶数長でも、 奇サイクルの他の頂点を余計に経由することで奇数長になる
s → tが奇数長になれば線が引ける
つまり、任意の頂点間において奇数長が存在することになる
完全グラフの辺の数は、n * (n - 1) // 2
これには元あった辺の数まで含まれているので、 -m する
'''
max_m = n * (n - 1) // 2
else:
'''
2部グラフの場合
結論:(blackの数*whiteの数)本、線ができる
why
奇数閉路が存在しない => 異なる色間は必ず奇数長、同色間は必ず偶数長
1. whiteとblackの間は奇数長のパスが存在する ->線が引ける
2. 同じ色どうしには奇数長のパスは存在しない -> 線は引かれない
black=3, white=2の時の線の引き方 = b*w
b*wにはパスの長さが1つまりもともとのパスが含まれてるので、-m する
'''
max_m = bp1 * (n - bp1)
print((max_m - m))
if __name__ == "__main__":
main() | '''
問題
http://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c
解説
https://img.atcoder.jp/code-festival-2017-qualb/editorial.pdf
参考
http://code-festival-2017-qualb.contest.atcoder.jp/submissions/1666106
'''
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))
def is_biparate(links):
'''
0=white,1=blackとする
2部グラフなら黒に塗られている頂点の数を返す
2部グラフでないなら-1を返す。
'''
colors = [-1] * n
colors[0] = 0
q = [(0, 0)] #0=white, 1=blackとする
visited = set()
while q:
v, c = q.pop()
if v in visited:
if colors[v] != c: #最初に塗られた色とは反対の色が塗られるなら
return -1
continue
visited.add(v)
colors[v] = c
for u in links[v]:
q.append((u, c ^ 1)) #0^1=1 1^1=0 vとは反対の色を塗る
return sum(colors) #1の数 = blackの数
n, m = readLine_int_list()
g = [set() for _ in range(n)]
def main():
for _ in range(m):
a, b = readLine_int_list()
a -= 1
b -= 1
g[a].add(b)
g[b].add(a)
bp1 = is_biparate(g)
if bp1 == -1:
'''
2部グラフではない場合
結論:完全グラフになるまで辺を追加できる
→why
奇サイクル上のある点をvとする
s → v → tが偶数長でも、 奇サイクルの他の頂点を余計に経由することで奇数長になる
s → tが奇数長になれば線が引ける
つまり、任意の頂点間において奇数長が存在することになる
完全グラフの辺の数は、n * (n - 1) // 2
これには元あった辺の数まで含まれているので、 -m する
'''
max_m = n * (n - 1) // 2
else:
'''
2部グラフの場合
結論:(blackの数*whiteの数)本、線ができる
why
奇数閉路が存在しない => 異なる色間は必ず奇数長、同色間は必ず偶数長
1. whiteとblackの間は奇数長のパスが存在する ->線が引ける
2. 同じ色どうしには奇数長のパスは存在しない -> 線は引かれない
black=3, white=2の時の線の引き方 = b*w
b*wにはパスの長さが1つまりもともとのパスが含まれてるので、-m する
'''
max_m = bp1 * (n - bp1)
print((max_m - m))
if __name__ == "__main__":
main() | 75 | 83 | 1,830 | 2,072 | from sys import stdin, stdout
def readLine_int_list():
return list(map(int, stdin.readline().split()))
def is_biparate(links):
"""
0=white,1=blackとする
2部グラフなら黒に塗られている頂点の数を返す
2部グラフでないなら-1を返す。
"""
colors = [-1] * n
colors[0] = 0
q = [(0, 0)] # 0=white, 1=blackとする
visited = set()
while q:
v, c = q.pop()
if v in visited:
if colors[v] != c: # 最初に塗られた色とは反対の色が塗られるなら
return -1
continue
visited.add(v)
colors[v] = c
for u in links[v]:
q.append((u, c ^ 1)) # 0^0=1 1^1=0 vとは反対の色を塗る
return sum(colors) # 1の数 = blackの数
n, m = readLine_int_list()
g = [set() for _ in range(n)]
def main():
for _ in range(m):
a, b = readLine_int_list()
a -= 1
b -= 1
g[a].add(b)
g[b].add(a)
bp1 = is_biparate(g)
if bp1 == -1:
"""
2部グラフではない場合
結論:完全グラフになるまで辺を追加できる
→why
奇サイクル上のある点をvとする
s → v → tが偶数長でも、 奇サイクルの他の頂点を余計に経由することで奇数長になる
s → tが奇数長になれば線が引ける
つまり、任意の頂点間において奇数長が存在することになる
完全グラフの辺の数は、n * (n - 1) // 2
これには元あった辺の数まで含まれているので、 -m する
"""
max_m = n * (n - 1) // 2
else:
"""
2部グラフの場合
結論:(blackの数*whiteの数)本、線ができる
why
奇数閉路が存在しない => 異なる色間は必ず奇数長、同色間は必ず偶数長
1. whiteとblackの間は奇数長のパスが存在する ->線が引ける
2. 同じ色どうしには奇数長のパスは存在しない -> 線は引かれない
black=3, white=2の時の線の引き方 = b*w
b*wにはパスの長さが1つまりもともとのパスが含まれてるので、-m する
"""
max_m = bp1 * (n - bp1)
print((max_m - m))
if __name__ == "__main__":
main()
| """
問題
http://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c
解説
https://img.atcoder.jp/code-festival-2017-qualb/editorial.pdf
参考
http://code-festival-2017-qualb.contest.atcoder.jp/submissions/1666106
"""
from sys import stdin, stdout
def readLine_int_list():
return list(map(int, stdin.readline().split()))
def is_biparate(links):
"""
0=white,1=blackとする
2部グラフなら黒に塗られている頂点の数を返す
2部グラフでないなら-1を返す。
"""
colors = [-1] * n
colors[0] = 0
q = [(0, 0)] # 0=white, 1=blackとする
visited = set()
while q:
v, c = q.pop()
if v in visited:
if colors[v] != c: # 最初に塗られた色とは反対の色が塗られるなら
return -1
continue
visited.add(v)
colors[v] = c
for u in links[v]:
q.append((u, c ^ 1)) # 0^1=1 1^1=0 vとは反対の色を塗る
return sum(colors) # 1の数 = blackの数
n, m = readLine_int_list()
g = [set() for _ in range(n)]
def main():
for _ in range(m):
a, b = readLine_int_list()
a -= 1
b -= 1
g[a].add(b)
g[b].add(a)
bp1 = is_biparate(g)
if bp1 == -1:
"""
2部グラフではない場合
結論:完全グラフになるまで辺を追加できる
→why
奇サイクル上のある点をvとする
s → v → tが偶数長でも、 奇サイクルの他の頂点を余計に経由することで奇数長になる
s → tが奇数長になれば線が引ける
つまり、任意の頂点間において奇数長が存在することになる
完全グラフの辺の数は、n * (n - 1) // 2
これには元あった辺の数まで含まれているので、 -m する
"""
max_m = n * (n - 1) // 2
else:
"""
2部グラフの場合
結論:(blackの数*whiteの数)本、線ができる
why
奇数閉路が存在しない => 異なる色間は必ず奇数長、同色間は必ず偶数長
1. whiteとblackの間は奇数長のパスが存在する ->線が引ける
2. 同じ色どうしには奇数長のパスは存在しない -> 線は引かれない
black=3, white=2の時の線の引き方 = b*w
b*wにはパスの長さが1つまりもともとのパスが含まれてるので、-m する
"""
max_m = bp1 * (n - bp1)
print((max_m - m))
if __name__ == "__main__":
main()
| false | 9.638554 | [
"+\"\"\"",
"+問題",
"+http://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c",
"+解説",
"+https://img.atcoder.jp/code-festival-2017-qualb/editorial.pdf",
"+参考",
"+http://code-festival-2017-qualb.contest.atcoder.jp/submissions/1666106",
"+\"\"\"",
"- q.append((u, c ^ 1)) # 0^0=1 1^1=0 vとは反対の色を塗る",
"+ q.append((u, c ^ 1)) # 0^1=1 1^1=0 vとは反対の色を塗る"
] | false | 0.118435 | 0.131694 | 0.899317 | [
"s458367481",
"s582684899"
] |
u936985471 | p04035 | python | s948587071 | s511420041 | 139 | 122 | 14,076 | 14,060 | Accepted | Accepted | 12.23 | n,l=list(map(int,input().split()))
a=list(map(int,input().split()))
last=-1
for i in range(n-1):
if a[i]+a[i+1]>=l:
last=i+1
if last==-1:
print("Impossible")
else:
print("Possible")
for i in range(1,last):
print(i)
for i in range(len(a)-1,last-1,-1):
print(i)
| n,l=list(map(int,input().split()))
a=list(map(int,input().split()))
last=-1
for i in range(n-1):
if a[i]+a[i+1]>=l:
last=i+1
break
if last==-1:
print("Impossible")
else:
print("Possible")
for i in range(1,last):
print(i)
for i in range(len(a)-1,last-1,-1):
print(i)
| 14 | 15 | 289 | 300 | n, l = list(map(int, input().split()))
a = list(map(int, input().split()))
last = -1
for i in range(n - 1):
if a[i] + a[i + 1] >= l:
last = i + 1
if last == -1:
print("Impossible")
else:
print("Possible")
for i in range(1, last):
print(i)
for i in range(len(a) - 1, last - 1, -1):
print(i)
| n, l = list(map(int, input().split()))
a = list(map(int, input().split()))
last = -1
for i in range(n - 1):
if a[i] + a[i + 1] >= l:
last = i + 1
break
if last == -1:
print("Impossible")
else:
print("Possible")
for i in range(1, last):
print(i)
for i in range(len(a) - 1, last - 1, -1):
print(i)
| false | 6.666667 | [
"+ break"
] | false | 0.098803 | 0.04964 | 1.990378 | [
"s948587071",
"s511420041"
] |
u803848678 | p03525 | python | s518707439 | s103010365 | 22 | 17 | 3,064 | 3,064 | Accepted | Accepted | 22.73 | n = int(eval(input()))
a = [0]*13
for i in map(int, input().split()):
a[i] += 1
ans = 0
if not (any(i>2 for i in a) or a[0] or a[12]>1):
s = [[0]]
for i in range(1, 13):
nxt = []
if a[i] == 0:
nxt = s
elif a[i] == 1:
for si in s:
nxt.append(si+[i])
nxt.append(si+[24-i])
else:
for si in s:
nxt.append(si+[i, 24-i])
s = nxt
for si in s:
si.sort()
tmp = float("Inf")
for i in range(len(si)):
k = abs(si[i]-si[i-1])
k = min(k, 24-k)
tmp = min(tmp, k)
ans = max(ans, tmp)
print(ans) | n = int(eval(input()))
d = list(map(int, input().split())) + [0]
d.sort()
d = [j if i%2 else (24-j)%24 for i, j in enumerate(d)]
d.sort()
ans = float("Inf")
for i in range(n+1):
k = abs(d[i-1]-d[i])
ans = min(ans, min(k, 24-k))
print(ans) | 29 | 10 | 709 | 249 | n = int(eval(input()))
a = [0] * 13
for i in map(int, input().split()):
a[i] += 1
ans = 0
if not (any(i > 2 for i in a) or a[0] or a[12] > 1):
s = [[0]]
for i in range(1, 13):
nxt = []
if a[i] == 0:
nxt = s
elif a[i] == 1:
for si in s:
nxt.append(si + [i])
nxt.append(si + [24 - i])
else:
for si in s:
nxt.append(si + [i, 24 - i])
s = nxt
for si in s:
si.sort()
tmp = float("Inf")
for i in range(len(si)):
k = abs(si[i] - si[i - 1])
k = min(k, 24 - k)
tmp = min(tmp, k)
ans = max(ans, tmp)
print(ans)
| n = int(eval(input()))
d = list(map(int, input().split())) + [0]
d.sort()
d = [j if i % 2 else (24 - j) % 24 for i, j in enumerate(d)]
d.sort()
ans = float("Inf")
for i in range(n + 1):
k = abs(d[i - 1] - d[i])
ans = min(ans, min(k, 24 - k))
print(ans)
| false | 65.517241 | [
"-a = [0] * 13",
"-for i in map(int, input().split()):",
"- a[i] += 1",
"-ans = 0",
"-if not (any(i > 2 for i in a) or a[0] or a[12] > 1):",
"- s = [[0]]",
"- for i in range(1, 13):",
"- nxt = []",
"- if a[i] == 0:",
"- nxt = s",
"- elif a[i] == 1:",
"- for si in s:",
"- nxt.append(si + [i])",
"- nxt.append(si + [24 - i])",
"- else:",
"- for si in s:",
"- nxt.append(si + [i, 24 - i])",
"- s = nxt",
"- for si in s:",
"- si.sort()",
"- tmp = float(\"Inf\")",
"- for i in range(len(si)):",
"- k = abs(si[i] - si[i - 1])",
"- k = min(k, 24 - k)",
"- tmp = min(tmp, k)",
"- ans = max(ans, tmp)",
"+d = list(map(int, input().split())) + [0]",
"+d.sort()",
"+d = [j if i % 2 else (24 - j) % 24 for i, j in enumerate(d)]",
"+d.sort()",
"+ans = float(\"Inf\")",
"+for i in range(n + 1):",
"+ k = abs(d[i - 1] - d[i])",
"+ ans = min(ans, min(k, 24 - k))"
] | false | 0.037628 | 0.119323 | 0.315345 | [
"s518707439",
"s103010365"
] |
u557792847 | p03087 | python | s317174728 | s350114086 | 340 | 312 | 29,780 | 29,896 | Accepted | Accepted | 8.24 | N, Q = list(map(int, input().split()))
S = eval(input())
qn = [list(map(int, input().split())) for _ in range(Q)]
S = "0" + S
cnt = []
cnt.append(0)
for i in range(1, N+1):
if (S[i-1:i+1] == "AC"):
cnt.append(cnt[i-1] + 1)
else:
cnt.append(cnt[i-1])
for q in qn:
ans = cnt[q[1]] - cnt[q[0]-1]
if S[q[0]-1:q[0]+1] == "AC":
ans -= 1
print(ans) | N, Q = list(map(int, input().split()))
S = eval(input())
qn = [list(map(int, input().split())) for _ in range(Q)]
S = "0" + S
cnt = [0 for _ in range(N+1)]
# cnt.append(0)
for i in range(1, N+1):
if (S[i-1:i+1] == "AC"):
cnt[i] = cnt[i-1] + 1
else:
cnt[i] = cnt[i-1]
for q in qn:
l, r = q
# print(l, cnt[l-2], r, cnt[r-1])
print((cnt[r] - cnt[l]))
| 16 | 15 | 388 | 384 | N, Q = list(map(int, input().split()))
S = eval(input())
qn = [list(map(int, input().split())) for _ in range(Q)]
S = "0" + S
cnt = []
cnt.append(0)
for i in range(1, N + 1):
if S[i - 1 : i + 1] == "AC":
cnt.append(cnt[i - 1] + 1)
else:
cnt.append(cnt[i - 1])
for q in qn:
ans = cnt[q[1]] - cnt[q[0] - 1]
if S[q[0] - 1 : q[0] + 1] == "AC":
ans -= 1
print(ans)
| N, Q = list(map(int, input().split()))
S = eval(input())
qn = [list(map(int, input().split())) for _ in range(Q)]
S = "0" + S
cnt = [0 for _ in range(N + 1)]
# cnt.append(0)
for i in range(1, N + 1):
if S[i - 1 : i + 1] == "AC":
cnt[i] = cnt[i - 1] + 1
else:
cnt[i] = cnt[i - 1]
for q in qn:
l, r = q
# print(l, cnt[l-2], r, cnt[r-1])
print((cnt[r] - cnt[l]))
| false | 6.25 | [
"-cnt = []",
"-cnt.append(0)",
"+cnt = [0 for _ in range(N + 1)]",
"+# cnt.append(0)",
"- cnt.append(cnt[i - 1] + 1)",
"+ cnt[i] = cnt[i - 1] + 1",
"- cnt.append(cnt[i - 1])",
"+ cnt[i] = cnt[i - 1]",
"- ans = cnt[q[1]] - cnt[q[0] - 1]",
"- if S[q[0] - 1 : q[0] + 1] == \"AC\":",
"- ans -= 1",
"- print(ans)",
"+ l, r = q",
"+ # print(l, cnt[l-2], r, cnt[r-1])",
"+ print((cnt[r] - cnt[l]))"
] | false | 0.066816 | 0.076372 | 0.874875 | [
"s317174728",
"s350114086"
] |
u063052907 | p03721 | python | s945465478 | s359872263 | 428 | 311 | 17,816 | 5,748 | Accepted | Accepted | 27.34 | N, K = list(map(int, input().split()))
lst_ab = sorted([tuple(map(int, input().split())) for _ in range(N)])
length = 0
for i in range(N):
ai, bi = lst_ab[i][0], lst_ab[i][1]
length += bi
if length >= K:
ans = ai
print(ans)
break
| N, K = list(map(int, input().split()))
lst = [0] * (10**5 + 1)
length = 0
for i in range(N):
ai, bi = list(map(int, input().split()))
lst[ai] += bi
for ai, bi in enumerate(lst):
length += bi
if length >= K:
ans = ai
print(ans)
break
| 12 | 15 | 273 | 278 | N, K = list(map(int, input().split()))
lst_ab = sorted([tuple(map(int, input().split())) for _ in range(N)])
length = 0
for i in range(N):
ai, bi = lst_ab[i][0], lst_ab[i][1]
length += bi
if length >= K:
ans = ai
print(ans)
break
| N, K = list(map(int, input().split()))
lst = [0] * (10**5 + 1)
length = 0
for i in range(N):
ai, bi = list(map(int, input().split()))
lst[ai] += bi
for ai, bi in enumerate(lst):
length += bi
if length >= K:
ans = ai
print(ans)
break
| false | 20 | [
"-lst_ab = sorted([tuple(map(int, input().split())) for _ in range(N)])",
"+lst = [0] * (10**5 + 1)",
"- ai, bi = lst_ab[i][0], lst_ab[i][1]",
"+ ai, bi = list(map(int, input().split()))",
"+ lst[ai] += bi",
"+for ai, bi in enumerate(lst):"
] | false | 0.035463 | 0.039123 | 0.906432 | [
"s945465478",
"s359872263"
] |
u499381410 | p02893 | python | s304799646 | s286037774 | 232 | 144 | 95,064 | 108,568 | Accepted | Accepted | 37.93 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
n = I()
x = S()
rx=x.replace("1","2").replace("0","1").replace("2","0")
D = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
if n // i % 2:
D += [i]
if i != n // i and i % 2:
D += [n // i]
D.sort()
bx=int(x,2)
cnt = [0] * len(D)
ans = 0
for k in range(len(D)):
t=x[:D[k]]
rt=rx[:D[k]]
f=(t+rt)*(n//D[k]//2)+t
cnt[k]=cnt[k]+int(int(f,2)<=bx)+int(t,2)
cnt[k]%=mod
ans += cnt[k]*D[k]*2
for kk in range(k + 1, len(D)):
if D[kk] % D[k] == 0:
cnt[kk] -= cnt[k]
cnt[kk]%=mod
ans %= mod
print((ans % mod))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
n = I()
x = S()
rx=x.replace("1","2").replace("0","1").replace("2","0")
D = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
if n // i % 2:
D += [i]
if i != n // i and i % 2:
D += [n // i]
D.sort()
bx=int(x,2)
cnt = [0] * len(D)
ans = 0
for k in range(len(D)):
t=x[:D[k]]
rt=rx[:D[k]]
f=(t+rt)*(n//D[k]//2)+t
cnt[k]=cnt[k]+int(f<=x)+int(t,2)
cnt[k]%=mod
ans += cnt[k]*D[k]*2
for kk in range(k + 1, len(D)):
if D[kk] % D[k] == 0:
cnt[kk] -= cnt[k]
cnt[kk]%=mod
ans %= mod
print((ans % mod))
| 57 | 57 | 1,598 | 1,590 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().rstrip().split()
def S():
return sys.stdin.readline().rstrip()
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
n = I()
x = S()
rx = x.replace("1", "2").replace("0", "1").replace("2", "0")
D = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
if n // i % 2:
D += [i]
if i != n // i and i % 2:
D += [n // i]
D.sort()
bx = int(x, 2)
cnt = [0] * len(D)
ans = 0
for k in range(len(D)):
t = x[: D[k]]
rt = rx[: D[k]]
f = (t + rt) * (n // D[k] // 2) + t
cnt[k] = cnt[k] + int(int(f, 2) <= bx) + int(t, 2)
cnt[k] %= mod
ans += cnt[k] * D[k] * 2
for kk in range(k + 1, len(D)):
if D[kk] % D[k] == 0:
cnt[kk] -= cnt[k]
cnt[kk] %= mod
ans %= mod
print((ans % mod))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().rstrip().split()
def S():
return sys.stdin.readline().rstrip()
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
n = I()
x = S()
rx = x.replace("1", "2").replace("0", "1").replace("2", "0")
D = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
if n // i % 2:
D += [i]
if i != n // i and i % 2:
D += [n // i]
D.sort()
bx = int(x, 2)
cnt = [0] * len(D)
ans = 0
for k in range(len(D)):
t = x[: D[k]]
rt = rx[: D[k]]
f = (t + rt) * (n // D[k] // 2) + t
cnt[k] = cnt[k] + int(f <= x) + int(t, 2)
cnt[k] %= mod
ans += cnt[k] * D[k] * 2
for kk in range(k + 1, len(D)):
if D[kk] % D[k] == 0:
cnt[kk] -= cnt[k]
cnt[kk] %= mod
ans %= mod
print((ans % mod))
| false | 0 | [
"- cnt[k] = cnt[k] + int(int(f, 2) <= bx) + int(t, 2)",
"+ cnt[k] = cnt[k] + int(f <= x) + int(t, 2)"
] | false | 0.038631 | 0.039333 | 0.982141 | [
"s304799646",
"s286037774"
] |
u032662562 | p00113 | python | s418121553 | s813056527 | 130 | 120 | 10,020 | 9,964 | Accepted | Accepted | 7.69 | from decimal import *
import re
def solve2(m, n):
maxlen = 80
PREC=200
getcontext().prec = PREC
x = Decimal(m) / Decimal(n)
s = x.to_eng_string()
if len(s) < PREC:
return(s[2:],'')
rep = 1
while True:
r = r'(.{%d})\1{%d,}' % (rep, int(maxlen/rep)) #ex. '(.{6})\\1{13,}'
a=re.search(r, s)
if a:
break
rep += 1
if rep > maxlen:
raise ValueError('This cannot happen.rep=%d' % rep)
u = s[2:a.start()+len(a.group(1))]
v = (' '*PREC + '^'*len(a.group(1)))[-len(u):]
return(u,v)
while True:
try:
m,n = list(map(int, input().strip().split()))
s,t = solve2(m, n)
print(s)
if t!='':
print(t)
except EOFError:
break | from decimal import *
import re
def solve2(m, n):
maxlen = 80
PREC=180
getcontext().prec = PREC
x = Decimal(m) / Decimal(n)
s = x.to_eng_string()
if len(s) < PREC:
return(s[2:],'')
rep = 1
while True:
r = r'(.{%d})\1{%d,}' % (rep, int(maxlen/rep)) #ex. '(.{6})\\1{13,}'
a=re.search(r, s)
if a:
break
rep += 1
if rep > maxlen:
raise ValueError('This cannot happen.rep=%d' % rep)
u = s[2:a.start()+len(a.group(1))]
v = (' '*PREC + '^'*len(a.group(1)))[-len(u):]
return(u,v)
while True:
try:
m,n = list(map(int, input().strip().split()))
s,t = solve2(m, n)
print(s)
if t!='':
print(t)
except EOFError:
break | 33 | 33 | 809 | 809 | from decimal import *
import re
def solve2(m, n):
maxlen = 80
PREC = 200
getcontext().prec = PREC
x = Decimal(m) / Decimal(n)
s = x.to_eng_string()
if len(s) < PREC:
return (s[2:], "")
rep = 1
while True:
r = r"(.{%d})\1{%d,}" % (rep, int(maxlen / rep)) # ex. '(.{6})\\1{13,}'
a = re.search(r, s)
if a:
break
rep += 1
if rep > maxlen:
raise ValueError("This cannot happen.rep=%d" % rep)
u = s[2 : a.start() + len(a.group(1))]
v = (" " * PREC + "^" * len(a.group(1)))[-len(u) :]
return (u, v)
while True:
try:
m, n = list(map(int, input().strip().split()))
s, t = solve2(m, n)
print(s)
if t != "":
print(t)
except EOFError:
break
| from decimal import *
import re
def solve2(m, n):
maxlen = 80
PREC = 180
getcontext().prec = PREC
x = Decimal(m) / Decimal(n)
s = x.to_eng_string()
if len(s) < PREC:
return (s[2:], "")
rep = 1
while True:
r = r"(.{%d})\1{%d,}" % (rep, int(maxlen / rep)) # ex. '(.{6})\\1{13,}'
a = re.search(r, s)
if a:
break
rep += 1
if rep > maxlen:
raise ValueError("This cannot happen.rep=%d" % rep)
u = s[2 : a.start() + len(a.group(1))]
v = (" " * PREC + "^" * len(a.group(1)))[-len(u) :]
return (u, v)
while True:
try:
m, n = list(map(int, input().strip().split()))
s, t = solve2(m, n)
print(s)
if t != "":
print(t)
except EOFError:
break
| false | 0 | [
"- PREC = 200",
"+ PREC = 180"
] | false | 0.052684 | 0.05421 | 0.971855 | [
"s418121553",
"s813056527"
] |
u392029857 | p03607 | python | s222204222 | s430194144 | 248 | 229 | 15,076 | 15,076 | Accepted | Accepted | 7.66 | N = int(eval(input()))
A = {}
for i in range(N):
a = int(eval(input()))
A.setdefault(a, 0)
if a in A:
A[a]+=1
count = 0
for v in list(A.values()):
if v%2!=0:
count += 1
print(count) | N = int(eval(input()))
cnt = 0
A = {}
for i in range(N):
a = int(eval(input()))
if a not in A:
A[a] = 1
cnt += 1
else:
A.pop(a)
cnt -= 1
print(cnt) | 12 | 12 | 206 | 190 | N = int(eval(input()))
A = {}
for i in range(N):
a = int(eval(input()))
A.setdefault(a, 0)
if a in A:
A[a] += 1
count = 0
for v in list(A.values()):
if v % 2 != 0:
count += 1
print(count)
| N = int(eval(input()))
cnt = 0
A = {}
for i in range(N):
a = int(eval(input()))
if a not in A:
A[a] = 1
cnt += 1
else:
A.pop(a)
cnt -= 1
print(cnt)
| false | 0 | [
"+cnt = 0",
"- A.setdefault(a, 0)",
"- if a in A:",
"- A[a] += 1",
"-count = 0",
"-for v in list(A.values()):",
"- if v % 2 != 0:",
"- count += 1",
"-print(count)",
"+ if a not in A:",
"+ A[a] = 1",
"+ cnt += 1",
"+ else:",
"+ A.pop(a)",
"+ cnt -= 1",
"+print(cnt)"
] | false | 0.037906 | 0.03938 | 0.962569 | [
"s222204222",
"s430194144"
] |
u219197917 | p02695 | python | s305050777 | s834336603 | 1,408 | 673 | 9,116 | 9,156 | Accepted | Accepted | 52.2 | from itertools import combinations_with_replacement
n, m, q = list(map(int, input().split()))
abcd = [[int(i) for i in input().split()] for _ in range(q)]
s = 0
for p in combinations_with_replacement(list(range(1, m + 1)), n):
t = 0
for a, b, c, d in abcd:
t += d * (p[b - 1] - p[a - 1] == c)
s = max(s, t)
print(s) | from itertools import combinations_with_replacement
def main():
n, m, q = list(map(int, input().split()))
abcd = [[int(i) for i in input().split()] for _ in range(q)]
s = 0
for p in combinations_with_replacement(list(range(1, m + 1)), n):
t = 0
for a, b, c, d in abcd:
t += d * (p[b - 1] - p[a - 1] == c)
s = max(s, t)
print(s)
if __name__ == '__main__':
main() | 11 | 15 | 334 | 425 | from itertools import combinations_with_replacement
n, m, q = list(map(int, input().split()))
abcd = [[int(i) for i in input().split()] for _ in range(q)]
s = 0
for p in combinations_with_replacement(list(range(1, m + 1)), n):
t = 0
for a, b, c, d in abcd:
t += d * (p[b - 1] - p[a - 1] == c)
s = max(s, t)
print(s)
| from itertools import combinations_with_replacement
def main():
n, m, q = list(map(int, input().split()))
abcd = [[int(i) for i in input().split()] for _ in range(q)]
s = 0
for p in combinations_with_replacement(list(range(1, m + 1)), n):
t = 0
for a, b, c, d in abcd:
t += d * (p[b - 1] - p[a - 1] == c)
s = max(s, t)
print(s)
if __name__ == "__main__":
main()
| false | 26.666667 | [
"-n, m, q = list(map(int, input().split()))",
"-abcd = [[int(i) for i in input().split()] for _ in range(q)]",
"-s = 0",
"-for p in combinations_with_replacement(list(range(1, m + 1)), n):",
"- t = 0",
"- for a, b, c, d in abcd:",
"- t += d * (p[b - 1] - p[a - 1] == c)",
"- s = max(s, t)",
"-print(s)",
"+",
"+def main():",
"+ n, m, q = list(map(int, input().split()))",
"+ abcd = [[int(i) for i in input().split()] for _ in range(q)]",
"+ s = 0",
"+ for p in combinations_with_replacement(list(range(1, m + 1)), n):",
"+ t = 0",
"+ for a, b, c, d in abcd:",
"+ t += d * (p[b - 1] - p[a - 1] == c)",
"+ s = max(s, t)",
"+ print(s)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.088605 | 0.211893 | 0.418161 | [
"s305050777",
"s834336603"
] |
u573900545 | p03013 | python | s880101305 | s412722420 | 159 | 144 | 13,792 | 12,696 | Accepted | Accepted | 9.43 | def fib(n):
if n <= 1:
return n
result = [1, 0, 0, 1]
matrix = [1, 1, 1, 0]
while n > 0:
if n % 2:
result = mul(matrix, result)
matrix = mul(matrix, matrix)
n //= 2
return result[2]
def mul(a, b):
return [a[0]*b[0] + a[1]*b[2],
a[0]*b[1] + a[1]*b[3],
a[2]*b[0] + a[3]*b[2],
a[2]*b[1] + a[3]*b[3]]
N, M = list(map(int, input().split()))
if N == 1:
print((1))
quit()
S = [-1]
for i in range(M):
S.append(int(eval(input())))
S.append(N + 1)
S = [S[i + 1] - S[i] for i in range(M + 1)]
if any([x == 1 for x in S]):
print((0))
exit()
num = 1
for x in S:
num *= fib(x - 1)
num = num % 1000000007
print(num) | N, M = list(map(int, input().split()))
if N == 1:
print((1))
quit()
S = [-1] * (N + 1)
S[0] = 1
for i in range(M):
S[int(eval(input()))] = 0
if S[1] != 0:
S[1] = 1
for i in range(2, N + 1):
if S[i] == 0:
continue
else:
S[i] = (S[i - 1] + S[i - 2]) % 1000000007
if S[i] == 0:
print((0))
quit()
print((S[N])) | 35 | 19 | 757 | 378 | def fib(n):
if n <= 1:
return n
result = [1, 0, 0, 1]
matrix = [1, 1, 1, 0]
while n > 0:
if n % 2:
result = mul(matrix, result)
matrix = mul(matrix, matrix)
n //= 2
return result[2]
def mul(a, b):
return [
a[0] * b[0] + a[1] * b[2],
a[0] * b[1] + a[1] * b[3],
a[2] * b[0] + a[3] * b[2],
a[2] * b[1] + a[3] * b[3],
]
N, M = list(map(int, input().split()))
if N == 1:
print((1))
quit()
S = [-1]
for i in range(M):
S.append(int(eval(input())))
S.append(N + 1)
S = [S[i + 1] - S[i] for i in range(M + 1)]
if any([x == 1 for x in S]):
print((0))
exit()
num = 1
for x in S:
num *= fib(x - 1)
num = num % 1000000007
print(num)
| N, M = list(map(int, input().split()))
if N == 1:
print((1))
quit()
S = [-1] * (N + 1)
S[0] = 1
for i in range(M):
S[int(eval(input()))] = 0
if S[1] != 0:
S[1] = 1
for i in range(2, N + 1):
if S[i] == 0:
continue
else:
S[i] = (S[i - 1] + S[i - 2]) % 1000000007
if S[i] == 0:
print((0))
quit()
print((S[N]))
| false | 45.714286 | [
"-def fib(n):",
"- if n <= 1:",
"- return n",
"- result = [1, 0, 0, 1]",
"- matrix = [1, 1, 1, 0]",
"- while n > 0:",
"- if n % 2:",
"- result = mul(matrix, result)",
"- matrix = mul(matrix, matrix)",
"- n //= 2",
"- return result[2]",
"-",
"-",
"-def mul(a, b):",
"- return [",
"- a[0] * b[0] + a[1] * b[2],",
"- a[0] * b[1] + a[1] * b[3],",
"- a[2] * b[0] + a[3] * b[2],",
"- a[2] * b[1] + a[3] * b[3],",
"- ]",
"-",
"-",
"-S = [-1]",
"+S = [-1] * (N + 1)",
"+S[0] = 1",
"- S.append(int(eval(input())))",
"-S.append(N + 1)",
"-S = [S[i + 1] - S[i] for i in range(M + 1)]",
"-if any([x == 1 for x in S]):",
"- print((0))",
"- exit()",
"-num = 1",
"-for x in S:",
"- num *= fib(x - 1)",
"- num = num % 1000000007",
"-print(num)",
"+ S[int(eval(input()))] = 0",
"+if S[1] != 0:",
"+ S[1] = 1",
"+for i in range(2, N + 1):",
"+ if S[i] == 0:",
"+ continue",
"+ else:",
"+ S[i] = (S[i - 1] + S[i - 2]) % 1000000007",
"+ if S[i] == 0:",
"+ print((0))",
"+ quit()",
"+print((S[N]))"
] | false | 0.047143 | 0.048065 | 0.980818 | [
"s880101305",
"s412722420"
] |
u254871849 | p02990 | python | s180810886 | s366688300 | 185 | 24 | 3,940 | 3,828 | Accepted | Accepted | 87.03 | # 2019-11-15 00:35:39(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
# from scipy.misc import comb # float
# import numpy as np
def nCr(n, r):
r = min(r, n - r)
upper = reduce(op.mul, list(range(n, n-r, -1)), 1)
lower = reduce(op.mul, list(range(r, 0, -1)), 1)
return upper // lower
mod = 10 ** 9 + 7
def main():
n, k = [int(x) for x in sys.stdin.readline().split()]
for i in range(1, k+1):
if i <= n - k + 1:
print((nCr(n-k+1, i) * nCr(k-1, i-1) % mod))
else:
print((0)) # i > n - k + 1 となる並べ方は存在しない
if __name__ == "__main__":
main()
| import sys
MOD = 10 ** 9 + 7
def make_table(size=10**6, p=MOD):
fac = [None] * (size + 1)
fac[0] = 1
for i in range(size):
fac[i+1] = fac[i] * (i + 1) % p
ifac = [None] * (size + 1)
ifac[size] = pow(fac[size], p-2, p)
for i in range(size, 0, -1):
ifac[i-1] = ifac[i] * i % p
return fac, ifac
fac, ifac = make_table(5*10**3)
def comb(n, r, mod=MOD):
if r > n or r < 0:
return 0
return fac[n] * ifac[r] % mod * ifac[n-r] % mod
def H(n, r):
return comb(n - 1 + r, r)
n, k = map(int, sys.stdin.readline().split())
def main():
res = [None] * (k + 1)
for i in range(1, k+1):
if i > n - k + 1:
for j in range(i, k+1):
res[j] = 0
break
res[i] = H(i + 1, n - k - (i - 1)) * H(i, k - i) % MOD
return res[1:]
if __name__ == '__main__':
ans = main()
print(*ans, sep='\n')
| 31 | 41 | 823 | 960 | # 2019-11-15 00:35:39(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
# from scipy.misc import comb # float
# import numpy as np
def nCr(n, r):
r = min(r, n - r)
upper = reduce(op.mul, list(range(n, n - r, -1)), 1)
lower = reduce(op.mul, list(range(r, 0, -1)), 1)
return upper // lower
mod = 10**9 + 7
def main():
n, k = [int(x) for x in sys.stdin.readline().split()]
for i in range(1, k + 1):
if i <= n - k + 1:
print((nCr(n - k + 1, i) * nCr(k - 1, i - 1) % mod))
else:
print((0)) # i > n - k + 1 となる並べ方は存在しない
if __name__ == "__main__":
main()
| import sys
MOD = 10**9 + 7
def make_table(size=10**6, p=MOD):
fac = [None] * (size + 1)
fac[0] = 1
for i in range(size):
fac[i + 1] = fac[i] * (i + 1) % p
ifac = [None] * (size + 1)
ifac[size] = pow(fac[size], p - 2, p)
for i in range(size, 0, -1):
ifac[i - 1] = ifac[i] * i % p
return fac, ifac
fac, ifac = make_table(5 * 10**3)
def comb(n, r, mod=MOD):
if r > n or r < 0:
return 0
return fac[n] * ifac[r] % mod * ifac[n - r] % mod
def H(n, r):
return comb(n - 1 + r, r)
n, k = map(int, sys.stdin.readline().split())
def main():
res = [None] * (k + 1)
for i in range(1, k + 1):
if i > n - k + 1:
for j in range(i, k + 1):
res[j] = 0
break
res[i] = H(i + 1, n - k - (i - 1)) * H(i, k - i) % MOD
return res[1:]
if __name__ == "__main__":
ans = main()
print(*ans, sep="\n")
| false | 24.390244 | [
"-# 2019-11-15 00:35:39(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",
"-",
"-# from scipy.misc import comb # float",
"-# import numpy as np",
"-def nCr(n, r):",
"- r = min(r, n - r)",
"- upper = reduce(op.mul, list(range(n, n - r, -1)), 1)",
"- lower = reduce(op.mul, list(range(r, 0, -1)), 1)",
"- return upper // lower",
"+MOD = 10**9 + 7",
"-mod = 10**9 + 7",
"+def make_table(size=10**6, p=MOD):",
"+ fac = [None] * (size + 1)",
"+ fac[0] = 1",
"+ for i in range(size):",
"+ fac[i + 1] = fac[i] * (i + 1) % p",
"+ ifac = [None] * (size + 1)",
"+ ifac[size] = pow(fac[size], p - 2, p)",
"+ for i in range(size, 0, -1):",
"+ ifac[i - 1] = ifac[i] * i % p",
"+ return fac, ifac",
"+",
"+",
"+fac, ifac = make_table(5 * 10**3)",
"+",
"+",
"+def comb(n, r, mod=MOD):",
"+ if r > n or r < 0:",
"+ return 0",
"+ return fac[n] * ifac[r] % mod * ifac[n - r] % mod",
"+",
"+",
"+def H(n, r):",
"+ return comb(n - 1 + r, r)",
"+",
"+",
"+n, k = map(int, sys.stdin.readline().split())",
"- n, k = [int(x) for x in sys.stdin.readline().split()]",
"+ res = [None] * (k + 1)",
"- if i <= n - k + 1:",
"- print((nCr(n - k + 1, i) * nCr(k - 1, i - 1) % mod))",
"- else:",
"- print((0)) # i > n - k + 1 となる並べ方は存在しない",
"+ if i > n - k + 1:",
"+ for j in range(i, k + 1):",
"+ res[j] = 0",
"+ break",
"+ res[i] = H(i + 1, n - k - (i - 1)) * H(i, k - i) % MOD",
"+ return res[1:]",
"- main()",
"+ ans = main()",
"+ print(*ans, sep=\"\\n\")"
] | false | 0.043933 | 0.041046 | 1.070343 | [
"s180810886",
"s366688300"
] |
u934442292 | p02762 | python | s063977440 | s587288654 | 669 | 592 | 47,116 | 52,044 | Accepted | Accepted | 11.51 | import sys
from collections import deque
input = sys.stdin.readline
def dfs(G, comp_id, comp_cnt):
i = 0
cnt = 0
for v in range(len(G)):
if comp_id[v] != -1:
continue
comp_id[v] = i
cnt += 1
stack = deque([v])
while stack:
v = stack.pop()
for c in G[v]:
if comp_id[c] != -1:
continue
comp_id[c] = i
cnt += 1
stack.append(c)
comp_cnt.append(cnt)
cnt = 0
i += 1
def main():
N, M, K = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
A, B = list(map(int, input().split()))
A -= 1
B -= 1
G[A].append(B)
G[B].append(A)
B = [[] for _ in range(N)]
for _ in range(K):
C, D = list(map(int, input().split()))
C -= 1
D -= 1
B[C].append(D)
B[D].append(C)
# connected component
comp_id = [-1] * N
comp_cnt = []
dfs(G, comp_id, comp_cnt)
ans = [-1] * N
for i in range(N):
c_id = comp_id[i]
n_neighbor = len(G[i])
n_block = len(B[i])
for j in B[i]:
if c_id != comp_id[j]:
n_block -= 1
ans[i] = comp_cnt[c_id] - 1 - n_neighbor - n_block
print((*ans))
if __name__ == "__main__":
main()
| import sys
from collections import deque
input = sys.stdin.readline
def calc_group(N, G, group_id, group_cnt):
g_id = 0
for i in range(N):
if group_id[i] != -1:
continue
g_id += 1
group_id[i] = g_id
group_cnt[g_id] = 1
stack = deque([i])
while stack:
v = stack.pop()
for u in G[v]:
if group_id[u] != -1:
continue
group_id[u] = g_id
group_cnt[g_id] += 1
stack.append(u)
def main():
N, M, K = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
A, B = list(map(int, input().split()))
A -= 1
B -= 1
G[A].append(B)
G[B].append(A)
B = [[] for _ in range(N)]
for i in range(K):
C, D = list(map(int, input().split()))
C -= 1
D -= 1
B[C].append(D)
B[D].append(C)
group_id = [-1] * N
group_cnt = {}
calc_group(N, G, group_id, group_cnt)
ans = [0] * N
for i in range(N):
n_neighbor = len(G[i])
n_block = sum(1 for j in B[i] if group_id[i] == group_id[j])
ans[i] = (group_cnt[group_id[i]] - 1) - n_neighbor - n_block
print((" ".join(map(str, ans))))
if __name__ == "__main__":
main()
| 64 | 57 | 1,446 | 1,373 | import sys
from collections import deque
input = sys.stdin.readline
def dfs(G, comp_id, comp_cnt):
i = 0
cnt = 0
for v in range(len(G)):
if comp_id[v] != -1:
continue
comp_id[v] = i
cnt += 1
stack = deque([v])
while stack:
v = stack.pop()
for c in G[v]:
if comp_id[c] != -1:
continue
comp_id[c] = i
cnt += 1
stack.append(c)
comp_cnt.append(cnt)
cnt = 0
i += 1
def main():
N, M, K = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
A, B = list(map(int, input().split()))
A -= 1
B -= 1
G[A].append(B)
G[B].append(A)
B = [[] for _ in range(N)]
for _ in range(K):
C, D = list(map(int, input().split()))
C -= 1
D -= 1
B[C].append(D)
B[D].append(C)
# connected component
comp_id = [-1] * N
comp_cnt = []
dfs(G, comp_id, comp_cnt)
ans = [-1] * N
for i in range(N):
c_id = comp_id[i]
n_neighbor = len(G[i])
n_block = len(B[i])
for j in B[i]:
if c_id != comp_id[j]:
n_block -= 1
ans[i] = comp_cnt[c_id] - 1 - n_neighbor - n_block
print((*ans))
if __name__ == "__main__":
main()
| import sys
from collections import deque
input = sys.stdin.readline
def calc_group(N, G, group_id, group_cnt):
g_id = 0
for i in range(N):
if group_id[i] != -1:
continue
g_id += 1
group_id[i] = g_id
group_cnt[g_id] = 1
stack = deque([i])
while stack:
v = stack.pop()
for u in G[v]:
if group_id[u] != -1:
continue
group_id[u] = g_id
group_cnt[g_id] += 1
stack.append(u)
def main():
N, M, K = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
A, B = list(map(int, input().split()))
A -= 1
B -= 1
G[A].append(B)
G[B].append(A)
B = [[] for _ in range(N)]
for i in range(K):
C, D = list(map(int, input().split()))
C -= 1
D -= 1
B[C].append(D)
B[D].append(C)
group_id = [-1] * N
group_cnt = {}
calc_group(N, G, group_id, group_cnt)
ans = [0] * N
for i in range(N):
n_neighbor = len(G[i])
n_block = sum(1 for j in B[i] if group_id[i] == group_id[j])
ans[i] = (group_cnt[group_id[i]] - 1) - n_neighbor - n_block
print((" ".join(map(str, ans))))
if __name__ == "__main__":
main()
| false | 10.9375 | [
"-def dfs(G, comp_id, comp_cnt):",
"- i = 0",
"- cnt = 0",
"- for v in range(len(G)):",
"- if comp_id[v] != -1:",
"+def calc_group(N, G, group_id, group_cnt):",
"+ g_id = 0",
"+ for i in range(N):",
"+ if group_id[i] != -1:",
"- comp_id[v] = i",
"- cnt += 1",
"- stack = deque([v])",
"+ g_id += 1",
"+ group_id[i] = g_id",
"+ group_cnt[g_id] = 1",
"+ stack = deque([i])",
"- for c in G[v]:",
"- if comp_id[c] != -1:",
"+ for u in G[v]:",
"+ if group_id[u] != -1:",
"- comp_id[c] = i",
"- cnt += 1",
"- stack.append(c)",
"- comp_cnt.append(cnt)",
"- cnt = 0",
"- i += 1",
"+ group_id[u] = g_id",
"+ group_cnt[g_id] += 1",
"+ stack.append(u)",
"- for _ in range(K):",
"+ for i in range(K):",
"- # connected component",
"- comp_id = [-1] * N",
"- comp_cnt = []",
"- dfs(G, comp_id, comp_cnt)",
"- ans = [-1] * N",
"+ group_id = [-1] * N",
"+ group_cnt = {}",
"+ calc_group(N, G, group_id, group_cnt)",
"+ ans = [0] * N",
"- c_id = comp_id[i]",
"- n_block = len(B[i])",
"- for j in B[i]:",
"- if c_id != comp_id[j]:",
"- n_block -= 1",
"- ans[i] = comp_cnt[c_id] - 1 - n_neighbor - n_block",
"- print((*ans))",
"+ n_block = sum(1 for j in B[i] if group_id[i] == group_id[j])",
"+ ans[i] = (group_cnt[group_id[i]] - 1) - n_neighbor - n_block",
"+ print((\" \".join(map(str, ans))))"
] | false | 0.048611 | 0.046478 | 1.045896 | [
"s063977440",
"s587288654"
] |