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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u588341295 | p02852 | python | s404248203 | s557608397 | 224 | 139 | 50,800 | 6,408 | Accepted | Accepted | 37.95 | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, M = MAP()
S = input()[::-1]
def check(a):
for i in range(min(N, a+M), a, -1):
if S[i] == '0':
return i
return a
i = 0
ans = []
while i < N:
res = check(i)
if res == i:
print((-1))
exit()
ans.append(res-i)
i = res
print((*ans[::-1]))
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, M = MAP()
S = input()[::-1]
# ๅฐ็นaใใ่กใใๆๅคงไฝ็ฝฎใ่ฟใ
def check(a):
for i in range(min(N, a+M), a, -1):
if S[i] == '0':
return i
return a
i = 0
ans = []
while i < N:
# ่กใใใจใใใพใง่กใ
res = check(i)
# 1ๆญฉใๅใใชใใใฐNG
if res == i:
print((-1))
exit()
ans.append(res-i)
i = res
# ้ใใใใฃใใฎใงใใใ1ๅ้้ ใใฆๅบๅ
print((*ans[::-1]))
| 39 | 43 | 1,009 | 1,088 | # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, M = MAP()
S = input()[::-1]
def check(a):
for i in range(min(N, a + M), a, -1):
if S[i] == "0":
return i
return a
i = 0
ans = []
while i < N:
res = check(i)
if res == i:
print((-1))
exit()
ans.append(res - i)
i = res
print((*ans[::-1]))
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, M = MAP()
S = input()[::-1]
# ๅฐ็นaใใ่กใใๆๅคงไฝ็ฝฎใ่ฟใ
def check(a):
for i in range(min(N, a + M), a, -1):
if S[i] == "0":
return i
return a
i = 0
ans = []
while i < N:
# ่กใใใจใใใพใง่กใ
res = check(i)
# 1ๆญฉใๅใใชใใใฐNG
if res == i:
print((-1))
exit()
ans.append(res - i)
i = res
# ้ใใใใฃใใฎใงใใใ1ๅ้้ ใใฆๅบๅ
print((*ans[::-1]))
| false | 9.302326 | [
"-",
"-",
"+# ๅฐ็นaใใ่กใใๆๅคงไฝ็ฝฎใ่ฟใ",
"+ # ่กใใใจใใใพใง่กใ",
"+ # 1ๆญฉใๅใใชใใใฐNG",
"+# ้ใใใใฃใใฎใงใใใ1ๅ้้ ใใฆๅบๅ"
] | false | 0.040801 | 0.04119 | 0.990536 | [
"s404248203",
"s557608397"
] |
u470286613 | p03317 | python | s240192181 | s954107142 | 41 | 18 | 13,812 | 4,724 | Accepted | Accepted | 56.1 | import math
N, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))
print((math.ceil((N - 1) / (K - 1)))) | N,K=list(map(int,input().split()))
_=eval(input())
print(((N-2)//(K-1)+1)) | 6 | 3 | 128 | 62 | import math
N, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))
print((math.ceil((N - 1) / (K - 1))))
| N, K = list(map(int, input().split()))
_ = eval(input())
print(((N - 2) // (K - 1) + 1))
| false | 50 | [
"-import math",
"-",
"-A_list = list(map(int, input().split()))",
"-print((math.ceil((N - 1) / (K - 1))))",
"+_ = eval(input())",
"+print(((N - 2) // (K - 1) + 1))"
] | false | 0.043294 | 0.041225 | 1.050194 | [
"s240192181",
"s954107142"
] |
u793868662 | p02570 | python | s792555066 | s594746381 | 103 | 62 | 61,664 | 61,844 | Accepted | Accepted | 39.81 | def resolve():
d, t, s = list(map(int, input().split()))
if t >= d/s:
print("Yes")
else:
print("No")
resolve() | d, t, s = list(map(int, input().split()))
if t < d/s:
print("No")
else:
print("Yes") | 7 | 5 | 138 | 86 | def resolve():
d, t, s = list(map(int, input().split()))
if t >= d / s:
print("Yes")
else:
print("No")
resolve()
| d, t, s = list(map(int, input().split()))
if t < d / s:
print("No")
else:
print("Yes")
| false | 28.571429 | [
"-def resolve():",
"- d, t, s = list(map(int, input().split()))",
"- if t >= d / s:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"-",
"-",
"-resolve()",
"+d, t, s = list(map(int, input().split()))",
"+if t < d / s:",
"+ print(\"No\")",
"+else:",
"+ print(\"Yes\")"
] | false | 0.037115 | 0.044734 | 0.829663 | [
"s792555066",
"s594746381"
] |
u638456847 | p02727 | python | s648300028 | s675532960 | 358 | 244 | 23,272 | 23,200 | Accepted | Accepted | 31.84 | from heapq import heapify, heappop
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
X,Y,A,B,C = list(map(int, readline().split()))
p = [-int(i) for i in readline().split()]
q = [-int(i) for i in readline().split()]
r = [-int(i) for i in readline().split()]
p = sorted(p)[:X]
q = sorted(q)[:Y]
r.sort()
Q = p + q + r
heapify(Q)
ans = 0
for i in range(X+Y):
ans -= heappop(Q)
print(ans)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
X,Y,A,B,C = list(map(int, readline().split()))
p = [int(i) for i in readline().split()]
q = [int(i) for i in readline().split()]
r = [int(i) for i in readline().split()]
p.sort()
q.sort()
r.sort()
Q = p[A-X:] + q[B-Y:] + r
Q.sort(reverse=True)
ans = sum(Q[:X+Y])
print(ans)
if __name__ == "__main__":
main()
| 28 | 24 | 577 | 490 | from heapq import heapify, heappop
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
X, Y, A, B, C = list(map(int, readline().split()))
p = [-int(i) for i in readline().split()]
q = [-int(i) for i in readline().split()]
r = [-int(i) for i in readline().split()]
p = sorted(p)[:X]
q = sorted(q)[:Y]
r.sort()
Q = p + q + r
heapify(Q)
ans = 0
for i in range(X + Y):
ans -= heappop(Q)
print(ans)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
X, Y, A, B, C = list(map(int, readline().split()))
p = [int(i) for i in readline().split()]
q = [int(i) for i in readline().split()]
r = [int(i) for i in readline().split()]
p.sort()
q.sort()
r.sort()
Q = p[A - X :] + q[B - Y :] + r
Q.sort(reverse=True)
ans = sum(Q[: X + Y])
print(ans)
if __name__ == "__main__":
main()
| false | 14.285714 | [
"-from heapq import heapify, heappop",
"- p = [-int(i) for i in readline().split()]",
"- q = [-int(i) for i in readline().split()]",
"- r = [-int(i) for i in readline().split()]",
"- p = sorted(p)[:X]",
"- q = sorted(q)[:Y]",
"+ p = [int(i) for i in readline().split()]",
"+ q = [int(i) for i in readline().split()]",
"+ r = [int(i) for i in readline().split()]",
"+ p.sort()",
"+ q.sort()",
"- Q = p + q + r",
"- heapify(Q)",
"- ans = 0",
"- for i in range(X + Y):",
"- ans -= heappop(Q)",
"+ Q = p[A - X :] + q[B - Y :] + r",
"+ Q.sort(reverse=True)",
"+ ans = sum(Q[: X + Y])"
] | false | 0.068604 | 0.007239 | 9.476517 | [
"s648300028",
"s675532960"
] |
u088552457 | p03673 | python | s780755834 | s696237066 | 175 | 114 | 34,372 | 26,608 | Accepted | Accepted | 34.86 | n = int(eval(input()))
a = list(map(int, input().split()))
#b = []
#for ai in a:
# b.append(str(ai))
# b = list(reversed(b))
#print(' '.join(b))
if len(a) % 2 == 0:
even = []
odd = []
for i, ai in enumerate(a):
if (i + 1) % 2 == 0:
even.append(str(ai))
else:
odd.append(str(ai))
r = list(reversed(even))
answer = r + odd
print((' '.join(answer)))
else:
even = []
odd = []
for i, ai in enumerate(a):
if (i + 1) % 2 == 0:
even.append(str(ai))
else:
odd.append(str(ai))
r = list(reversed(odd))
answer = r + even
print((' '.join(answer))) | def main():
n = int(eval(input()))
a = list(input_list_str())
index = n - 1
ans = [a[index]]
is_add = False
for i in range(n-1):
if is_add:
index += 2
else:
index -= 2
if index < 0:
index = 0
is_add = True
ans.append(a[index])
if index == 0 and is_add is False:
index = -1
is_add = True
print((' '.join(ans)))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
import math
import fractions
from functools import reduce
main() | 30 | 48 | 620 | 879 | n = int(eval(input()))
a = list(map(int, input().split()))
# b = []
# for ai in a:
# b.append(str(ai))
# b = list(reversed(b))
# print(' '.join(b))
if len(a) % 2 == 0:
even = []
odd = []
for i, ai in enumerate(a):
if (i + 1) % 2 == 0:
even.append(str(ai))
else:
odd.append(str(ai))
r = list(reversed(even))
answer = r + odd
print((" ".join(answer)))
else:
even = []
odd = []
for i, ai in enumerate(a):
if (i + 1) % 2 == 0:
even.append(str(ai))
else:
odd.append(str(ai))
r = list(reversed(odd))
answer = r + even
print((" ".join(answer)))
| def main():
n = int(eval(input()))
a = list(input_list_str())
index = n - 1
ans = [a[index]]
is_add = False
for i in range(n - 1):
if is_add:
index += 2
else:
index -= 2
if index < 0:
index = 0
is_add = True
ans.append(a[index])
if index == 0 and is_add is False:
index = -1
is_add = True
print((" ".join(ans)))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
import math
import fractions
from functools import reduce
main()
| false | 37.5 | [
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-# b = []",
"-# for ai in a:",
"-# b.append(str(ai))",
"-# b = list(reversed(b))",
"-# print(' '.join(b))",
"-if len(a) % 2 == 0:",
"- even = []",
"- odd = []",
"- for i, ai in enumerate(a):",
"- if (i + 1) % 2 == 0:",
"- even.append(str(ai))",
"+def main():",
"+ n = int(eval(input()))",
"+ a = list(input_list_str())",
"+ index = n - 1",
"+ ans = [a[index]]",
"+ is_add = False",
"+ for i in range(n - 1):",
"+ if is_add:",
"+ index += 2",
"- odd.append(str(ai))",
"- r = list(reversed(even))",
"- answer = r + odd",
"- print((\" \".join(answer)))",
"-else:",
"- even = []",
"- odd = []",
"- for i, ai in enumerate(a):",
"- if (i + 1) % 2 == 0:",
"- even.append(str(ai))",
"- else:",
"- odd.append(str(ai))",
"- r = list(reversed(odd))",
"- answer = r + even",
"- print((\" \".join(answer)))",
"+ index -= 2",
"+ if index < 0:",
"+ index = 0",
"+ is_add = True",
"+ ans.append(a[index])",
"+ if index == 0 and is_add is False:",
"+ index = -1",
"+ is_add = True",
"+ print((\" \".join(ans)))",
"+",
"+",
"+def input_list():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def input_list_str():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+def lcm_base(x, y):",
"+ return (x * y) // fractions.gcd(x, y)",
"+",
"+",
"+def lcm_list(numbers):",
"+ return reduce(lcm_base, numbers, 1)",
"+",
"+",
"+def gcd(*numbers):",
"+ return reduce(fractions.gcd, numbers)",
"+",
"+",
"+def gcd_list(numbers):",
"+ return reduce(fractions.gcd, numbers)",
"+",
"+",
"+import math",
"+import fractions",
"+from functools import reduce",
"+",
"+main()"
] | false | 0.041816 | 0.048569 | 0.860966 | [
"s780755834",
"s696237066"
] |
u025595730 | p02898 | python | s432096576 | s589606469 | 177 | 67 | 20,888 | 11,908 | Accepted | Accepted | 62.15 | # coding: utf-8
import numpy as np
def main():
_, limit = list(map(int, input().split(' ')))
heights = np.array(list(map(int, input().split(' '))))
print((np.count_nonzero(heights >= limit)))
return 0
if __name__ == '__main__':
main()
| # coding: utf-8
def main():
n, limit = list(map(int, input().split(' ')))
heights = list(map(int, input().split(' ')))
heights = sorted(heights, reverse=True)
nakama_count = 0
for height in heights:
if height >= limit:
nakama_count += 1
else:
break
print(nakama_count)
return 0
if __name__ == '__main__':
main()
| 16 | 23 | 277 | 416 | # coding: utf-8
import numpy as np
def main():
_, limit = list(map(int, input().split(" ")))
heights = np.array(list(map(int, input().split(" "))))
print((np.count_nonzero(heights >= limit)))
return 0
if __name__ == "__main__":
main()
| # coding: utf-8
def main():
n, limit = list(map(int, input().split(" ")))
heights = list(map(int, input().split(" ")))
heights = sorted(heights, reverse=True)
nakama_count = 0
for height in heights:
if height >= limit:
nakama_count += 1
else:
break
print(nakama_count)
return 0
if __name__ == "__main__":
main()
| false | 30.434783 | [
"-import numpy as np",
"-",
"-",
"- _, limit = list(map(int, input().split(\" \")))",
"- heights = np.array(list(map(int, input().split(\" \"))))",
"- print((np.count_nonzero(heights >= limit)))",
"+ n, limit = list(map(int, input().split(\" \")))",
"+ heights = list(map(int, input().split(\" \")))",
"+ heights = sorted(heights, reverse=True)",
"+ nakama_count = 0",
"+ for height in heights:",
"+ if height >= limit:",
"+ nakama_count += 1",
"+ else:",
"+ break",
"+ print(nakama_count)"
] | false | 0.211394 | 0.036886 | 5.73105 | [
"s432096576",
"s589606469"
] |
u043048943 | p03078 | python | s547593095 | s851383304 | 1,005 | 491 | 147,760 | 105,176 | Accepted | Accepted | 51.14 | #coding:utf-8
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True
def main():
X,Y,Z,K = LMIIS()
A = LMIIS()
B = LMIIS()
C = LMIIS()
AB = []
for a in A:
for b in B:
AB.append(a+b)
AB.sort(reverse=True)
ABC = []
for ab in AB[:K]:
for c in C:
ABC.append(ab+c)
ABC.sort(reverse=True)
for i in range(K):
print(ABC[i])
pass
if __name__ == '__main__':
main()
| #coding:utf-8
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True
def main():
X,Y,Z,K = LMIIS()
A = LMIIS()
B = LMIIS()
C = LMIIS()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = []
for ai in range(X):
for bi in range(Y):
if ai * bi > K:
break
for ci in range(Z):
if ai * bi * ci > K:
break
ans.append(A[ai]+B[bi]+C[ci])
ans.sort(reverse=True)
for i in range(K):
print(ans[i])
if __name__ == '__main__':
main()
| 35 | 40 | 697 | 862 | # coding:utf-8
import sys
sys.setrecursionlimit(2**31 - 1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda: list(map(int, input().split()))
II = lambda: int(input())
dbg = lambda *something: print(*something) if DEBUG is True else 0
DEBUG = True
def main():
X, Y, Z, K = LMIIS()
A = LMIIS()
B = LMIIS()
C = LMIIS()
AB = []
for a in A:
for b in B:
AB.append(a + b)
AB.sort(reverse=True)
ABC = []
for ab in AB[:K]:
for c in C:
ABC.append(ab + c)
ABC.sort(reverse=True)
for i in range(K):
print(ABC[i])
pass
if __name__ == "__main__":
main()
| # coding:utf-8
import sys
sys.setrecursionlimit(2**31 - 1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda: list(map(int, input().split()))
II = lambda: int(input())
dbg = lambda *something: print(*something) if DEBUG is True else 0
DEBUG = True
def main():
X, Y, Z, K = LMIIS()
A = LMIIS()
B = LMIIS()
C = LMIIS()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = []
for ai in range(X):
for bi in range(Y):
if ai * bi > K:
break
for ci in range(Z):
if ai * bi * ci > K:
break
ans.append(A[ai] + B[bi] + C[ci])
ans.sort(reverse=True)
for i in range(K):
print(ans[i])
if __name__ == "__main__":
main()
| false | 12.5 | [
"- AB = []",
"- for a in A:",
"- for b in B:",
"- AB.append(a + b)",
"- AB.sort(reverse=True)",
"- ABC = []",
"- for ab in AB[:K]:",
"- for c in C:",
"- ABC.append(ab + c)",
"- ABC.sort(reverse=True)",
"+ A.sort(reverse=True)",
"+ B.sort(reverse=True)",
"+ C.sort(reverse=True)",
"+ ans = []",
"+ for ai in range(X):",
"+ for bi in range(Y):",
"+ if ai * bi > K:",
"+ break",
"+ for ci in range(Z):",
"+ if ai * bi * ci > K:",
"+ break",
"+ ans.append(A[ai] + B[bi] + C[ci])",
"+ ans.sort(reverse=True)",
"- print(ABC[i])",
"- pass",
"+ print(ans[i])"
] | false | 0.04765 | 0.061578 | 0.773822 | [
"s547593095",
"s851383304"
] |
u075012704 | p02937 | python | s346430775 | s315516337 | 294 | 124 | 54,232 | 8,164 | Accepted | Accepted | 57.82 | from collections import defaultdict
from bisect import bisect_right
S = eval(input())
T = eval(input())
s_set = set(list(S))
t_set = set(list(T))
if not t_set <= s_set:
print((-1))
exit()
s_position = defaultdict(list)
for i, s in enumerate(S):
s_position[s].append(i)
now_position = -1
t_position = [-1] * len(T)
for i, t in enumerate(T):
ti = bisect_right(s_position[t], now_position)
if ti >= len(s_position[t]):
ti = 0
t_position[i] = s_position[t][ti]
now_position = s_position[t][ti]
ans = 0
for i in range(len(T) - 1):
if t_position[i] >= t_position[i + 1]:
ans += len(S)
print((ans + t_position[-1] + 1))
| from collections import defaultdict
from bisect import bisect_right
S = eval(input())
T = eval(input())
NS = len(S)
# ๆงๆไธๅฏ
if set(list(T)) - set(list(S)):
print((-1))
exit()
# ๅๆๅญใฎๅบ็พๅ ดๆใ่จ้ฒ
D = defaultdict(list)
for i, s in enumerate(S):
D[s].append(i)
ans = 0
marker = -1
for t in T:
target_char_appeared_indexes = D[t]
bi = bisect_right(target_char_appeared_indexes, marker)
# ใใไธๅจใใฆใใชใใจ่ฆใคใใใใชใ
if bi == len(target_char_appeared_indexes):
ans += NS
marker = target_char_appeared_indexes[0]
else:
marker = target_char_appeared_indexes[bi]
# 0-indexedใฎใใ+1
print((ans + marker + 1))
| 35 | 33 | 689 | 660 | from collections import defaultdict
from bisect import bisect_right
S = eval(input())
T = eval(input())
s_set = set(list(S))
t_set = set(list(T))
if not t_set <= s_set:
print((-1))
exit()
s_position = defaultdict(list)
for i, s in enumerate(S):
s_position[s].append(i)
now_position = -1
t_position = [-1] * len(T)
for i, t in enumerate(T):
ti = bisect_right(s_position[t], now_position)
if ti >= len(s_position[t]):
ti = 0
t_position[i] = s_position[t][ti]
now_position = s_position[t][ti]
ans = 0
for i in range(len(T) - 1):
if t_position[i] >= t_position[i + 1]:
ans += len(S)
print((ans + t_position[-1] + 1))
| from collections import defaultdict
from bisect import bisect_right
S = eval(input())
T = eval(input())
NS = len(S)
# ๆงๆไธๅฏ
if set(list(T)) - set(list(S)):
print((-1))
exit()
# ๅๆๅญใฎๅบ็พๅ ดๆใ่จ้ฒ
D = defaultdict(list)
for i, s in enumerate(S):
D[s].append(i)
ans = 0
marker = -1
for t in T:
target_char_appeared_indexes = D[t]
bi = bisect_right(target_char_appeared_indexes, marker)
# ใใไธๅจใใฆใใชใใจ่ฆใคใใใใชใ
if bi == len(target_char_appeared_indexes):
ans += NS
marker = target_char_appeared_indexes[0]
else:
marker = target_char_appeared_indexes[bi]
# 0-indexedใฎใใ+1
print((ans + marker + 1))
| false | 5.714286 | [
"-s_set = set(list(S))",
"-t_set = set(list(T))",
"-if not t_set <= s_set:",
"+NS = len(S)",
"+# ๆงๆไธๅฏ",
"+if set(list(T)) - set(list(S)):",
"-s_position = defaultdict(list)",
"+# ๅๆๅญใฎๅบ็พๅ ดๆใ่จ้ฒ",
"+D = defaultdict(list)",
"- s_position[s].append(i)",
"-now_position = -1",
"-t_position = [-1] * len(T)",
"-for i, t in enumerate(T):",
"- ti = bisect_right(s_position[t], now_position)",
"- if ti >= len(s_position[t]):",
"- ti = 0",
"- t_position[i] = s_position[t][ti]",
"- now_position = s_position[t][ti]",
"+ D[s].append(i)",
"-for i in range(len(T) - 1):",
"- if t_position[i] >= t_position[i + 1]:",
"- ans += len(S)",
"-print((ans + t_position[-1] + 1))",
"+marker = -1",
"+for t in T:",
"+ target_char_appeared_indexes = D[t]",
"+ bi = bisect_right(target_char_appeared_indexes, marker)",
"+ # ใใไธๅจใใฆใใชใใจ่ฆใคใใใใชใ",
"+ if bi == len(target_char_appeared_indexes):",
"+ ans += NS",
"+ marker = target_char_appeared_indexes[0]",
"+ else:",
"+ marker = target_char_appeared_indexes[bi]",
"+# 0-indexedใฎใใ+1",
"+print((ans + marker + 1))"
] | false | 0.042971 | 0.035482 | 1.211059 | [
"s346430775",
"s315516337"
] |
u970449052 | p02975 | python | s311817807 | s813195106 | 59 | 51 | 14,212 | 14,116 | Accepted | Accepted | 13.56 | n=int(eval(input()))
al=list(map(int,input().split()))
t=0
for i in range(n):
t^=al[i]
if t==0:
print('Yes')
else:
print('No') | n=int(eval(input()))
al=list(map(int,input().split()))
t=0
for a in al:
t^=a
print(('Yes' if t==0 else 'No')) | 9 | 6 | 140 | 110 | n = int(eval(input()))
al = list(map(int, input().split()))
t = 0
for i in range(n):
t ^= al[i]
if t == 0:
print("Yes")
else:
print("No")
| n = int(eval(input()))
al = list(map(int, input().split()))
t = 0
for a in al:
t ^= a
print(("Yes" if t == 0 else "No"))
| false | 33.333333 | [
"-for i in range(n):",
"- t ^= al[i]",
"-if t == 0:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+for a in al:",
"+ t ^= a",
"+print((\"Yes\" if t == 0 else \"No\"))"
] | false | 0.075089 | 0.07662 | 0.980026 | [
"s311817807",
"s813195106"
] |
u144913062 | p03546 | python | s892537247 | s633796510 | 205 | 185 | 41,564 | 40,284 | Accepted | Accepted | 9.76 | import sys
input = sys.stdin.readline
def floyd_warshall(dist):
v = len(dist)
for k in range(v):
for i in range(v):
for j in range(v):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
H, W = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
floyd_warshall(c)
A = [list(map(int, input().split())) for _ in range(H)]
ans = 0
for row in A:
for a in row:
if a != -1:
ans += c[a][1]
print(ans)
| import sys
input = sys.stdin.readline
def floyd_warshall(dist):
v = len(dist)
for k in range(v):
for i in range(v):
for j in range(v):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
H, W = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
floyd_warshall(c)
A = [list(map(int, input().split())) for _ in range(H)]
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1:
ans += c[A[i][j]][1]
print(ans) | 20 | 20 | 516 | 537 | import sys
input = sys.stdin.readline
def floyd_warshall(dist):
v = len(dist)
for k in range(v):
for i in range(v):
for j in range(v):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
H, W = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
floyd_warshall(c)
A = [list(map(int, input().split())) for _ in range(H)]
ans = 0
for row in A:
for a in row:
if a != -1:
ans += c[a][1]
print(ans)
| import sys
input = sys.stdin.readline
def floyd_warshall(dist):
v = len(dist)
for k in range(v):
for i in range(v):
for j in range(v):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
H, W = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
floyd_warshall(c)
A = [list(map(int, input().split())) for _ in range(H)]
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1:
ans += c[A[i][j]][1]
print(ans)
| false | 0 | [
"-for row in A:",
"- for a in row:",
"- if a != -1:",
"- ans += c[a][1]",
"+for i in range(H):",
"+ for j in range(W):",
"+ if A[i][j] != -1:",
"+ ans += c[A[i][j]][1]"
] | false | 0.035905 | 0.037818 | 0.949415 | [
"s892537247",
"s633796510"
] |
u957167787 | p03329 | python | s343045321 | s381273912 | 609 | 563 | 3,956 | 3,864 | Accepted | Accepted | 7.55 | # ๅ็่จ็ปๆณ(dp)
# dp[N](ๆฐๅ)ใๆฑใใใใ
# dp[0]ใใdp[N-1]ใฏๆข็ฅ(ๆๅฐใจใชใใฃใฆใใ)ใจใใใ
# dp[N] = (dp[N-1] + 1) , (dp[N-6] + 1) , ... , (dp[N-6^i] + 1) , (dp[N-9] + 1) , ... , (dp[N-9^j] + 1)ใฎไธญใใๆๅฐใฎใใฎใ้ธในใฐ่ฏใ
# ใใญใฐใฉใ ไธใงใฏ0ใใNใพใงๅใใฆ1ใคใใคๆๅฐๅใใใฐ่ฏใ
N = int(eval(input()))
INF = 10**7
dp = [INF for _ in range(N+1)] # 0ใใNใพใง
dp[0] = 0 # 0็ช็ฎไปฅๅคใฏๅคงใใๅคใซๅๆๅ
for i in range(1, N+1):
dp[i] = dp[i-1] + 1
power = 6
while power <= N: # N-6^xใ้่ฒ ใฎ็ฏๅฒใง
dp[i] = min(dp[i], dp[i - power] + 1)
power *= 6
power = 9
while power <= N: # N-9^xใ้่ฒ ใฎ็ฏๅฒใง
dp[i] = min(dp[i], dp[i - power] + 1)
power *= 9
print((dp[N]))
"""
# ๅคงใใๆนใใ่ฒชๆฌฒใซๅใใฎใฏ่ชคใ(ไพใใฐ12ใซใคใใฆใ12=9+1+1+1ใซใชใใ12=6+6ใฎๆนใใใๅฐใชใ)
N = int(input())
money = [1]
for i in range(1, 100):
if 6**i <= N:
money.append(6**i)
if 9**i <= N:
money.append(9**i)
if 6**i > N and 9**i > N:
break
money.sort()
money.reverse()
zannkinn = N
ans = 0
for i in range(len(money)):
ans += zannkinn//money[i]
zannkinn = zannkinn % money[i]
if zannkinn == 0:
break
print(ans)
""" | N = int(eval(input()))
dp = [10**9 for _ in range(N+1)] # 0ๅใใNๅใพใงใฎใชในใ
dp[0] = 0
for i in range(1, N+1): # iๅๆใๆๅฐๆๆฐใๅ
ฅใใ
dp[i] = min(dp[i], dp[i-1] + 1)
power_6 = 6
while i >= power_6:
dp[i] = min(dp[i], dp[i-power_6] + 1)
power_6 *= 6
power_9 = 9
while i >= power_9:
dp[i] = min(dp[i], dp[i-power_9] + 1)
power_9 *= 9
ans = dp[N]
print(ans)
| 50 | 20 | 1,104 | 411 | # ๅ็่จ็ปๆณ(dp)
# dp[N](ๆฐๅ)ใๆฑใใใใ
# dp[0]ใใdp[N-1]ใฏๆข็ฅ(ๆๅฐใจใชใใฃใฆใใ)ใจใใใ
# dp[N] = (dp[N-1] + 1) , (dp[N-6] + 1) , ... , (dp[N-6^i] + 1) , (dp[N-9] + 1) , ... , (dp[N-9^j] + 1)ใฎไธญใใๆๅฐใฎใใฎใ้ธในใฐ่ฏใ
# ใใญใฐใฉใ ไธใงใฏ0ใใNใพใงๅใใฆ1ใคใใคๆๅฐๅใใใฐ่ฏใ
N = int(eval(input()))
INF = 10**7
dp = [INF for _ in range(N + 1)] # 0ใใNใพใง
dp[0] = 0 # 0็ช็ฎไปฅๅคใฏๅคงใใๅคใซๅๆๅ
for i in range(1, N + 1):
dp[i] = dp[i - 1] + 1
power = 6
while power <= N: # N-6^xใ้่ฒ ใฎ็ฏๅฒใง
dp[i] = min(dp[i], dp[i - power] + 1)
power *= 6
power = 9
while power <= N: # N-9^xใ้่ฒ ใฎ็ฏๅฒใง
dp[i] = min(dp[i], dp[i - power] + 1)
power *= 9
print((dp[N]))
"""
# ๅคงใใๆนใใ่ฒชๆฌฒใซๅใใฎใฏ่ชคใ(ไพใใฐ12ใซใคใใฆใ12=9+1+1+1ใซใชใใ12=6+6ใฎๆนใใใๅฐใชใ)
N = int(input())
money = [1]
for i in range(1, 100):
if 6**i <= N:
money.append(6**i)
if 9**i <= N:
money.append(9**i)
if 6**i > N and 9**i > N:
break
money.sort()
money.reverse()
zannkinn = N
ans = 0
for i in range(len(money)):
ans += zannkinn//money[i]
zannkinn = zannkinn % money[i]
if zannkinn == 0:
break
print(ans)
"""
| N = int(eval(input()))
dp = [10**9 for _ in range(N + 1)] # 0ๅใใNๅใพใงใฎใชในใ
dp[0] = 0
for i in range(1, N + 1): # iๅๆใๆๅฐๆๆฐใๅ
ฅใใ
dp[i] = min(dp[i], dp[i - 1] + 1)
power_6 = 6
while i >= power_6:
dp[i] = min(dp[i], dp[i - power_6] + 1)
power_6 *= 6
power_9 = 9
while i >= power_9:
dp[i] = min(dp[i], dp[i - power_9] + 1)
power_9 *= 9
ans = dp[N]
print(ans)
| false | 60 | [
"-# ๅ็่จ็ปๆณ(dp)",
"-# dp[N](ๆฐๅ)ใๆฑใใใใ",
"-# dp[0]ใใdp[N-1]ใฏๆข็ฅ(ๆๅฐใจใชใใฃใฆใใ)ใจใใใ",
"-# dp[N] = (dp[N-1] + 1) , (dp[N-6] + 1) , ... , (dp[N-6^i] + 1) , (dp[N-9] + 1) , ... , (dp[N-9^j] + 1)ใฎไธญใใๆๅฐใฎใใฎใ้ธในใฐ่ฏใ",
"-# ใใญใฐใฉใ ไธใงใฏ0ใใNใพใงๅใใฆ1ใคใใคๆๅฐๅใใใฐ่ฏใ",
"-INF = 10**7",
"-dp = [INF for _ in range(N + 1)] # 0ใใNใพใง",
"-dp[0] = 0 # 0็ช็ฎไปฅๅคใฏๅคงใใๅคใซๅๆๅ",
"-for i in range(1, N + 1):",
"- dp[i] = dp[i - 1] + 1",
"- power = 6",
"- while power <= N: # N-6^xใ้่ฒ ใฎ็ฏๅฒใง",
"- dp[i] = min(dp[i], dp[i - power] + 1)",
"- power *= 6",
"- power = 9",
"- while power <= N: # N-9^xใ้่ฒ ใฎ็ฏๅฒใง",
"- dp[i] = min(dp[i], dp[i - power] + 1)",
"- power *= 9",
"-print((dp[N]))",
"-\"\"\"",
"-# ๅคงใใๆนใใ่ฒชๆฌฒใซๅใใฎใฏ่ชคใ(ไพใใฐ12ใซใคใใฆใ12=9+1+1+1ใซใชใใ12=6+6ใฎๆนใใใๅฐใชใ)",
"-N = int(input())",
"-money = [1]",
"-for i in range(1, 100):",
"- if 6**i <= N:",
"- money.append(6**i)",
"- if 9**i <= N:",
"- money.append(9**i)",
"- if 6**i > N and 9**i > N:",
"- break",
"-money.sort()",
"-money.reverse()",
"-zannkinn = N",
"-ans = 0",
"-for i in range(len(money)):",
"- ans += zannkinn//money[i]",
"- zannkinn = zannkinn % money[i]",
"- if zannkinn == 0:",
"- break",
"+dp = [10**9 for _ in range(N + 1)] # 0ๅใใNๅใพใงใฎใชในใ",
"+dp[0] = 0",
"+for i in range(1, N + 1): # iๅๆใๆๅฐๆๆฐใๅ
ฅใใ",
"+ dp[i] = min(dp[i], dp[i - 1] + 1)",
"+ power_6 = 6",
"+ while i >= power_6:",
"+ dp[i] = min(dp[i], dp[i - power_6] + 1)",
"+ power_6 *= 6",
"+ power_9 = 9",
"+ while i >= power_9:",
"+ dp[i] = min(dp[i], dp[i - power_9] + 1)",
"+ power_9 *= 9",
"+ans = dp[N]",
"-\"\"\""
] | false | 0.101746 | 0.121674 | 0.836224 | [
"s343045321",
"s381273912"
] |
u260980560 | p02377 | python | s967163882 | s718903855 | 80 | 40 | 8,024 | 5,944 | Accepted | Accepted | 50 | class MinCostFlow:
def __init__(self, n):
self.n = n
self.G = [[] for i in range(n)]
def addEdge(self, f, t, cap, cost):
# [to, cap, cost, rev]
self.G[f].append([t, cap, cost, len(self.G[t])])
self.G[t].append([f, 0, -cost, len(self.G[f])-1])
def minCostFlow(self, s, t, f):
n = self.n
G = self.G
prevv = [0]*n; preve = [0]*n
INF = 10**9+7
res = 0
while f:
dist = [INF]*n
dist[s] = 0
update = 1
while update:
update = 0
for v in range(n):
if dist[v] == INF:
continue
gv = G[v]
for i in range(len(gv)):
to, cap, cost, rev = gv[i]
if cap > 0 and dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
prevv[to] = v; preve[to] = i
update = 1
if dist[t] == INF:
return -1
d = f; v = t
while v != s:
d = min(d, G[prevv[v]][preve[v]][1])
v = prevv[v]
f -= d
res += d * dist[t]
v = t
while v != s:
e = G[prevv[v]][preve[v]]
e[1] -= d
G[v][e[3]][1] += d
v = prevv[v]
return res
n, m, f = list(map(int, input().split()))
graph = MinCostFlow(n)
for i in range(m):
u, v, c, d = list(map(int, input().split()))
graph.addEdge(u, v, c, d)
print((graph.minCostFlow(0, n-1, f))) |
from heapq import heappush, heappop
class MinCostFlow:
INF = 10**18
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap, cost):
G = self.G
G[fr].append([to, cap, cost, len(G[to])])
G[to].append([fr, 0, -cost, len(G[fr])-1])
def flow(self, s, t, f):
N = self.N; G = self.G
INF = MinCostFlow.INF
res = 0
H = [0]*N
prv_v = [0]*N
prv_e = [0]*N
while f:
dist = [INF]*N
dist[s] = 0
que = [(0, s)]
while que:
c, v = heappop(que)
if dist[v] < c:
continue
for i, (w, cap, cost, rev) in enumerate(G[v]):
if cap > 0 and dist[w] > dist[v] + cost + H[v] - H[w]:
dist[w] = r = dist[v] + cost + H[v] - H[w]
prv_v[w] = v
prv_e[w] = i
heappush(que, (r, w))
if dist[t] == INF:
return -1
for i in range(N):
H[i] += dist[i]
d = f; v = t
while v != s:
d = min(d, G[prv_v[v]][prv_e[v]][1])
v = prv_v[v]
f -= d
res += d * H[t]
v = t
while v != s:
e = G[prv_v[v]][prv_e[v]]
e[1] -= d
G[v][e[3]][1] += d
v = prv_v[v]
return res
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N, M, F = list(map(int, readline().split()))
mcf = MinCostFlow(N)
for i in range(M):
u, v, c, d = list(map(int, readline().split()))
mcf.add_edge(u, v, c, d)
write("%d\n" % mcf.flow(0, N-1, F))
| 56 | 69 | 1,714 | 1,860 | class MinCostFlow:
def __init__(self, n):
self.n = n
self.G = [[] for i in range(n)]
def addEdge(self, f, t, cap, cost):
# [to, cap, cost, rev]
self.G[f].append([t, cap, cost, len(self.G[t])])
self.G[t].append([f, 0, -cost, len(self.G[f]) - 1])
def minCostFlow(self, s, t, f):
n = self.n
G = self.G
prevv = [0] * n
preve = [0] * n
INF = 10**9 + 7
res = 0
while f:
dist = [INF] * n
dist[s] = 0
update = 1
while update:
update = 0
for v in range(n):
if dist[v] == INF:
continue
gv = G[v]
for i in range(len(gv)):
to, cap, cost, rev = gv[i]
if cap > 0 and dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
prevv[to] = v
preve[to] = i
update = 1
if dist[t] == INF:
return -1
d = f
v = t
while v != s:
d = min(d, G[prevv[v]][preve[v]][1])
v = prevv[v]
f -= d
res += d * dist[t]
v = t
while v != s:
e = G[prevv[v]][preve[v]]
e[1] -= d
G[v][e[3]][1] += d
v = prevv[v]
return res
n, m, f = list(map(int, input().split()))
graph = MinCostFlow(n)
for i in range(m):
u, v, c, d = list(map(int, input().split()))
graph.addEdge(u, v, c, d)
print((graph.minCostFlow(0, n - 1, f)))
| from heapq import heappush, heappop
class MinCostFlow:
INF = 10**18
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap, cost):
G = self.G
G[fr].append([to, cap, cost, len(G[to])])
G[to].append([fr, 0, -cost, len(G[fr]) - 1])
def flow(self, s, t, f):
N = self.N
G = self.G
INF = MinCostFlow.INF
res = 0
H = [0] * N
prv_v = [0] * N
prv_e = [0] * N
while f:
dist = [INF] * N
dist[s] = 0
que = [(0, s)]
while que:
c, v = heappop(que)
if dist[v] < c:
continue
for i, (w, cap, cost, rev) in enumerate(G[v]):
if cap > 0 and dist[w] > dist[v] + cost + H[v] - H[w]:
dist[w] = r = dist[v] + cost + H[v] - H[w]
prv_v[w] = v
prv_e[w] = i
heappush(que, (r, w))
if dist[t] == INF:
return -1
for i in range(N):
H[i] += dist[i]
d = f
v = t
while v != s:
d = min(d, G[prv_v[v]][prv_e[v]][1])
v = prv_v[v]
f -= d
res += d * H[t]
v = t
while v != s:
e = G[prv_v[v]][prv_e[v]]
e[1] -= d
G[v][e[3]][1] += d
v = prv_v[v]
return res
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N, M, F = list(map(int, readline().split()))
mcf = MinCostFlow(N)
for i in range(M):
u, v, c, d = list(map(int, readline().split()))
mcf.add_edge(u, v, c, d)
write("%d\n" % mcf.flow(0, N - 1, F))
| false | 18.84058 | [
"+from heapq import heappush, heappop",
"+",
"+",
"- def __init__(self, n):",
"- self.n = n",
"- self.G = [[] for i in range(n)]",
"+ INF = 10**18",
"- def addEdge(self, f, t, cap, cost):",
"- # [to, cap, cost, rev]",
"- self.G[f].append([t, cap, cost, len(self.G[t])])",
"- self.G[t].append([f, 0, -cost, len(self.G[f]) - 1])",
"+ def __init__(self, N):",
"+ self.N = N",
"+ self.G = [[] for i in range(N)]",
"- def minCostFlow(self, s, t, f):",
"- n = self.n",
"+ def add_edge(self, fr, to, cap, cost):",
"- prevv = [0] * n",
"- preve = [0] * n",
"- INF = 10**9 + 7",
"+ G[fr].append([to, cap, cost, len(G[to])])",
"+ G[to].append([fr, 0, -cost, len(G[fr]) - 1])",
"+",
"+ def flow(self, s, t, f):",
"+ N = self.N",
"+ G = self.G",
"+ INF = MinCostFlow.INF",
"+ H = [0] * N",
"+ prv_v = [0] * N",
"+ prv_e = [0] * N",
"- dist = [INF] * n",
"+ dist = [INF] * N",
"- update = 1",
"- while update:",
"- update = 0",
"- for v in range(n):",
"- if dist[v] == INF:",
"- continue",
"- gv = G[v]",
"- for i in range(len(gv)):",
"- to, cap, cost, rev = gv[i]",
"- if cap > 0 and dist[v] + cost < dist[to]:",
"- dist[to] = dist[v] + cost",
"- prevv[to] = v",
"- preve[to] = i",
"- update = 1",
"+ que = [(0, s)]",
"+ while que:",
"+ c, v = heappop(que)",
"+ if dist[v] < c:",
"+ continue",
"+ for i, (w, cap, cost, rev) in enumerate(G[v]):",
"+ if cap > 0 and dist[w] > dist[v] + cost + H[v] - H[w]:",
"+ dist[w] = r = dist[v] + cost + H[v] - H[w]",
"+ prv_v[w] = v",
"+ prv_e[w] = i",
"+ heappush(que, (r, w))",
"+ for i in range(N):",
"+ H[i] += dist[i]",
"- d = min(d, G[prevv[v]][preve[v]][1])",
"- v = prevv[v]",
"+ d = min(d, G[prv_v[v]][prv_e[v]][1])",
"+ v = prv_v[v]",
"- res += d * dist[t]",
"+ res += d * H[t]",
"- e = G[prevv[v]][preve[v]]",
"+ e = G[prv_v[v]][prv_e[v]]",
"- v = prevv[v]",
"+ v = prv_v[v]",
"-n, m, f = list(map(int, input().split()))",
"-graph = MinCostFlow(n)",
"-for i in range(m):",
"- u, v, c, d = list(map(int, input().split()))",
"- graph.addEdge(u, v, c, d)",
"-print((graph.minCostFlow(0, n - 1, f)))",
"+import sys",
"+",
"+readline = sys.stdin.readline",
"+write = sys.stdout.write",
"+N, M, F = list(map(int, readline().split()))",
"+mcf = MinCostFlow(N)",
"+for i in range(M):",
"+ u, v, c, d = list(map(int, readline().split()))",
"+ mcf.add_edge(u, v, c, d)",
"+write(\"%d\\n\" % mcf.flow(0, N - 1, F))"
] | false | 0.06804 | 0.075426 | 0.902083 | [
"s967163882",
"s718903855"
] |
u869790980 | p03080 | python | s265062210 | s388918024 | 363 | 334 | 85,668 | 85,856 | Accepted | Accepted | 7.99 | 4
'RRBR'
n = input()
import collections
cc = collections.Counter(input())
print('Yes' if cc['R'] > cc['B'] else 'No') | import collections
n,cc = int(input()), collections.Counter(input())
print('Yes' if cc['R'] > cc['B'] else 'No') | 7 | 3 | 131 | 121 | 4
"RRBR"
n = input()
import collections
cc = collections.Counter(input())
print("Yes" if cc["R"] > cc["B"] else "No")
| import collections
n, cc = int(input()), collections.Counter(input())
print("Yes" if cc["R"] > cc["B"] else "No")
| false | 57.142857 | [
"-4",
"-\"RRBR\"",
"-n = input()",
"-cc = collections.Counter(input())",
"+n, cc = int(input()), collections.Counter(input())"
] | false | 0.062437 | 0.037661 | 1.65787 | [
"s265062210",
"s388918024"
] |
u046187684 | p03401 | python | s639053303 | s052073088 | 285 | 193 | 14,048 | 16,700 | Accepted | Accepted | 32.28 | n = int(input().strip())
a = list(map(int, input().strip().split(" ")))
a.append(0)
a.insert(0, 0)
s = [abs(j - i) for i, j in zip(a, a[1:])]
base = sum(s)
for i in range(1, n + 1):
if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):
print(base)
elif max(a[i - 1], a[i + 1]) < a[i]:
print((base - 2 * abs(a[i] - max(a[i - 1], a[i + 1]))))
else:
print((base - 2 * abs(a[i] - min(a[i - 1], a[i + 1]))))
| def solve(string):
n, *a = list(map(int, string.split()))
a = [0] + a + [0]
base = sum([abs(j - i) for i, j in zip(a, a[1:])])
ans = []
for i in range(1, n + 1):
if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):
ans.append(str(base))
elif max(a[i - 1], a[i + 1]) < a[i]:
ans.append(str(base - 2 * abs(a[i] - max(a[i - 1], a[i + 1]))))
else:
ans.append(str(base - 2 * abs(a[i] - min(a[i - 1], a[i + 1]))))
return "\n".join(ans)
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
| 13 | 17 | 456 | 611 | n = int(input().strip())
a = list(map(int, input().strip().split(" ")))
a.append(0)
a.insert(0, 0)
s = [abs(j - i) for i, j in zip(a, a[1:])]
base = sum(s)
for i in range(1, n + 1):
if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):
print(base)
elif max(a[i - 1], a[i + 1]) < a[i]:
print((base - 2 * abs(a[i] - max(a[i - 1], a[i + 1]))))
else:
print((base - 2 * abs(a[i] - min(a[i - 1], a[i + 1]))))
| def solve(string):
n, *a = list(map(int, string.split()))
a = [0] + a + [0]
base = sum([abs(j - i) for i, j in zip(a, a[1:])])
ans = []
for i in range(1, n + 1):
if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):
ans.append(str(base))
elif max(a[i - 1], a[i + 1]) < a[i]:
ans.append(str(base - 2 * abs(a[i] - max(a[i - 1], a[i + 1]))))
else:
ans.append(str(base - 2 * abs(a[i] - min(a[i - 1], a[i + 1]))))
return "\n".join(ans)
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
| false | 23.529412 | [
"-n = int(input().strip())",
"-a = list(map(int, input().strip().split(\" \")))",
"-a.append(0)",
"-a.insert(0, 0)",
"-s = [abs(j - i) for i, j in zip(a, a[1:])]",
"-base = sum(s)",
"-for i in range(1, n + 1):",
"- if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):",
"- print(base)",
"- elif max(a[i - 1], a[i + 1]) < a[i]:",
"- print((base - 2 * abs(a[i] - max(a[i - 1], a[i + 1]))))",
"- else:",
"- print((base - 2 * abs(a[i] - min(a[i - 1], a[i + 1]))))",
"+def solve(string):",
"+ n, *a = list(map(int, string.split()))",
"+ a = [0] + a + [0]",
"+ base = sum([abs(j - i) for i, j in zip(a, a[1:])])",
"+ ans = []",
"+ for i in range(1, n + 1):",
"+ if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):",
"+ ans.append(str(base))",
"+ elif max(a[i - 1], a[i + 1]) < a[i]:",
"+ ans.append(str(base - 2 * abs(a[i] - max(a[i - 1], a[i + 1]))))",
"+ else:",
"+ ans.append(str(base - 2 * abs(a[i] - min(a[i - 1], a[i + 1]))))",
"+ return \"\\n\".join(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ print((solve(\"\\n\".join([eval(input()), eval(input())]))))"
] | false | 0.035728 | 0.124119 | 0.287856 | [
"s639053303",
"s052073088"
] |
u564589929 | p03087 | python | s174329852 | s428234478 | 1,007 | 277 | 52,708 | 6,436 | Accepted | Accepted | 72.49 | import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
INF = float('inf')
def solve():
n, q = MI()
S = eval(input())
ats = [0]
cnt = 0
for i in range(n-1):
j = i + 2
s = S[i:j]
# print(s)
if s == 'AC':
cnt += 1
ats.append(cnt)
# print(ats)
for _ in range(q):
l, r = MI1()
# print(S[l:r+1])
print((ats[r] - ats[l]))
if __name__ == '__main__':
solve()
| import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
INF = float('inf')
def solve():
n, q = MI()
S = eval(input())
ats = [0]
cnt = 0
for i in range(n-1):
j = i + 2
s = S[i:j]
# print(s)
if s == 'AC':
cnt += 1
ats.append(cnt)
# print(ats)
for _ in range(q):
l, r = MI1()
# print(S[l:r+1])
print((ats[r] - ats[l]))
if __name__ == '__main__':
solve()
| 36 | 36 | 825 | 823 | import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
INF = float("inf")
def solve():
n, q = MI()
S = eval(input())
ats = [0]
cnt = 0
for i in range(n - 1):
j = i + 2
s = S[i:j]
# print(s)
if s == "AC":
cnt += 1
ats.append(cnt)
# print(ats)
for _ in range(q):
l, r = MI1()
# print(S[l:r+1])
print((ats[r] - ats[l]))
if __name__ == "__main__":
solve()
| import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
INF = float("inf")
def solve():
n, q = MI()
S = eval(input())
ats = [0]
cnt = 0
for i in range(n - 1):
j = i + 2
s = S[i:j]
# print(s)
if s == "AC":
cnt += 1
ats.append(cnt)
# print(ats)
for _ in range(q):
l, r = MI1()
# print(S[l:r+1])
print((ats[r] - ats[l]))
if __name__ == "__main__":
solve()
| false | 0 | [
"-# input = sys.stdin.readline ####",
"+input = sys.stdin.readline ####"
] | false | 0.097643 | 0.083812 | 1.165023 | [
"s174329852",
"s428234478"
] |
u620480037 | p02844 | python | s523475551 | s592828948 | 989 | 409 | 67,956 | 98,720 | Accepted | Accepted | 58.65 | N=int(eval(input()))
import copy
S=list(eval(input()))
F=[]
E=[]
L=[0 for i in range(10)]
for i in range(N):
L[int(S[i])]=1
F.append(copy.deepcopy(L))
#print(F)
RS=S[::-1]
L=[0 for i in range(10)]
for i in range(N):
L[int(RS[i])]=1
E.append(copy.deepcopy(L))
E=E[::-1]
D={}
for i in range(1,N-1):
for f in range(10):
if F[i-1][f]==1:
for e in range(10):
if E[i+1][e]==1:
if (f,S[i],e) not in D:
D[(f,S[i],e)]=1
print((len(D)))
#print(E) | N=int(eval(input()))
S=list(eval(input()))
#print(S)
SETF=[set() for i in range(N)]
SETE=[0 for i in range(N)]
ANSSET=set()
SETF[0]=set()
SETF[0].add(S[0])
#print(SETF)
#print(type(SETF[1]))
import copy
for i in range(1,N):
SETF[i]=copy.deepcopy(SETF[i-1])
SETF[i].add(S[i])
#print(SETF)
SETE[0]=set()
SETE[0].add(S[-1])
#print(SETE)
for i in range(1,N):
SETE[i]=copy.deepcopy(SETE[i-1])
SETE[i].add(S[N-1-i])
SETE=SETE[::-1]
for i in range(1,N-1):
for f in SETF[i-1]:
for e in SETE[i+1]:
ANSSET.add(f+S[i]+e)
print((len(ANSSET)))
#print(SETE) | 27 | 30 | 553 | 600 | N = int(eval(input()))
import copy
S = list(eval(input()))
F = []
E = []
L = [0 for i in range(10)]
for i in range(N):
L[int(S[i])] = 1
F.append(copy.deepcopy(L))
# print(F)
RS = S[::-1]
L = [0 for i in range(10)]
for i in range(N):
L[int(RS[i])] = 1
E.append(copy.deepcopy(L))
E = E[::-1]
D = {}
for i in range(1, N - 1):
for f in range(10):
if F[i - 1][f] == 1:
for e in range(10):
if E[i + 1][e] == 1:
if (f, S[i], e) not in D:
D[(f, S[i], e)] = 1
print((len(D)))
# print(E)
| N = int(eval(input()))
S = list(eval(input()))
# print(S)
SETF = [set() for i in range(N)]
SETE = [0 for i in range(N)]
ANSSET = set()
SETF[0] = set()
SETF[0].add(S[0])
# print(SETF)
# print(type(SETF[1]))
import copy
for i in range(1, N):
SETF[i] = copy.deepcopy(SETF[i - 1])
SETF[i].add(S[i])
# print(SETF)
SETE[0] = set()
SETE[0].add(S[-1])
# print(SETE)
for i in range(1, N):
SETE[i] = copy.deepcopy(SETE[i - 1])
SETE[i].add(S[N - 1 - i])
SETE = SETE[::-1]
for i in range(1, N - 1):
for f in SETF[i - 1]:
for e in SETE[i + 1]:
ANSSET.add(f + S[i] + e)
print((len(ANSSET)))
# print(SETE)
| false | 10 | [
"+S = list(eval(input()))",
"+# print(S)",
"+SETF = [set() for i in range(N)]",
"+SETE = [0 for i in range(N)]",
"+ANSSET = set()",
"+SETF[0] = set()",
"+SETF[0].add(S[0])",
"+# print(SETF)",
"+# print(type(SETF[1]))",
"-S = list(eval(input()))",
"-F = []",
"-E = []",
"-L = [0 for i in range(10)]",
"-for i in range(N):",
"- L[int(S[i])] = 1",
"- F.append(copy.deepcopy(L))",
"-# print(F)",
"-RS = S[::-1]",
"-L = [0 for i in range(10)]",
"-for i in range(N):",
"- L[int(RS[i])] = 1",
"- E.append(copy.deepcopy(L))",
"-E = E[::-1]",
"-D = {}",
"+for i in range(1, N):",
"+ SETF[i] = copy.deepcopy(SETF[i - 1])",
"+ SETF[i].add(S[i])",
"+# print(SETF)",
"+SETE[0] = set()",
"+SETE[0].add(S[-1])",
"+# print(SETE)",
"+for i in range(1, N):",
"+ SETE[i] = copy.deepcopy(SETE[i - 1])",
"+ SETE[i].add(S[N - 1 - i])",
"+SETE = SETE[::-1]",
"- for f in range(10):",
"- if F[i - 1][f] == 1:",
"- for e in range(10):",
"- if E[i + 1][e] == 1:",
"- if (f, S[i], e) not in D:",
"- D[(f, S[i], e)] = 1",
"-print((len(D)))",
"-# print(E)",
"+ for f in SETF[i - 1]:",
"+ for e in SETE[i + 1]:",
"+ ANSSET.add(f + S[i] + e)",
"+print((len(ANSSET)))",
"+# print(SETE)"
] | false | 0.033283 | 0.055112 | 0.603916 | [
"s523475551",
"s592828948"
] |
u456353530 | p03077 | python | s153503667 | s792681586 | 164 | 17 | 38,384 | 3,064 | Accepted | Accepted | 89.63 | import math
N = int(eval(input()))
d = [int(eval(input())) for i in range(5)]
mi = d[0]
Ans = math.ceil(N / mi)
for i in d[1:]:
Ans += 1
if i < mi:
x = math.ceil(N / i) - math.ceil(N / mi)
Ans += x
mi = i
print(Ans) | N = int(eval(input()))
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
D = int(eval(input()))
E = int(eval(input()))
x = min(A, B, C, D, E)
ans = 4 + N // x
if N % x != 0:
ans += 1
print(ans) | 15 | 14 | 239 | 194 | import math
N = int(eval(input()))
d = [int(eval(input())) for i in range(5)]
mi = d[0]
Ans = math.ceil(N / mi)
for i in d[1:]:
Ans += 1
if i < mi:
x = math.ceil(N / i) - math.ceil(N / mi)
Ans += x
mi = i
print(Ans)
| N = int(eval(input()))
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
D = int(eval(input()))
E = int(eval(input()))
x = min(A, B, C, D, E)
ans = 4 + N // x
if N % x != 0:
ans += 1
print(ans)
| false | 6.666667 | [
"-import math",
"-",
"-d = [int(eval(input())) for i in range(5)]",
"-mi = d[0]",
"-Ans = math.ceil(N / mi)",
"-for i in d[1:]:",
"- Ans += 1",
"- if i < mi:",
"- x = math.ceil(N / i) - math.ceil(N / mi)",
"- Ans += x",
"- mi = i",
"-print(Ans)",
"+A = int(eval(input()))",
"+B = int(eval(input()))",
"+C = int(eval(input()))",
"+D = int(eval(input()))",
"+E = int(eval(input()))",
"+x = min(A, B, C, D, E)",
"+ans = 4 + N // x",
"+if N % x != 0:",
"+ ans += 1",
"+print(ans)"
] | false | 0.047954 | 0.043643 | 1.098776 | [
"s153503667",
"s792681586"
] |
u933341648 | p03380 | python | s593283381 | s299273108 | 105 | 71 | 14,052 | 14,056 | Accepted | Accepted | 32.38 | n = int(eval(input()))
arr = [int(a) for a in input().split()]
i = max(arr)
arr.remove(i)
j = min(arr, key=lambda a: min(abs(i//2-a), abs((i+1)//2-a)))
print((i, j))
| n = int(eval(input()))
arr = [int(a) for a in input().split()]
i = max(arr)
arr.remove(i)
j = min(arr, key=lambda a: abs(i/2-a))
print((i, j))
| 8 | 8 | 167 | 144 | n = int(eval(input()))
arr = [int(a) for a in input().split()]
i = max(arr)
arr.remove(i)
j = min(arr, key=lambda a: min(abs(i // 2 - a), abs((i + 1) // 2 - a)))
print((i, j))
| n = int(eval(input()))
arr = [int(a) for a in input().split()]
i = max(arr)
arr.remove(i)
j = min(arr, key=lambda a: abs(i / 2 - a))
print((i, j))
| false | 0 | [
"-j = min(arr, key=lambda a: min(abs(i // 2 - a), abs((i + 1) // 2 - a)))",
"+j = min(arr, key=lambda a: abs(i / 2 - a))"
] | false | 0.044166 | 0.045155 | 0.978113 | [
"s593283381",
"s299273108"
] |
u832039789 | p02897 | python | s038081912 | s012557637 | 265 | 17 | 64,108 | 2,940 | Accepted | Accepted | 93.58 | import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
if f:
print('Yes')
else:
print('No')
def Y(f):
if f:
print('YES')
else:
print('NO')
n = int(eval(input()))
if n % 2 == 0:
print((0.5))
else:
print(((n - n // 2) / n))
| n = int(eval(input()))
odd = 0
for i in range(1, n + 1):
if i % 2 == 1:
odd += 1
print((odd / n))
| 24 | 6 | 514 | 107 | import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
if f:
print("Yes")
else:
print("No")
def Y(f):
if f:
print("YES")
else:
print("NO")
n = int(eval(input()))
if n % 2 == 0:
print((0.5))
else:
print(((n - n // 2) / n))
| n = int(eval(input()))
odd = 0
for i in range(1, n + 1):
if i % 2 == 1:
odd += 1
print((odd / n))
| false | 75 | [
"-import sys",
"-from fractions import gcd",
"-from itertools import groupby as gb",
"-from itertools import permutations as perm",
"-from itertools import combinations as comb",
"-from collections import Counter as C",
"-from collections import defaultdict as dd",
"-",
"-sys.setrecursionlimit(10**5)",
"-",
"-",
"-def y(f):",
"- if f:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"-",
"-",
"-def Y(f):",
"- if f:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"-",
"-",
"-if n % 2 == 0:",
"- print((0.5))",
"-else:",
"- print(((n - n // 2) / n))",
"+odd = 0",
"+for i in range(1, n + 1):",
"+ if i % 2 == 1:",
"+ odd += 1",
"+print((odd / n))"
] | false | 0.03942 | 0.035196 | 1.119998 | [
"s038081912",
"s012557637"
] |
u391589398 | p03476 | python | s598211050 | s375611017 | 945 | 855 | 8,984 | 8,900 | Accepted | Accepted | 9.52 | import math
Q = int(eval(input()))
ps = []
maxfac = math.sqrt(10**5)
nums = [i+1 for i in range(1, 10**5)]
while True:
p = nums[0]
if maxfac <= p:
break
ps.append(p)
nums = [num for num in nums if num % p != 0]
ps = set(ps + nums)
c = [0] * 10**5
for i in range(3, 10**5+1, 2):
if i in ps and (i+1)//2 in ps:
c[i] = 1
from itertools import accumulate
cs = list(accumulate(c))
for _ in range(Q):
l, r = list(map(int, input().split()))
print((cs[r] - cs[l-1])) | Q = int(eval(input()))
maxn = 10**5
is_prime = [True if i%2 == 1 else False for i in range(0, maxn+1) ]
is_prime[0] = False
is_prime[1] = False
is_prime[2] = True
for i in range(3, int(maxn**0.5) + 1, 2):
if not is_prime[i]:
continue
for j in range(i*2, maxn+1, i):
is_prime[j] = False
ps = [i for i in range(maxn+1) if is_prime[i]]
ps = set(ps)
c = [0] * 10**5
for i in range(3, 10**5+1, 2):
if i in ps and (i+1)//2 in ps:
c[i] = 1
from itertools import accumulate
cs = list(accumulate(c))
for _ in range(Q):
l, r = list(map(int, input().split()))
print((cs[r] - cs[l-1]))
| 26 | 26 | 519 | 633 | import math
Q = int(eval(input()))
ps = []
maxfac = math.sqrt(10**5)
nums = [i + 1 for i in range(1, 10**5)]
while True:
p = nums[0]
if maxfac <= p:
break
ps.append(p)
nums = [num for num in nums if num % p != 0]
ps = set(ps + nums)
c = [0] * 10**5
for i in range(3, 10**5 + 1, 2):
if i in ps and (i + 1) // 2 in ps:
c[i] = 1
from itertools import accumulate
cs = list(accumulate(c))
for _ in range(Q):
l, r = list(map(int, input().split()))
print((cs[r] - cs[l - 1]))
| Q = int(eval(input()))
maxn = 10**5
is_prime = [True if i % 2 == 1 else False for i in range(0, maxn + 1)]
is_prime[0] = False
is_prime[1] = False
is_prime[2] = True
for i in range(3, int(maxn**0.5) + 1, 2):
if not is_prime[i]:
continue
for j in range(i * 2, maxn + 1, i):
is_prime[j] = False
ps = [i for i in range(maxn + 1) if is_prime[i]]
ps = set(ps)
c = [0] * 10**5
for i in range(3, 10**5 + 1, 2):
if i in ps and (i + 1) // 2 in ps:
c[i] = 1
from itertools import accumulate
cs = list(accumulate(c))
for _ in range(Q):
l, r = list(map(int, input().split()))
print((cs[r] - cs[l - 1]))
| false | 0 | [
"-import math",
"-",
"-ps = []",
"-maxfac = math.sqrt(10**5)",
"-nums = [i + 1 for i in range(1, 10**5)]",
"-while True:",
"- p = nums[0]",
"- if maxfac <= p:",
"- break",
"- ps.append(p)",
"- nums = [num for num in nums if num % p != 0]",
"-ps = set(ps + nums)",
"+maxn = 10**5",
"+is_prime = [True if i % 2 == 1 else False for i in range(0, maxn + 1)]",
"+is_prime[0] = False",
"+is_prime[1] = False",
"+is_prime[2] = True",
"+for i in range(3, int(maxn**0.5) + 1, 2):",
"+ if not is_prime[i]:",
"+ continue",
"+ for j in range(i * 2, maxn + 1, i):",
"+ is_prime[j] = False",
"+ps = [i for i in range(maxn + 1) if is_prime[i]]",
"+ps = set(ps)"
] | false | 0.181929 | 0.09549 | 1.905221 | [
"s598211050",
"s375611017"
] |
u226108478 | p03645 | python | s187319584 | s865808962 | 693 | 172 | 19,016 | 27,672 | Accepted | Accepted | 75.18 | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem C
if __name__ == '__main__':
n, m = list(map(int, input().split()))
set_a = set()
set_b = set()
for i in range(m):
a, b = list(map(int, input().split()))
if a == 1:
set_b.add(b)
elif b == n:
set_a.add(a)
if set_a & set_b:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
| # -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
first = list()
second = list()
for i in range(m):
ai, bi = list(map(int, input().split()))
if ai == 1:
first.append(bi)
if bi == n:
second.append(ai)
ans = set(first) & set(second)
if len(ans) > 0:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
if __name__ == '__main__':
main()
| 22 | 30 | 441 | 520 | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem C
if __name__ == "__main__":
n, m = list(map(int, input().split()))
set_a = set()
set_b = set()
for i in range(m):
a, b = list(map(int, input().split()))
if a == 1:
set_b.add(b)
elif b == n:
set_a.add(a)
if set_a & set_b:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| # -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
first = list()
second = list()
for i in range(m):
ai, bi = list(map(int, input().split()))
if ai == 1:
first.append(bi)
if bi == n:
second.append(ai)
ans = set(first) & set(second)
if len(ans) > 0:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
if __name__ == "__main__":
main()
| false | 26.666667 | [
"-# AtCoder Beginner Contest",
"-# Problem C",
"-if __name__ == \"__main__\":",
"+def main():",
"+ import sys",
"+",
"+ input = sys.stdin.readline",
"- set_a = set()",
"- set_b = set()",
"+ first = list()",
"+ second = list()",
"- a, b = list(map(int, input().split()))",
"- if a == 1:",
"- set_b.add(b)",
"- elif b == n:",
"- set_a.add(a)",
"- if set_a & set_b:",
"+ ai, bi = list(map(int, input().split()))",
"+ if ai == 1:",
"+ first.append(bi)",
"+ if bi == n:",
"+ second.append(ai)",
"+ ans = set(first) & set(second)",
"+ if len(ans) > 0:",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.200521 | 0.068038 | 2.947175 | [
"s187319584",
"s865808962"
] |
u697696097 | p02726 | python | s184051440 | s132225561 | 1,971 | 1,299 | 16,152 | 16,124 | Accepted | Accepted | 34.09 | ### ----------------
### ใใใใ
### ----------------
import sys
from io import StringIO
import unittest
def yn(b):
print(("Yes" if b==1 else "No"))
return
def resolve():
readline=sys.stdin.readline
n,x,y=list(map(int, readline().rstrip().split()))
ans = [0] * (n-1)
for i in range(1,n+1):
for j in range(i+1,n+1):
d1 = abs(i-x) + abs(j-x)
d2 = abs(i-y) + abs(j-y)
d3 = abs(i-x) + abs(j-y) + 1
d4 = abs(i-y) + abs(j-x) + 1
d5 = abs(i-j)
d=min(d1,d2,d3,d4,d5)
ans[d-1]+=1
for a in ans:
print(a)
#arr=list(map(int, readline().rstrip().split()))
#n=int(readline())
#ss=readline().rstrip()
#yn(1)
return
if 'doTest' not in globals():
resolve()
sys.exit()
### ----------------
### ใใใพใง
### ---------------- | ### ----------------
### ใใใใ
### ----------------
import sys
from io import StringIO
import unittest
def yn(b):
print(("Yes" if b==1 else "No"))
return
def resolve():
readline=sys.stdin.readline
n,x,y=list(map(int, readline().rstrip().split()))
ans = [0] * (n-1)
for i in range(1,n+1):
for j in range(i+1,n+1):
d1 = abs(i-x) + abs(j-y) + 1
d2 = abs(i-y) + abs(j-x) + 1
d3 = abs(i-j)
d=min(d1,d2,d3)
ans[d-1]+=1
for a in ans:
print(a)
return
if 'doTest' not in globals():
resolve()
sys.exit()
### ----------------
### ใใใพใง
### ---------------- | 42 | 36 | 895 | 694 | ### ----------------
### ใใใใ
### ----------------
import sys
from io import StringIO
import unittest
def yn(b):
print(("Yes" if b == 1 else "No"))
return
def resolve():
readline = sys.stdin.readline
n, x, y = list(map(int, readline().rstrip().split()))
ans = [0] * (n - 1)
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d1 = abs(i - x) + abs(j - x)
d2 = abs(i - y) + abs(j - y)
d3 = abs(i - x) + abs(j - y) + 1
d4 = abs(i - y) + abs(j - x) + 1
d5 = abs(i - j)
d = min(d1, d2, d3, d4, d5)
ans[d - 1] += 1
for a in ans:
print(a)
# arr=list(map(int, readline().rstrip().split()))
# n=int(readline())
# ss=readline().rstrip()
# yn(1)
return
if "doTest" not in globals():
resolve()
sys.exit()
### ----------------
### ใใใพใง
### ----------------
| ### ----------------
### ใใใใ
### ----------------
import sys
from io import StringIO
import unittest
def yn(b):
print(("Yes" if b == 1 else "No"))
return
def resolve():
readline = sys.stdin.readline
n, x, y = list(map(int, readline().rstrip().split()))
ans = [0] * (n - 1)
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d1 = abs(i - x) + abs(j - y) + 1
d2 = abs(i - y) + abs(j - x) + 1
d3 = abs(i - j)
d = min(d1, d2, d3)
ans[d - 1] += 1
for a in ans:
print(a)
return
if "doTest" not in globals():
resolve()
sys.exit()
### ----------------
### ใใใพใง
### ----------------
| false | 14.285714 | [
"- d1 = abs(i - x) + abs(j - x)",
"- d2 = abs(i - y) + abs(j - y)",
"- d3 = abs(i - x) + abs(j - y) + 1",
"- d4 = abs(i - y) + abs(j - x) + 1",
"- d5 = abs(i - j)",
"- d = min(d1, d2, d3, d4, d5)",
"+ d1 = abs(i - x) + abs(j - y) + 1",
"+ d2 = abs(i - y) + abs(j - x) + 1",
"+ d3 = abs(i - j)",
"+ d = min(d1, d2, d3)",
"- # arr=list(map(int, readline().rstrip().split()))",
"- # n=int(readline())",
"- # ss=readline().rstrip()",
"- # yn(1)"
] | false | 0.03524 | 0.036797 | 0.957675 | [
"s184051440",
"s132225561"
] |
u402629484 | p03695 | python | s445471462 | s441099996 | 21 | 17 | 3,064 | 3,060 | Accepted | Accepted | 19.05 | N = int(eval(input()))
a = list(map(int, input().split()))
COLOR = 8
cnt, ov = [0] * COLOR, 0
for i in range(N):
if a[i] < 3200:
cnt[a[i] // 400] += 1
else:
ov += 1
used = 0
for c in cnt:
if c > 0:
used += 1
unused = N - used
print((max(1, used), used + min(unused, ov))) | N = int(eval(input()))
a = list(map(int, input().split()))
COLOR = 8
cnt, ov = [0] * COLOR, 0
for r in a:
if r < 3200:
cnt[r // 400] = 1
else:
ov += 1
used = 0
for c in cnt:
if c > 0:
used += 1
print((max(1, used), used + ov))
| 18 | 17 | 322 | 275 | N = int(eval(input()))
a = list(map(int, input().split()))
COLOR = 8
cnt, ov = [0] * COLOR, 0
for i in range(N):
if a[i] < 3200:
cnt[a[i] // 400] += 1
else:
ov += 1
used = 0
for c in cnt:
if c > 0:
used += 1
unused = N - used
print((max(1, used), used + min(unused, ov)))
| N = int(eval(input()))
a = list(map(int, input().split()))
COLOR = 8
cnt, ov = [0] * COLOR, 0
for r in a:
if r < 3200:
cnt[r // 400] = 1
else:
ov += 1
used = 0
for c in cnt:
if c > 0:
used += 1
print((max(1, used), used + ov))
| false | 5.555556 | [
"-for i in range(N):",
"- if a[i] < 3200:",
"- cnt[a[i] // 400] += 1",
"+for r in a:",
"+ if r < 3200:",
"+ cnt[r // 400] = 1",
"-unused = N - used",
"-print((max(1, used), used + min(unused, ov)))",
"+print((max(1, used), used + ov))"
] | false | 0.048685 | 0.065796 | 0.739927 | [
"s445471462",
"s441099996"
] |
u047796752 | p02722 | python | s000791510 | s122825987 | 208 | 89 | 39,024 | 67,800 | Accepted | Accepted | 57.21 | def make_divs(n):
divs = []
for i in range(1, int(n**0.5)+1):
if n%i==0:
divs.append(i)
if i!=n//i:
divs.append(n//i)
return divs
N = int(eval(input()))
divs = make_divs(N)
ans = 0
for d in divs:
if d==1:
continue
N2 = N
while N2%d==0:
N2 //= d
if (N2-1)%d==0:
ans += 1
divs = make_divs(N-1)
ans += len(divs)-1
print(ans) | import sys
input = sys.stdin.readline
from collections import *
def make_divs(n):
divs = []
i = 1
while i*i<=n:
if n%i==0:
divs.append(i)
if i!=n//i:
divs.append(n//i)
i += 1
return divs
N = int(eval(input()))
ds = make_divs(N)
ans = 0
for d in ds:
if d==1:
continue
N2 = N
while N2%d==0:
N2 //= d
if (N2-1)%d==0:
ans += 1
ans += len(make_divs(N-1))-1
print(ans) | 32 | 37 | 488 | 559 | def make_divs(n):
divs = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divs.append(i)
if i != n // i:
divs.append(n // i)
return divs
N = int(eval(input()))
divs = make_divs(N)
ans = 0
for d in divs:
if d == 1:
continue
N2 = N
while N2 % d == 0:
N2 //= d
if (N2 - 1) % d == 0:
ans += 1
divs = make_divs(N - 1)
ans += len(divs) - 1
print(ans)
| import sys
input = sys.stdin.readline
from collections import *
def make_divs(n):
divs = []
i = 1
while i * i <= n:
if n % i == 0:
divs.append(i)
if i != n // i:
divs.append(n // i)
i += 1
return divs
N = int(eval(input()))
ds = make_divs(N)
ans = 0
for d in ds:
if d == 1:
continue
N2 = N
while N2 % d == 0:
N2 //= d
if (N2 - 1) % d == 0:
ans += 1
ans += len(make_divs(N - 1)) - 1
print(ans)
| false | 13.513514 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+from collections import *",
"+",
"+",
"- for i in range(1, int(n**0.5) + 1):",
"+ i = 1",
"+ while i * i <= n:",
"+ i += 1",
"-divs = make_divs(N)",
"+ds = make_divs(N)",
"-for d in divs:",
"+for d in ds:",
"-divs = make_divs(N - 1)",
"-ans += len(divs) - 1",
"+ans += len(make_divs(N - 1)) - 1"
] | false | 0.054625 | 0.070908 | 0.770363 | [
"s000791510",
"s122825987"
] |
u887207211 | p03078 | python | s486337264 | s830035777 | 535 | 37 | 8,708 | 5,104 | Accepted | Accepted | 93.08 | def main():
import sys
input = sys.stdin.readline
X, Y, Z, K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
res = []
for i in range(X):
for j in range(Y):
for k in range(Z):
if (i+1)*(j+1)*(k+1) <= K:
res.append(A[i]+B[j]+C[k])
else:
break
res.sort(reverse = True)
for r in res[:K]:
print(r)
if __name__ == "__main__":
main() | def main():
import sys
from heapq import heappush as hpush, heappop as hpop
input = sys.stdin.readline
X, Y, Z, K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
memo = set([(0, 0, 0)])
h = [(-(A[0]+B[0]+C[0]), (0, 0, 0))]
for _ in range(K):
val, (i,j,k) = hpop(h)
if i+1 < len(A) and (i+1, j, k) not in memo:
hpush(h, (-(A[i+1]+B[j]+C[k]), (i+1, j, k)))
memo.add((i+1, j, k))
if j+1 < len(B) and (i, j+1, k) not in memo:
hpush(h, (-(A[i]+B[j+1]+C[k]), (i, j+1, k)))
memo.add((i, j+1, k))
if k+1 < len(C) and (i, j, k+1) not in memo:
hpush(h, (-(A[i]+B[j]+C[k+1]), (i, j, k+1)))
memo.add((i, j, k+1))
print((-val))
if __name__ == "__main__":
main() | 25 | 30 | 585 | 919 | def main():
import sys
input = sys.stdin.readline
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
res = []
for i in range(X):
for j in range(Y):
for k in range(Z):
if (i + 1) * (j + 1) * (k + 1) <= K:
res.append(A[i] + B[j] + C[k])
else:
break
res.sort(reverse=True)
for r in res[:K]:
print(r)
if __name__ == "__main__":
main()
| def main():
import sys
from heapq import heappush as hpush, heappop as hpop
input = sys.stdin.readline
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
memo = set([(0, 0, 0)])
h = [(-(A[0] + B[0] + C[0]), (0, 0, 0))]
for _ in range(K):
val, (i, j, k) = hpop(h)
if i + 1 < len(A) and (i + 1, j, k) not in memo:
hpush(h, (-(A[i + 1] + B[j] + C[k]), (i + 1, j, k)))
memo.add((i + 1, j, k))
if j + 1 < len(B) and (i, j + 1, k) not in memo:
hpush(h, (-(A[i] + B[j + 1] + C[k]), (i, j + 1, k)))
memo.add((i, j + 1, k))
if k + 1 < len(C) and (i, j, k + 1) not in memo:
hpush(h, (-(A[i] + B[j] + C[k + 1]), (i, j, k + 1)))
memo.add((i, j, k + 1))
print((-val))
if __name__ == "__main__":
main()
| false | 16.666667 | [
"+ from heapq import heappush as hpush, heappop as hpop",
"- res = []",
"- for i in range(X):",
"- for j in range(Y):",
"- for k in range(Z):",
"- if (i + 1) * (j + 1) * (k + 1) <= K:",
"- res.append(A[i] + B[j] + C[k])",
"- else:",
"- break",
"- res.sort(reverse=True)",
"- for r in res[:K]:",
"- print(r)",
"+ memo = set([(0, 0, 0)])",
"+ h = [(-(A[0] + B[0] + C[0]), (0, 0, 0))]",
"+ for _ in range(K):",
"+ val, (i, j, k) = hpop(h)",
"+ if i + 1 < len(A) and (i + 1, j, k) not in memo:",
"+ hpush(h, (-(A[i + 1] + B[j] + C[k]), (i + 1, j, k)))",
"+ memo.add((i + 1, j, k))",
"+ if j + 1 < len(B) and (i, j + 1, k) not in memo:",
"+ hpush(h, (-(A[i] + B[j + 1] + C[k]), (i, j + 1, k)))",
"+ memo.add((i, j + 1, k))",
"+ if k + 1 < len(C) and (i, j, k + 1) not in memo:",
"+ hpush(h, (-(A[i] + B[j] + C[k + 1]), (i, j, k + 1)))",
"+ memo.add((i, j, k + 1))",
"+ print((-val))"
] | false | 0.042351 | 0.035991 | 1.176705 | [
"s486337264",
"s830035777"
] |
u560867850 | p02819 | python | s191307658 | s019818988 | 169 | 18 | 14,764 | 3,060 | Accepted | Accepted | 89.35 | import sys
import math
input = sys.stdin.readline
def multiples(n):
for i in range(3,100003):
yield i*n
if i*n > 100003:
break
def sosuu(x):
if x == 2 : return 2
d = set()
end = math.ceil(math.sqrt(x))
d = d.union(multiples(2))
for i in range(3,end,2):
if i not in d:
d = d.union(set(multiples(i)))
i = x if x % 2 != 0 else x+1
while True:
if i not in d:
return i
i += 2
def main():
x = int(eval(input()))
print((sosuu(x)))
if __name__ == "__main__":
main() | import sys
import math
input = sys.stdin.readline
def is_prime(x):
if x <= 1:
return False
for i in range(2,math.ceil(x**0.5)):
if x%i==0:
return False
return True
def main():
x = int(eval(input()))
p = x
while not is_prime(p):
p += 1
print(p)
if __name__ == "__main__":
main() | 31 | 20 | 608 | 362 | import sys
import math
input = sys.stdin.readline
def multiples(n):
for i in range(3, 100003):
yield i * n
if i * n > 100003:
break
def sosuu(x):
if x == 2:
return 2
d = set()
end = math.ceil(math.sqrt(x))
d = d.union(multiples(2))
for i in range(3, end, 2):
if i not in d:
d = d.union(set(multiples(i)))
i = x if x % 2 != 0 else x + 1
while True:
if i not in d:
return i
i += 2
def main():
x = int(eval(input()))
print((sosuu(x)))
if __name__ == "__main__":
main()
| import sys
import math
input = sys.stdin.readline
def is_prime(x):
if x <= 1:
return False
for i in range(2, math.ceil(x**0.5)):
if x % i == 0:
return False
return True
def main():
x = int(eval(input()))
p = x
while not is_prime(p):
p += 1
print(p)
if __name__ == "__main__":
main()
| false | 35.483871 | [
"-def multiples(n):",
"- for i in range(3, 100003):",
"- yield i * n",
"- if i * n > 100003:",
"- break",
"-",
"-",
"-def sosuu(x):",
"- if x == 2:",
"- return 2",
"- d = set()",
"- end = math.ceil(math.sqrt(x))",
"- d = d.union(multiples(2))",
"- for i in range(3, end, 2):",
"- if i not in d:",
"- d = d.union(set(multiples(i)))",
"- i = x if x % 2 != 0 else x + 1",
"- while True:",
"- if i not in d:",
"- return i",
"- i += 2",
"+def is_prime(x):",
"+ if x <= 1:",
"+ return False",
"+ for i in range(2, math.ceil(x**0.5)):",
"+ if x % i == 0:",
"+ return False",
"+ return True",
"- print((sosuu(x)))",
"+ p = x",
"+ while not is_prime(p):",
"+ p += 1",
"+ print(p)"
] | false | 0.288431 | 0.007552 | 38.193157 | [
"s191307658",
"s019818988"
] |
u066413086 | p02902 | python | s582606397 | s638203251 | 368 | 47 | 9,736 | 13,728 | Accepted | Accepted | 87.23 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def find_shortest_cycle(G, s):
dq = deque()
N = len(G)
INF = float('inf')
dist = [INF] * N
dist[s] = 0
parent = [-1] * N
ans_last = None # sใใใซใผใใๆขใใฆ่ฆใคใใฃใๆใฎใใซใผใใฎๆๅพใฎ้ ็น็ชๅท
dq.append(s)
# BFSใงใซใผใใ่ฆใคใใ
while dq and ans_last is None:
v = dq.popleft()
d = dist[v]
for n in G[v]:
# ้ ็นvใใใใใ้ ็นใฎไธญใซ้ๅง็นใใใฃใใใใซใผใใงใใ
if dist[n] == 0:
ans_last = v
parent[n] = v
break
# ใพใ ๆข็ดขใใฆใใชใ้ ็นใชใๆฌกใฎๆข็ดขๅ่ฃใซใใ
elif dist[n] == INF:
dist[n] = d + 1
parent[n] = v
dq.append(n)
# ใซใผใใ่ฆใคใใฃใๅ ดๅ
if ans_last:
# ใซใผใใฎๆๅพใฎ้ ็นใใใๅ
ใฎ้ ็นใใใฉใใใใฎใซใผใใ้ใซใใ
g = ans_last
route = [g]
while g != s:
g = parent[g]
route.append(g)
return list(reversed(route))
# ่ฆใคใใใชใใฃใๅ ดๅใฏNoneใ่ฟใ
return None
def main():
N, M, *A = map(int, read().split())
G = [[] for i in range(N+1)]
for a, b in zip(A[::2], A[1::2]):
G[a].append(b)
# ใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใงใใใใใช G ใฎ่ชๅฐ้จๅใฐใฉใ
# [ใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใฎใฐใฉใ] -> ใซใผใ
# ๆๅใฐใฉใ G=(V,E) ใซๅฏพใใๆฌกใฎใใใชๆกไปถใๆบใใๆๅใฐใฉใ Gโฒ=(Vโฒ,Eโฒ) ใ G ใฎ่ชๅฐ้จๅใฐใฉใใจๅผใถใ
# Vโฒ ใฏ V ใฎ (็ฉบใงใชใ) ้จๅ้ๅใงใใใ
# Eโฒ ใฏใE ใฎ่พบใงใใฃใฆไธก็ซฏ็นใใจใใซ Vโฒ ใซๅซใพใใใใฎใในใฆใๅซใ้ๅใงใใใ
# -> ใซใผใใงใใใทใงใผใใซใใใงใใใใใชใซใผใใฏใ ใ
# ไพ: 1 -> 2 -> 3 -> 4 -> 5
# ^ | ^ |
# | ----------| |
# ---------------------
# V' = {1, 2, 3, 4, 5} ใจใใฆใใพใใจใ
# E' = {(1->2), (2->3), (3->4), (2->4), (4->5), (5->1)}
# ใจใชใฃใฆใใพใใใใฎ่ชๅฐ้จๅใฐใฉใG'=(V', E')ใซใใใฆใ
# ้ ็น2ใฎๅบๆฌกๆฐใ2ใซใชใฃใฆใใพใใ๏ผ้ ็น4ใฎๅ
ฅๆฌกๆฐใ2ใซใชใฃใฆใใพใ๏ผ
# V' = {1, 2, 4, 5} ใจใใใฐใ
# E' = {(1->2), (2->4), (4->5), (5->1)}
# ใจใชใใใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใจใชใ
# ใคใพใใใทใงใผใใซใใใงใใชใๆ็ญใฎใซใผใใ1ใคใงใ่ฆใคใใใฐใใ
min_route = None
for s in range(1, N+1):
# ๅ้ ็นใ้ๅง็นใซใใฆใซใผใใๆขใ
route = find_shortest_cycle(G, s)
# ใซใผใใ่คๆฐใใๅ ดๅใ็ญใใปใใๆก็จ
if route:
if min_route is None or len(route) < len(min_route):
min_route = route
if min_route:
print(len(min_route), *min_route, sep='\n')
else:
print(-1)
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10 ** 6)
n, m = list(map(int, input().split()))
e = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
e[a-1].append(b-1)
c = [0] * n
ans = []
def search_path(p, temp):
c[p] = 1
for x in e[p]:
if x in temp:
print((-99999))
exit()
else:
search_path(x, temp + [x])
t = 1
for i in range(n):
if c[i] == 0:
ans = search_path(i, [i])
print((-1))
| 92 | 28 | 2,460 | 500 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def find_shortest_cycle(G, s):
dq = deque()
N = len(G)
INF = float("inf")
dist = [INF] * N
dist[s] = 0
parent = [-1] * N
ans_last = None # sใใใซใผใใๆขใใฆ่ฆใคใใฃใๆใฎใใซใผใใฎๆๅพใฎ้ ็น็ชๅท
dq.append(s)
# BFSใงใซใผใใ่ฆใคใใ
while dq and ans_last is None:
v = dq.popleft()
d = dist[v]
for n in G[v]:
# ้ ็นvใใใใใ้ ็นใฎไธญใซ้ๅง็นใใใฃใใใใซใผใใงใใ
if dist[n] == 0:
ans_last = v
parent[n] = v
break
# ใพใ ๆข็ดขใใฆใใชใ้ ็นใชใๆฌกใฎๆข็ดขๅ่ฃใซใใ
elif dist[n] == INF:
dist[n] = d + 1
parent[n] = v
dq.append(n)
# ใซใผใใ่ฆใคใใฃใๅ ดๅ
if ans_last:
# ใซใผใใฎๆๅพใฎ้ ็นใใใๅ
ใฎ้ ็นใใใฉใใใใฎใซใผใใ้ใซใใ
g = ans_last
route = [g]
while g != s:
g = parent[g]
route.append(g)
return list(reversed(route))
# ่ฆใคใใใชใใฃใๅ ดๅใฏNoneใ่ฟใ
return None
def main():
N, M, *A = map(int, read().split())
G = [[] for i in range(N + 1)]
for a, b in zip(A[::2], A[1::2]):
G[a].append(b)
# ใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใงใใใใใช G ใฎ่ชๅฐ้จๅใฐใฉใ
# [ใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใฎใฐใฉใ] -> ใซใผใ
# ๆๅใฐใฉใ G=(V,E) ใซๅฏพใใๆฌกใฎใใใชๆกไปถใๆบใใๆๅใฐใฉใ Gโฒ=(Vโฒ,Eโฒ) ใ G ใฎ่ชๅฐ้จๅใฐใฉใใจๅผใถใ
# Vโฒ ใฏ V ใฎ (็ฉบใงใชใ) ้จๅ้ๅใงใใใ
# Eโฒ ใฏใE ใฎ่พบใงใใฃใฆไธก็ซฏ็นใใจใใซ Vโฒ ใซๅซใพใใใใฎใในใฆใๅซใ้ๅใงใใใ
# -> ใซใผใใงใใใทใงใผใใซใใใงใใใใใชใซใผใใฏใ ใ
# ไพ: 1 -> 2 -> 3 -> 4 -> 5
# ^ | ^ |
# | ----------| |
# ---------------------
# V' = {1, 2, 3, 4, 5} ใจใใฆใใพใใจใ
# E' = {(1->2), (2->3), (3->4), (2->4), (4->5), (5->1)}
# ใจใชใฃใฆใใพใใใใฎ่ชๅฐ้จๅใฐใฉใG'=(V', E')ใซใใใฆใ
# ้ ็น2ใฎๅบๆฌกๆฐใ2ใซใชใฃใฆใใพใใ๏ผ้ ็น4ใฎๅ
ฅๆฌกๆฐใ2ใซใชใฃใฆใใพใ๏ผ
# V' = {1, 2, 4, 5} ใจใใใฐใ
# E' = {(1->2), (2->4), (4->5), (5->1)}
# ใจใชใใใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใจใชใ
# ใคใพใใใทใงใผใใซใใใงใใชใๆ็ญใฎใซใผใใ1ใคใงใ่ฆใคใใใฐใใ
min_route = None
for s in range(1, N + 1):
# ๅ้ ็นใ้ๅง็นใซใใฆใซใผใใๆขใ
route = find_shortest_cycle(G, s)
# ใซใผใใ่คๆฐใใๅ ดๅใ็ญใใปใใๆก็จ
if route:
if min_route is None or len(route) < len(min_route):
min_route = route
if min_route:
print(len(min_route), *min_route, sep="\n")
else:
print(-1)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**6)
n, m = list(map(int, input().split()))
e = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
e[a - 1].append(b - 1)
c = [0] * n
ans = []
def search_path(p, temp):
c[p] = 1
for x in e[p]:
if x in temp:
print((-99999))
exit()
else:
search_path(x, temp + [x])
t = 1
for i in range(n):
if c[i] == 0:
ans = search_path(i, [i])
print((-1))
| false | 69.565217 | [
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines",
"-from collections import deque",
"+sys.setrecursionlimit(10**6)",
"+n, m = list(map(int, input().split()))",
"+e = [[] for _ in range(n)]",
"+for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ e[a - 1].append(b - 1)",
"+c = [0] * n",
"+ans = []",
"-def find_shortest_cycle(G, s):",
"- dq = deque()",
"- N = len(G)",
"- INF = float(\"inf\")",
"- dist = [INF] * N",
"- dist[s] = 0",
"- parent = [-1] * N",
"- ans_last = None # sใใใซใผใใๆขใใฆ่ฆใคใใฃใๆใฎใใซใผใใฎๆๅพใฎ้ ็น็ชๅท",
"- dq.append(s)",
"- # BFSใงใซใผใใ่ฆใคใใ",
"- while dq and ans_last is None:",
"- v = dq.popleft()",
"- d = dist[v]",
"- for n in G[v]:",
"- # ้ ็นvใใใใใ้ ็นใฎไธญใซ้ๅง็นใใใฃใใใใซใผใใงใใ",
"- if dist[n] == 0:",
"- ans_last = v",
"- parent[n] = v",
"- break",
"- # ใพใ ๆข็ดขใใฆใใชใ้ ็นใชใๆฌกใฎๆข็ดขๅ่ฃใซใใ",
"- elif dist[n] == INF:",
"- dist[n] = d + 1",
"- parent[n] = v",
"- dq.append(n)",
"- # ใซใผใใ่ฆใคใใฃใๅ ดๅ",
"- if ans_last:",
"- # ใซใผใใฎๆๅพใฎ้ ็นใใใๅ
ใฎ้ ็นใใใฉใใใใฎใซใผใใ้ใซใใ",
"- g = ans_last",
"- route = [g]",
"- while g != s:",
"- g = parent[g]",
"- route.append(g)",
"- return list(reversed(route))",
"- # ่ฆใคใใใชใใฃใๅ ดๅใฏNoneใ่ฟใ",
"- return None",
"+def search_path(p, temp):",
"+ c[p] = 1",
"+ for x in e[p]:",
"+ if x in temp:",
"+ print((-99999))",
"+ exit()",
"+ else:",
"+ search_path(x, temp + [x])",
"-def main():",
"- N, M, *A = map(int, read().split())",
"- G = [[] for i in range(N + 1)]",
"- for a, b in zip(A[::2], A[1::2]):",
"- G[a].append(b)",
"- # ใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใงใใใใใช G ใฎ่ชๅฐ้จๅใฐใฉใ",
"- # [ใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใฎใฐใฉใ] -> ใซใผใ",
"- # ๆๅใฐใฉใ G=(V,E) ใซๅฏพใใๆฌกใฎใใใชๆกไปถใๆบใใๆๅใฐใฉใ Gโฒ=(Vโฒ,Eโฒ) ใ G ใฎ่ชๅฐ้จๅใฐใฉใใจๅผใถใ",
"- # Vโฒ ใฏ V ใฎ (็ฉบใงใชใ) ้จๅ้ๅใงใใใ",
"- # Eโฒ ใฏใE ใฎ่พบใงใใฃใฆไธก็ซฏ็นใใจใใซ Vโฒ ใซๅซใพใใใใฎใในใฆใๅซใ้ๅใงใใใ",
"- # -> ใซใผใใงใใใทใงใผใใซใใใงใใใใใชใซใผใใฏใ ใ",
"- # ไพ: 1 -> 2 -> 3 -> 4 -> 5",
"- # ^ | ^ |",
"- # V' = {1, 2, 3, 4, 5} ใจใใฆใใพใใจใ",
"- # E' = {(1->2), (2->3), (3->4), (2->4), (4->5), (5->1)}",
"- # ใจใชใฃใฆใใพใใใใฎ่ชๅฐ้จๅใฐใฉใG'=(V', E')ใซใใใฆใ",
"- # ้ ็น2ใฎๅบๆฌกๆฐใ2ใซใชใฃใฆใใพใใ๏ผ้ ็น4ใฎๅ
ฅๆฌกๆฐใ2ใซใชใฃใฆใใพใ๏ผ",
"- # V' = {1, 2, 4, 5} ใจใใใฐใ",
"- # E' = {(1->2), (2->4), (4->5), (5->1)}",
"- # ใจใชใใใในใฆใฎ้ ็นใฎๅ
ฅๆฌกๆฐใ 1ใๅบๆฌกๆฐใ 1 ใจใชใ",
"- # ใคใพใใใทใงใผใใซใใใงใใชใๆ็ญใฎใซใผใใ1ใคใงใ่ฆใคใใใฐใใ",
"- min_route = None",
"- for s in range(1, N + 1):",
"- # ๅ้ ็นใ้ๅง็นใซใใฆใซใผใใๆขใ",
"- route = find_shortest_cycle(G, s)",
"- # ใซใผใใ่คๆฐใใๅ ดๅใ็ญใใปใใๆก็จ",
"- if route:",
"- if min_route is None or len(route) < len(min_route):",
"- min_route = route",
"- if min_route:",
"- print(len(min_route), *min_route, sep=\"\\n\")",
"- else:",
"- print(-1)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+t = 1",
"+for i in range(n):",
"+ if c[i] == 0:",
"+ ans = search_path(i, [i])",
"+print((-1))"
] | false | 0.036298 | 0.036842 | 0.985231 | [
"s582606397",
"s638203251"
] |
u863370423 | p02784 | python | s380718548 | s786495970 | 57 | 40 | 14,012 | 13,964 | Accepted | Accepted | 29.82 | import math
inputs = input().split(" ")
health, moves_num = int(inputs[0]), int(inputs[1])
moves_inp = input().split(" ")
moves = [int(move) for move in moves_inp]
can_win = False
for move in moves:
health -= move
if health <= 0:
can_win = True
break
print(("Yes" if can_win else "No")) | H,N=list(map(int,input().split()))
A=list(map(int,input().split()))
x=sum(A)
print(("Yes" if x>=H else "No")) | 16 | 4 | 327 | 104 | import math
inputs = input().split(" ")
health, moves_num = int(inputs[0]), int(inputs[1])
moves_inp = input().split(" ")
moves = [int(move) for move in moves_inp]
can_win = False
for move in moves:
health -= move
if health <= 0:
can_win = True
break
print(("Yes" if can_win else "No"))
| H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
x = sum(A)
print(("Yes" if x >= H else "No"))
| false | 75 | [
"-import math",
"-",
"-inputs = input().split(\" \")",
"-health, moves_num = int(inputs[0]), int(inputs[1])",
"-moves_inp = input().split(\" \")",
"-moves = [int(move) for move in moves_inp]",
"-can_win = False",
"-for move in moves:",
"- health -= move",
"- if health <= 0:",
"- can_win = True",
"- break",
"-print((\"Yes\" if can_win else \"No\"))",
"+H, N = list(map(int, input().split()))",
"+A = list(map(int, input().split()))",
"+x = sum(A)",
"+print((\"Yes\" if x >= H else \"No\"))"
] | false | 0.043518 | 0.042623 | 1.021012 | [
"s380718548",
"s786495970"
] |
u595893956 | p03062 | python | s006319089 | s706375658 | 66 | 58 | 14,224 | 14,412 | Accepted | Accepted | 12.12 | n=eval(input())
a=list(map(int,input().split()))
n=sum(x<0 for x in a)
a=list([abs(x) for x in a])
s=sum(a) if n%2==0 else sum(a)-min(a)*2
print(s)
| n=eval(input())
a=list(map(int,input().split()))
n=sum(x<0 for x in a)
a=list(map(abs,a))
s=sum(a) if n%2==0 else sum(a)-min(a)*2
print(s)
| 6 | 6 | 151 | 138 | n = eval(input())
a = list(map(int, input().split()))
n = sum(x < 0 for x in a)
a = list([abs(x) for x in a])
s = sum(a) if n % 2 == 0 else sum(a) - min(a) * 2
print(s)
| n = eval(input())
a = list(map(int, input().split()))
n = sum(x < 0 for x in a)
a = list(map(abs, a))
s = sum(a) if n % 2 == 0 else sum(a) - min(a) * 2
print(s)
| false | 0 | [
"-a = list([abs(x) for x in a])",
"+a = list(map(abs, a))"
] | false | 0.038357 | 0.038032 | 1.008546 | [
"s006319089",
"s706375658"
] |
u493520238 | p02726 | python | s012924803 | s352174575 | 1,430 | 127 | 3,444 | 74,888 | Accepted | Accepted | 91.12 | def main():
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1,n):
for j in range(i+1, n+1):
r1 = j-i
r2 = abs(x-i) + 1 + abs(j-y)
r3 = abs(y-i) + 1 + abs(j-x)
ans[min(r1,r2,r3)] += 1
for i in range(1,n):
print((ans[i]))
if __name__ == "__main__":
main() | n,x,y = list(map(int, input().split()))
ans = [0]*n
for i in range(1,n):
for j in range(i+1,n+1):
v1 = j-i
v2 = abs(x-i) + 1 + abs(y-j)
v3 = abs(y-i) + 1 + abs(x-j)
minv = min(v1,v2,v3)
ans[minv] += 1
for a in ans[1:]:
print(a) | 16 | 13 | 371 | 283 | def main():
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
r1 = j - i
r2 = abs(x - i) + 1 + abs(j - y)
r3 = abs(y - i) + 1 + abs(j - x)
ans[min(r1, r2, r3)] += 1
for i in range(1, n):
print((ans[i]))
if __name__ == "__main__":
main()
| n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
v1 = j - i
v2 = abs(x - i) + 1 + abs(y - j)
v3 = abs(y - i) + 1 + abs(x - j)
minv = min(v1, v2, v3)
ans[minv] += 1
for a in ans[1:]:
print(a)
| false | 18.75 | [
"-def main():",
"- n, x, y = list(map(int, input().split()))",
"- ans = [0] * n",
"- for i in range(1, n):",
"- for j in range(i + 1, n + 1):",
"- r1 = j - i",
"- r2 = abs(x - i) + 1 + abs(j - y)",
"- r3 = abs(y - i) + 1 + abs(j - x)",
"- ans[min(r1, r2, r3)] += 1",
"- for i in range(1, n):",
"- print((ans[i]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+n, x, y = list(map(int, input().split()))",
"+ans = [0] * n",
"+for i in range(1, n):",
"+ for j in range(i + 1, n + 1):",
"+ v1 = j - i",
"+ v2 = abs(x - i) + 1 + abs(y - j)",
"+ v3 = abs(y - i) + 1 + abs(x - j)",
"+ minv = min(v1, v2, v3)",
"+ ans[minv] += 1",
"+for a in ans[1:]:",
"+ print(a)"
] | false | 0.042616 | 0.04659 | 0.914708 | [
"s012924803",
"s352174575"
] |
u908984540 | p02261 | python | s181860525 | s043474791 | 50 | 30 | 7,760 | 8,224 | Accepted | Accepted | 40 | # -*- coding: utf-8 -*-
def bubble_sort(c):
c = list(c)
for i in range(len(c)):
for j in range(len(c)-1, i, -1):
if int(c[j][1]) < int(c[j-1][1]):
c[j], c[j-1] = c[j-1], c[j]
return c
def selection_sort(c):
c = list(c)
for i in range(len(c)):
minj = i
for j in range(i+1, len(c)):
if int(c[j][1]) < int(c[minj][1]):
minj = j
c[i], c[minj] = c[minj], c[i]
return c
input_num = int(input())
input_list = input().split()
bubble_list = bubble_sort(input_list)
selection_list = selection_sort(input_list)
for c in bubble_list:
print(c, end='')
if c != bubble_list[len(bubble_list)-1]:
print(' ', end='')
print("\nStable")
stable_flg = True
for i in range(len(input_list)):
if bubble_list[i] != selection_list[i]:
stable_flg = False
print(selection_list[i], end='')
if i < len(input_list)-1:
print(" ", end='')
if stable_flg:
print("\nStable")
else:
print("\nNot stable")
| # -*- coding:utf-8 -*-
import copy
def bubble_sort(num_list):
for i in range(len(num_list)):
for j in range(len(num_list)-1, i , -1):
if num_list[j][1] < num_list[j-1][1]:
num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
return num_list
def selection_sort(num_list):
for i in range(len(num_list)):
mini = i
for j in range(i, len(num_list)):
if num_list[j][1] < num_list[mini][1]:
mini = j
num_list[i], num_list[mini] = num_list[mini], num_list[i]
return num_list
def is_stable(before_sort, after_sort):
current_num = 0
same_number_card = list()
for num in after_sort:
if current_num == int(num[1]):
for same_card in same_number_card:
if before_sort.index(same_card) > before_sort.index(num):
return False
same_number_card.append(num)
else:
current_num = int(num[1])
same_number_card = [num,]
return True
def show_list(list):
i = 0;
while(i < len(list)-1):
print(list[i], end=" ")
i = i + 1
print(list[i])
def show_stable(flag):
if flag:
print('Stable')
else:
print('Not stable')
num = int(input())
input_card = [x for i, x in enumerate(input().split()) if i < num]
bubble_sort_card = bubble_sort(copy.deepcopy(input_card))
show_list(bubble_sort_card)
show_stable(is_stable(input_card, bubble_sort_card))
selection_sort_card = selection_sort(copy.deepcopy(input_card))
show_list(selection_sort_card)
show_stable(is_stable(input_card, selection_sort_card))
| 41 | 55 | 1,073 | 1,694 | # -*- coding: utf-8 -*-
def bubble_sort(c):
c = list(c)
for i in range(len(c)):
for j in range(len(c) - 1, i, -1):
if int(c[j][1]) < int(c[j - 1][1]):
c[j], c[j - 1] = c[j - 1], c[j]
return c
def selection_sort(c):
c = list(c)
for i in range(len(c)):
minj = i
for j in range(i + 1, len(c)):
if int(c[j][1]) < int(c[minj][1]):
minj = j
c[i], c[minj] = c[minj], c[i]
return c
input_num = int(input())
input_list = input().split()
bubble_list = bubble_sort(input_list)
selection_list = selection_sort(input_list)
for c in bubble_list:
print(c, end="")
if c != bubble_list[len(bubble_list) - 1]:
print(" ", end="")
print("\nStable")
stable_flg = True
for i in range(len(input_list)):
if bubble_list[i] != selection_list[i]:
stable_flg = False
print(selection_list[i], end="")
if i < len(input_list) - 1:
print(" ", end="")
if stable_flg:
print("\nStable")
else:
print("\nNot stable")
| # -*- coding:utf-8 -*-
import copy
def bubble_sort(num_list):
for i in range(len(num_list)):
for j in range(len(num_list) - 1, i, -1):
if num_list[j][1] < num_list[j - 1][1]:
num_list[j], num_list[j - 1] = num_list[j - 1], num_list[j]
return num_list
def selection_sort(num_list):
for i in range(len(num_list)):
mini = i
for j in range(i, len(num_list)):
if num_list[j][1] < num_list[mini][1]:
mini = j
num_list[i], num_list[mini] = num_list[mini], num_list[i]
return num_list
def is_stable(before_sort, after_sort):
current_num = 0
same_number_card = list()
for num in after_sort:
if current_num == int(num[1]):
for same_card in same_number_card:
if before_sort.index(same_card) > before_sort.index(num):
return False
same_number_card.append(num)
else:
current_num = int(num[1])
same_number_card = [
num,
]
return True
def show_list(list):
i = 0
while i < len(list) - 1:
print(list[i], end=" ")
i = i + 1
print(list[i])
def show_stable(flag):
if flag:
print("Stable")
else:
print("Not stable")
num = int(input())
input_card = [x for i, x in enumerate(input().split()) if i < num]
bubble_sort_card = bubble_sort(copy.deepcopy(input_card))
show_list(bubble_sort_card)
show_stable(is_stable(input_card, bubble_sort_card))
selection_sort_card = selection_sort(copy.deepcopy(input_card))
show_list(selection_sort_card)
show_stable(is_stable(input_card, selection_sort_card))
| false | 25.454545 | [
"-# -*- coding: utf-8 -*-",
"-def bubble_sort(c):",
"- c = list(c)",
"- for i in range(len(c)):",
"- for j in range(len(c) - 1, i, -1):",
"- if int(c[j][1]) < int(c[j - 1][1]):",
"- c[j], c[j - 1] = c[j - 1], c[j]",
"- return c",
"+# -*- coding:utf-8 -*-",
"+import copy",
"-def selection_sort(c):",
"- c = list(c)",
"- for i in range(len(c)):",
"- minj = i",
"- for j in range(i + 1, len(c)):",
"- if int(c[j][1]) < int(c[minj][1]):",
"- minj = j",
"- c[i], c[minj] = c[minj], c[i]",
"- return c",
"+def bubble_sort(num_list):",
"+ for i in range(len(num_list)):",
"+ for j in range(len(num_list) - 1, i, -1):",
"+ if num_list[j][1] < num_list[j - 1][1]:",
"+ num_list[j], num_list[j - 1] = num_list[j - 1], num_list[j]",
"+ return num_list",
"-input_num = int(input())",
"-input_list = input().split()",
"-bubble_list = bubble_sort(input_list)",
"-selection_list = selection_sort(input_list)",
"-for c in bubble_list:",
"- print(c, end=\"\")",
"- if c != bubble_list[len(bubble_list) - 1]:",
"- print(\" \", end=\"\")",
"-print(\"\\nStable\")",
"-stable_flg = True",
"-for i in range(len(input_list)):",
"- if bubble_list[i] != selection_list[i]:",
"- stable_flg = False",
"- print(selection_list[i], end=\"\")",
"- if i < len(input_list) - 1:",
"- print(\" \", end=\"\")",
"-if stable_flg:",
"- print(\"\\nStable\")",
"-else:",
"- print(\"\\nNot stable\")",
"+def selection_sort(num_list):",
"+ for i in range(len(num_list)):",
"+ mini = i",
"+ for j in range(i, len(num_list)):",
"+ if num_list[j][1] < num_list[mini][1]:",
"+ mini = j",
"+ num_list[i], num_list[mini] = num_list[mini], num_list[i]",
"+ return num_list",
"+",
"+",
"+def is_stable(before_sort, after_sort):",
"+ current_num = 0",
"+ same_number_card = list()",
"+ for num in after_sort:",
"+ if current_num == int(num[1]):",
"+ for same_card in same_number_card:",
"+ if before_sort.index(same_card) > before_sort.index(num):",
"+ return False",
"+ same_number_card.append(num)",
"+ else:",
"+ current_num = int(num[1])",
"+ same_number_card = [",
"+ num,",
"+ ]",
"+ return True",
"+",
"+",
"+def show_list(list):",
"+ i = 0",
"+ while i < len(list) - 1:",
"+ print(list[i], end=\" \")",
"+ i = i + 1",
"+ print(list[i])",
"+",
"+",
"+def show_stable(flag):",
"+ if flag:",
"+ print(\"Stable\")",
"+ else:",
"+ print(\"Not stable\")",
"+",
"+",
"+num = int(input())",
"+input_card = [x for i, x in enumerate(input().split()) if i < num]",
"+bubble_sort_card = bubble_sort(copy.deepcopy(input_card))",
"+show_list(bubble_sort_card)",
"+show_stable(is_stable(input_card, bubble_sort_card))",
"+selection_sort_card = selection_sort(copy.deepcopy(input_card))",
"+show_list(selection_sort_card)",
"+show_stable(is_stable(input_card, selection_sort_card))"
] | false | 0.10302 | 0.040251 | 2.559436 | [
"s181860525",
"s043474791"
] |
u935558307 | p03608 | python | s221709169 | s814900873 | 324 | 298 | 76,940 | 80,792 | Accepted | Accepted | 8.02 | N,M,R = list(map(int,input().split()))
R = list(map(int,input().split()))
dp = [[float("INF")]*(N+1) for _ in range(N+1)]
for i in range(N+1):
dp[i][i] = 0
for _ in range(M):
a,b,c = list(map(int,input().split()))
dp[a][b] = min(dp[a][b],c)
dp[b][a] = min(dp[b][a],c)
for i in range(1,N+1):
for j in range(1,N+1):
for k in range(1,N+1):
dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])
def dfs(p,n,path,cost):
path.add(n)
cost += dp[p][n]
if len(path) == len(R):
return cost
else:
res = float("INF")
for r in R:
if r not in path:
res = min(res,dfs(n,r,path,cost))
path.remove(r)
return res
ans = float("INF")
for r in R:
ans = min(ans,dfs(r,r,set(),0))
print(ans) | from itertools import permutations
N,M,R = list(map(int,input().split()))
RList = list(map(int,input().split()))
dp = [[float("INF")]*(N+1) for _ in range(N+1)]
for i in range(N+1):
dp[i][i] = 0
for _ in range(M):
a,b,c = list(map(int,input().split()))
dp[a][b] = c
dp[b][a] = c
for i in range(1,N+1):
for j in range(1,N+1):
for k in range(1,N+1):
dp[j][k] = min(dp[j][i]+dp[i][k],dp[j][k])
ans = float("INF")
RList = list(permutations(RList))
for Rs in RList:
tmp = 0
for i in range(1,R):
a = Rs[i-1]
b = Rs[i]
tmp += dp[a][b]
ans = min(ans,tmp)
print(ans) | 33 | 26 | 821 | 648 | N, M, R = list(map(int, input().split()))
R = list(map(int, input().split()))
dp = [[float("INF")] * (N + 1) for _ in range(N + 1)]
for i in range(N + 1):
dp[i][i] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
dp[a][b] = min(dp[a][b], c)
dp[b][a] = min(dp[b][a], c)
for i in range(1, N + 1):
for j in range(1, N + 1):
for k in range(1, N + 1):
dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k])
def dfs(p, n, path, cost):
path.add(n)
cost += dp[p][n]
if len(path) == len(R):
return cost
else:
res = float("INF")
for r in R:
if r not in path:
res = min(res, dfs(n, r, path, cost))
path.remove(r)
return res
ans = float("INF")
for r in R:
ans = min(ans, dfs(r, r, set(), 0))
print(ans)
| from itertools import permutations
N, M, R = list(map(int, input().split()))
RList = list(map(int, input().split()))
dp = [[float("INF")] * (N + 1) for _ in range(N + 1)]
for i in range(N + 1):
dp[i][i] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
dp[a][b] = c
dp[b][a] = c
for i in range(1, N + 1):
for j in range(1, N + 1):
for k in range(1, N + 1):
dp[j][k] = min(dp[j][i] + dp[i][k], dp[j][k])
ans = float("INF")
RList = list(permutations(RList))
for Rs in RList:
tmp = 0
for i in range(1, R):
a = Rs[i - 1]
b = Rs[i]
tmp += dp[a][b]
ans = min(ans, tmp)
print(ans)
| false | 21.212121 | [
"+from itertools import permutations",
"+",
"-R = list(map(int, input().split()))",
"+RList = list(map(int, input().split()))",
"- dp[a][b] = min(dp[a][b], c)",
"- dp[b][a] = min(dp[b][a], c)",
"+ dp[a][b] = c",
"+ dp[b][a] = c",
"- dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k])",
"-",
"-",
"-def dfs(p, n, path, cost):",
"- path.add(n)",
"- cost += dp[p][n]",
"- if len(path) == len(R):",
"- return cost",
"- else:",
"- res = float(\"INF\")",
"- for r in R:",
"- if r not in path:",
"- res = min(res, dfs(n, r, path, cost))",
"- path.remove(r)",
"- return res",
"-",
"-",
"+ dp[j][k] = min(dp[j][i] + dp[i][k], dp[j][k])",
"-for r in R:",
"- ans = min(ans, dfs(r, r, set(), 0))",
"+RList = list(permutations(RList))",
"+for Rs in RList:",
"+ tmp = 0",
"+ for i in range(1, R):",
"+ a = Rs[i - 1]",
"+ b = Rs[i]",
"+ tmp += dp[a][b]",
"+ ans = min(ans, tmp)"
] | false | 0.038139 | 0.044089 | 0.865054 | [
"s221709169",
"s814900873"
] |
u586759271 | p02762 | python | s630355378 | s304976258 | 1,243 | 1,117 | 103,584 | 103,328 | Accepted | Accepted | 10.14 | #d
# import sys
# input = sys.stdin.readline
n,m,k = list(map(int,input().split()))
friends_pair=[]
friend=[[] for _ in range(n)]
for i in range(m):
a,b = list(map(int,input().split()))
a-=1
b-=1
friends_pair.append((a,b))
friend[a].append(b)
friend[b].append(a)
block=[]
for i in range(k):
a,b = list(map(int,input().split()))
block.append((a-1,b-1))
from collections import deque
clusters=[]
visited=[0]*n
list_cluster=[0]*n
i_c=0
# while sum(visited)<n:
# for i in range(n):
# if visited[i]==0:
# start=i
# break
for i in range(n):
if visited[i]==0:
start=i
else:
continue
cluster =[start]
q=deque([(start,togo) for togo in friend[start]]) #ในใฟใผใๅฐ็นใใ่กใใๅ ดๆใๅๆ
visited[start]=1
list_cluster[start]=i_c
for togo in friend[start]:
visited[togo]=1
cluster.append(togo)
list_cluster[togo]=i_c
while q:
parent,x = q.popleft()
for y in friend[x]:
if y == parent:#่ฆชใใผใใ้ฃใฐใ
continue
if visited[y]==0:
q.append((x,y))#ๅญใใผใใ่ฟฝๅ
visited[y]=1
cluster.append(y)
list_cluster[y]=i_c
# print(parent,x,q)
clusters.append(cluster)
i_c+=1
ans = [len(clusters[list_cluster[i]])-1 for i in range(n) ]
for f0,f1 in friends_pair:
if list_cluster[f0] == list_cluster[f1]:
ans[f0]-=1
ans[f1]-=1
for b0,b1 in block:
if list_cluster[b0] == list_cluster[b1]:
ans[b0]-=1
ans[b1]-=1
print((*ans))
| #d
# import sys
# input = sys.stdin.readline
n,m,k = list(map(int,input().split()))
friends_pair=[]
friend=[[] for _ in range(n)]
for i in range(m):
a,b = list(map(int,input().split()))
a-=1
b-=1
friends_pair.append((a,b))
friend[a].append(b)
friend[b].append(a)
block=[]
for i in range(k):
a,b = list(map(int,input().split()))
block.append((a-1,b-1))
from collections import deque
clusters=[]
visited=[0]*n
list_cluster=[0]*n
i_c=0
for i in range(n):
if visited[i]==0:
start=i
else:
continue
cluster =[start]
q=deque([(start,togo) for togo in friend[start]]) #ในใฟใผใๅฐ็นใใ่กใใๅ ดๆใๅๆ
visited[start]=1
list_cluster[start]=i_c
for togo in friend[start]:
visited[togo]=1
cluster.append(togo)
list_cluster[togo]=i_c
while q:
parent,x = q.popleft()
for y in friend[x]:
# if y == parent:#่ฆชใใผใใ้ฃใฐใ
# continue
if visited[y]==0:
q.append((x,y))#ๅญใใผใใ่ฟฝๅ
visited[y]=1
cluster.append(y)
list_cluster[y]=i_c
# print(parent,x,q)
clusters.append(cluster)
i_c+=1
ans = [len(clusters[list_cluster[i]])-1 for i in range(n) ]
for f0,f1 in friends_pair:
if list_cluster[f0] == list_cluster[f1]:
ans[f0]-=1
ans[f1]-=1
for b0,b1 in block:
if list_cluster[b0] == list_cluster[b1]:
ans[b0]-=1
ans[b1]-=1
print((*ans))
| 72 | 68 | 1,674 | 1,556 | # d
# import sys
# input = sys.stdin.readline
n, m, k = list(map(int, input().split()))
friends_pair = []
friend = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
friends_pair.append((a, b))
friend[a].append(b)
friend[b].append(a)
block = []
for i in range(k):
a, b = list(map(int, input().split()))
block.append((a - 1, b - 1))
from collections import deque
clusters = []
visited = [0] * n
list_cluster = [0] * n
i_c = 0
# while sum(visited)<n:
# for i in range(n):
# if visited[i]==0:
# start=i
# break
for i in range(n):
if visited[i] == 0:
start = i
else:
continue
cluster = [start]
q = deque([(start, togo) for togo in friend[start]]) # ในใฟใผใๅฐ็นใใ่กใใๅ ดๆใๅๆ
visited[start] = 1
list_cluster[start] = i_c
for togo in friend[start]:
visited[togo] = 1
cluster.append(togo)
list_cluster[togo] = i_c
while q:
parent, x = q.popleft()
for y in friend[x]:
if y == parent: # ่ฆชใใผใใ้ฃใฐใ
continue
if visited[y] == 0:
q.append((x, y)) # ๅญใใผใใ่ฟฝๅ
visited[y] = 1
cluster.append(y)
list_cluster[y] = i_c
# print(parent,x,q)
clusters.append(cluster)
i_c += 1
ans = [len(clusters[list_cluster[i]]) - 1 for i in range(n)]
for f0, f1 in friends_pair:
if list_cluster[f0] == list_cluster[f1]:
ans[f0] -= 1
ans[f1] -= 1
for b0, b1 in block:
if list_cluster[b0] == list_cluster[b1]:
ans[b0] -= 1
ans[b1] -= 1
print((*ans))
| # d
# import sys
# input = sys.stdin.readline
n, m, k = list(map(int, input().split()))
friends_pair = []
friend = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
friends_pair.append((a, b))
friend[a].append(b)
friend[b].append(a)
block = []
for i in range(k):
a, b = list(map(int, input().split()))
block.append((a - 1, b - 1))
from collections import deque
clusters = []
visited = [0] * n
list_cluster = [0] * n
i_c = 0
for i in range(n):
if visited[i] == 0:
start = i
else:
continue
cluster = [start]
q = deque([(start, togo) for togo in friend[start]]) # ในใฟใผใๅฐ็นใใ่กใใๅ ดๆใๅๆ
visited[start] = 1
list_cluster[start] = i_c
for togo in friend[start]:
visited[togo] = 1
cluster.append(togo)
list_cluster[togo] = i_c
while q:
parent, x = q.popleft()
for y in friend[x]:
# if y == parent:#่ฆชใใผใใ้ฃใฐใ
# continue
if visited[y] == 0:
q.append((x, y)) # ๅญใใผใใ่ฟฝๅ
visited[y] = 1
cluster.append(y)
list_cluster[y] = i_c
# print(parent,x,q)
clusters.append(cluster)
i_c += 1
ans = [len(clusters[list_cluster[i]]) - 1 for i in range(n)]
for f0, f1 in friends_pair:
if list_cluster[f0] == list_cluster[f1]:
ans[f0] -= 1
ans[f1] -= 1
for b0, b1 in block:
if list_cluster[b0] == list_cluster[b1]:
ans[b0] -= 1
ans[b1] -= 1
print((*ans))
| false | 5.555556 | [
"-# while sum(visited)<n:",
"-# for i in range(n):",
"-# if visited[i]==0:",
"-# start=i",
"-# break",
"- if y == parent: # ่ฆชใใผใใ้ฃใฐใ",
"- continue",
"+ # if y == parent:#่ฆชใใผใใ้ฃใฐใ",
"+ # continue"
] | false | 0.033574 | 0.041716 | 0.804808 | [
"s630355378",
"s304976258"
] |
u227082700 | p03854 | python | s969165771 | s786658952 | 64 | 18 | 3,188 | 3,188 | Accepted | Accepted | 71.88 | a=("dream","erase");ans="YES"
s=eval(input())
while s!="":
if s[-7:]=="dreamer":s=s[:-7]
elif s[-6:]=="eraser":s=s[:-6]
elif s[-5:]in a:s=s[:-5]
else:ans="NO";break
print(ans) | s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s=="":print('YES')
else:print('NO') | 8 | 3 | 184 | 133 | a = ("dream", "erase")
ans = "YES"
s = eval(input())
while s != "":
if s[-7:] == "dreamer":
s = s[:-7]
elif s[-6:] == "eraser":
s = s[:-6]
elif s[-5:] in a:
s = s[:-5]
else:
ans = "NO"
break
print(ans)
| s = (
input()
.replace("eraser", "")
.replace("erase", "")
.replace("dreamer", "")
.replace("dream", "")
)
if s == "":
print("YES")
else:
print("NO")
| false | 62.5 | [
"-a = (\"dream\", \"erase\")",
"-ans = \"YES\"",
"-s = eval(input())",
"-while s != \"\":",
"- if s[-7:] == \"dreamer\":",
"- s = s[:-7]",
"- elif s[-6:] == \"eraser\":",
"- s = s[:-6]",
"- elif s[-5:] in a:",
"- s = s[:-5]",
"- else:",
"- ans = \"NO\"",
"- break",
"-print(ans)",
"+s = (",
"+ input()",
"+ .replace(\"eraser\", \"\")",
"+ .replace(\"erase\", \"\")",
"+ .replace(\"dreamer\", \"\")",
"+ .replace(\"dream\", \"\")",
"+)",
"+if s == \"\":",
"+ print(\"YES\")",
"+else:",
"+ print(\"NO\")"
] | false | 0.044252 | 0.036729 | 1.204814 | [
"s969165771",
"s786658952"
] |
u796942881 | p02959 | python | s319134964 | s541580765 | 149 | 88 | 20,572 | 20,800 | Accepted | Accepted | 40.94 | from collections import deque
from sys import stdin
def main():
lines = stdin.readlines()
A = deque(list(map(int, lines[1].split())))
B = deque(list(map(int, lines[2].split())))
cnt = 0
ans = 0
while B:
a = A.pop()
b = B.pop()
tmp = a if a < b else b
ans += tmp
if cnt % 2:
A.append(a - tmp)
else:
B.append(b - tmp)
cnt += 1
print(ans)
return
main()
| from sys import stdin
def main():
lines = stdin.readlines()
A = tuple(map(int, lines[1].split()))
B = tuple(map(int, lines[2].split()))
pre = A[0]
ans = 0
for a, b in zip(A[1:], B):
tmp1 = pre if pre < b else b
b -= tmp1
tmp2 = a if a < b else b
ans += tmp1 + tmp2
pre = a - tmp2
print(ans)
return
main()
| 25 | 20 | 478 | 400 | from collections import deque
from sys import stdin
def main():
lines = stdin.readlines()
A = deque(list(map(int, lines[1].split())))
B = deque(list(map(int, lines[2].split())))
cnt = 0
ans = 0
while B:
a = A.pop()
b = B.pop()
tmp = a if a < b else b
ans += tmp
if cnt % 2:
A.append(a - tmp)
else:
B.append(b - tmp)
cnt += 1
print(ans)
return
main()
| from sys import stdin
def main():
lines = stdin.readlines()
A = tuple(map(int, lines[1].split()))
B = tuple(map(int, lines[2].split()))
pre = A[0]
ans = 0
for a, b in zip(A[1:], B):
tmp1 = pre if pre < b else b
b -= tmp1
tmp2 = a if a < b else b
ans += tmp1 + tmp2
pre = a - tmp2
print(ans)
return
main()
| false | 20 | [
"-from collections import deque",
"- A = deque(list(map(int, lines[1].split())))",
"- B = deque(list(map(int, lines[2].split())))",
"- cnt = 0",
"+ A = tuple(map(int, lines[1].split()))",
"+ B = tuple(map(int, lines[2].split()))",
"+ pre = A[0]",
"- while B:",
"- a = A.pop()",
"- b = B.pop()",
"- tmp = a if a < b else b",
"- ans += tmp",
"- if cnt % 2:",
"- A.append(a - tmp)",
"- else:",
"- B.append(b - tmp)",
"- cnt += 1",
"+ for a, b in zip(A[1:], B):",
"+ tmp1 = pre if pre < b else b",
"+ b -= tmp1",
"+ tmp2 = a if a < b else b",
"+ ans += tmp1 + tmp2",
"+ pre = a - tmp2"
] | false | 0.066401 | 0.138902 | 0.478046 | [
"s319134964",
"s541580765"
] |
u492447501 | p03107 | python | s781665526 | s048069053 | 39 | 22 | 3,188 | 3,956 | Accepted | Accepted | 43.59 | S = eval(input())
count_1 = 0
count_0 = 0
for i in range(len(S)):
if S[i]=="1":
count_1 = count_1 + 1
elif S[i]=="0":
count_0 = count_0 + 1
if count_1 >= count_0:
print((count_0*2))
else:
print((count_1*2))
| S = list(eval(input()))
zero = S.count("0")
one = S.count("1")
print((int(zero*2) if zero <= one else int(one*2))) | 18 | 6 | 240 | 114 | S = eval(input())
count_1 = 0
count_0 = 0
for i in range(len(S)):
if S[i] == "1":
count_1 = count_1 + 1
elif S[i] == "0":
count_0 = count_0 + 1
if count_1 >= count_0:
print((count_0 * 2))
else:
print((count_1 * 2))
| S = list(eval(input()))
zero = S.count("0")
one = S.count("1")
print((int(zero * 2) if zero <= one else int(one * 2)))
| false | 66.666667 | [
"-S = eval(input())",
"-count_1 = 0",
"-count_0 = 0",
"-for i in range(len(S)):",
"- if S[i] == \"1\":",
"- count_1 = count_1 + 1",
"- elif S[i] == \"0\":",
"- count_0 = count_0 + 1",
"-if count_1 >= count_0:",
"- print((count_0 * 2))",
"-else:",
"- print((count_1 * 2))",
"+S = list(eval(input()))",
"+zero = S.count(\"0\")",
"+one = S.count(\"1\")",
"+print((int(zero * 2) if zero <= one else int(one * 2)))"
] | false | 0.037243 | 0.036314 | 1.025588 | [
"s781665526",
"s048069053"
] |
u678167152 | p03293 | python | s225068237 | s466075863 | 162 | 27 | 38,384 | 9,028 | Accepted | Accepted | 83.33 | def check():
S = eval(input())
T = eval(input())
S *= 2
if T in S:
return 'Yes'
return 'No'
print((check())) | def check():
S = eval(input())
T = eval(input())
S *= 2
for i in range(len(T)):
if S[i:i+len(T)]==T:
return 'Yes'
return 'No'
print((check())) | 8 | 9 | 129 | 156 | def check():
S = eval(input())
T = eval(input())
S *= 2
if T in S:
return "Yes"
return "No"
print((check()))
| def check():
S = eval(input())
T = eval(input())
S *= 2
for i in range(len(T)):
if S[i : i + len(T)] == T:
return "Yes"
return "No"
print((check()))
| false | 11.111111 | [
"- if T in S:",
"- return \"Yes\"",
"+ for i in range(len(T)):",
"+ if S[i : i + len(T)] == T:",
"+ return \"Yes\""
] | false | 0.10033 | 0.036341 | 2.760801 | [
"s225068237",
"s466075863"
] |
u535171899 | p02954 | python | s337446045 | s139357552 | 1,625 | 121 | 14,068 | 6,400 | Accepted | Accepted | 92.55 | s = eval(input())
n = len(s)
#RRLRL=(R2L),(RL)
#ใฉใณใฌใณใฐในๅง็ธฎใงRLใๅง็ธฎใใๆฐใฎๅถๅฅใงๅ้
ใใ
#n<=10**5ใชใฎใงใ10**5็งปๅใใใๅพใฎๅคใงใๆฑใใใใ
v=[]
def RLE(s,v):
for i in range(len(s)):
if len(v)==0 or v[-1][0]!=s[i]:
v.append([s[i],1])
else:
v[-1][1]+=1
return v
rle_li = RLE(s,v)
string_li = [0]*n
for i in range(1,n):
if s[i-1]=='R' and s[i]=='L':
x = rle_li.pop(0)[1]
y = rle_li.pop(0)[1]
if x==1 and y==1:
string_li[i-1]=1
string_li[i]=1
else:
if y%2==0:
string_li[i-1]+=y//2
string_li[i]+=y//2
else:
string_li[i-1]+=y//2
string_li[i]+=y//2+1
if x%2==0:
string_li[i-1]+=x//2
string_li[i]+=x//2
else:
string_li[i-1]+=x//2+1
string_li[i]+=x//2
print((' '.join(map(str,string_li))))
| s = eval(input())
l=len(s)
ans=[1]*l
for i in range(l-1):
if s[i]==s[i+1]=="R":
ans[i+2]+=ans[i]
ans[i]=0
for i in range(l-1,1,-1):
if s[i]==s[i-1]=="L":
ans[i-2]+=ans[i]
ans[i]=0
print((*ans)) | 39 | 12 | 967 | 236 | s = eval(input())
n = len(s)
# RRLRL=(R2L),(RL)
# ใฉใณใฌใณใฐในๅง็ธฎใงRLใๅง็ธฎใใๆฐใฎๅถๅฅใงๅ้
ใใ
# n<=10**5ใชใฎใงใ10**5็งปๅใใใๅพใฎๅคใงใๆฑใใใใ
v = []
def RLE(s, v):
for i in range(len(s)):
if len(v) == 0 or v[-1][0] != s[i]:
v.append([s[i], 1])
else:
v[-1][1] += 1
return v
rle_li = RLE(s, v)
string_li = [0] * n
for i in range(1, n):
if s[i - 1] == "R" and s[i] == "L":
x = rle_li.pop(0)[1]
y = rle_li.pop(0)[1]
if x == 1 and y == 1:
string_li[i - 1] = 1
string_li[i] = 1
else:
if y % 2 == 0:
string_li[i - 1] += y // 2
string_li[i] += y // 2
else:
string_li[i - 1] += y // 2
string_li[i] += y // 2 + 1
if x % 2 == 0:
string_li[i - 1] += x // 2
string_li[i] += x // 2
else:
string_li[i - 1] += x // 2 + 1
string_li[i] += x // 2
print((" ".join(map(str, string_li))))
| s = eval(input())
l = len(s)
ans = [1] * l
for i in range(l - 1):
if s[i] == s[i + 1] == "R":
ans[i + 2] += ans[i]
ans[i] = 0
for i in range(l - 1, 1, -1):
if s[i] == s[i - 1] == "L":
ans[i - 2] += ans[i]
ans[i] = 0
print((*ans))
| false | 69.230769 | [
"-n = len(s)",
"-# RRLRL=(R2L),(RL)",
"-# ใฉใณใฌใณใฐในๅง็ธฎใงRLใๅง็ธฎใใๆฐใฎๅถๅฅใงๅ้
ใใ",
"-# n<=10**5ใชใฎใงใ10**5็งปๅใใใๅพใฎๅคใงใๆฑใใใใ",
"-v = []",
"-",
"-",
"-def RLE(s, v):",
"- for i in range(len(s)):",
"- if len(v) == 0 or v[-1][0] != s[i]:",
"- v.append([s[i], 1])",
"- else:",
"- v[-1][1] += 1",
"- return v",
"-",
"-",
"-rle_li = RLE(s, v)",
"-string_li = [0] * n",
"-for i in range(1, n):",
"- if s[i - 1] == \"R\" and s[i] == \"L\":",
"- x = rle_li.pop(0)[1]",
"- y = rle_li.pop(0)[1]",
"- if x == 1 and y == 1:",
"- string_li[i - 1] = 1",
"- string_li[i] = 1",
"- else:",
"- if y % 2 == 0:",
"- string_li[i - 1] += y // 2",
"- string_li[i] += y // 2",
"- else:",
"- string_li[i - 1] += y // 2",
"- string_li[i] += y // 2 + 1",
"- if x % 2 == 0:",
"- string_li[i - 1] += x // 2",
"- string_li[i] += x // 2",
"- else:",
"- string_li[i - 1] += x // 2 + 1",
"- string_li[i] += x // 2",
"-print((\" \".join(map(str, string_li))))",
"+l = len(s)",
"+ans = [1] * l",
"+for i in range(l - 1):",
"+ if s[i] == s[i + 1] == \"R\":",
"+ ans[i + 2] += ans[i]",
"+ ans[i] = 0",
"+for i in range(l - 1, 1, -1):",
"+ if s[i] == s[i - 1] == \"L\":",
"+ ans[i - 2] += ans[i]",
"+ ans[i] = 0",
"+print((*ans))"
] | false | 0.037136 | 0.035107 | 1.057797 | [
"s337446045",
"s139357552"
] |
u513081876 | p03645 | python | s395685418 | s374867947 | 946 | 458 | 39,960 | 40,644 | Accepted | Accepted | 51.59 | N, M = list(map(int, input().split()))
matrix = [[] for i in range(N)]
check1 = [0] * N
check1[0] = 1
for i in range(M):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
matrix[a].append(b)
matrix[b].append(a)
for i in matrix[0]:
if (N-1) in matrix[i]:
print('POSSIBLE')
break
else:
print('IMPOSSIBLE') | N, M = list(map(int, input().split()))
check = [0] * N
check[0] = 1
ab = []
for i in range(M):
a, b = list(map(int, input().split()))
ab.append([a, b])
if a == 1:
check[b-1] = 1
for a, b in ab:
if check[a-1] == 1 and b == N:
print('POSSIBLE')
break
else:
print('IMPOSSIBLE')
| 17 | 16 | 354 | 323 | N, M = list(map(int, input().split()))
matrix = [[] for i in range(N)]
check1 = [0] * N
check1[0] = 1
for i in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
matrix[a].append(b)
matrix[b].append(a)
for i in matrix[0]:
if (N - 1) in matrix[i]:
print("POSSIBLE")
break
else:
print("IMPOSSIBLE")
| N, M = list(map(int, input().split()))
check = [0] * N
check[0] = 1
ab = []
for i in range(M):
a, b = list(map(int, input().split()))
ab.append([a, b])
if a == 1:
check[b - 1] = 1
for a, b in ab:
if check[a - 1] == 1 and b == N:
print("POSSIBLE")
break
else:
print("IMPOSSIBLE")
| false | 5.882353 | [
"-matrix = [[] for i in range(N)]",
"-check1 = [0] * N",
"-check1[0] = 1",
"+check = [0] * N",
"+check[0] = 1",
"+ab = []",
"- a, b = a - 1, b - 1",
"- matrix[a].append(b)",
"- matrix[b].append(a)",
"-for i in matrix[0]:",
"- if (N - 1) in matrix[i]:",
"+ ab.append([a, b])",
"+ if a == 1:",
"+ check[b - 1] = 1",
"+for a, b in ab:",
"+ if check[a - 1] == 1 and b == N:"
] | false | 0.037998 | 0.037689 | 1.008214 | [
"s395685418",
"s374867947"
] |
u841568901 | p03659 | python | s895635811 | s675010744 | 165 | 151 | 30,740 | 30,712 | Accepted | Accepted | 8.48 | N = int(eval(input()))
A = list(map(int, input().split()))
P = A[0]
Q = sum(A[1:])
m = abs(P-Q)
for i in range(1, N-1):
P += A[i]
Q -= A[i]
m = min(m, abs(P-Q))
print(m) | N = int(eval(input()))
A = list(map(int,input().split()))
S = sum(A)
T = [0]*(N+1)
for i in range(N):
T[i+1] = T[i] + A[i]
print((min(abs(S-2*T[i]) for i in range(1, N)))) | 10 | 7 | 178 | 171 | N = int(eval(input()))
A = list(map(int, input().split()))
P = A[0]
Q = sum(A[1:])
m = abs(P - Q)
for i in range(1, N - 1):
P += A[i]
Q -= A[i]
m = min(m, abs(P - Q))
print(m)
| N = int(eval(input()))
A = list(map(int, input().split()))
S = sum(A)
T = [0] * (N + 1)
for i in range(N):
T[i + 1] = T[i] + A[i]
print((min(abs(S - 2 * T[i]) for i in range(1, N))))
| false | 30 | [
"-P = A[0]",
"-Q = sum(A[1:])",
"-m = abs(P - Q)",
"-for i in range(1, N - 1):",
"- P += A[i]",
"- Q -= A[i]",
"- m = min(m, abs(P - Q))",
"-print(m)",
"+S = sum(A)",
"+T = [0] * (N + 1)",
"+for i in range(N):",
"+ T[i + 1] = T[i] + A[i]",
"+print((min(abs(S - 2 * T[i]) for i in range(1, N))))"
] | false | 0.036643 | 0.036368 | 1.007572 | [
"s895635811",
"s675010744"
] |
u476435125 | p02948 | python | s842844815 | s132504131 | 437 | 403 | 31,980 | 31,980 | Accepted | Accepted | 7.78 | import heapq
import sys
input=sys.stdin.readline
N,M=list(map(int,input().split()))
lab=[]
for i in range(N):
llab=list(map(int,input().split()))
lab.append(llab)
lab.sort(key=lambda ab:ab[0])
hq=[]
ind=0
ans=0
#print(lab)
#c=0
for i in range(M):
if hq:
ans-=heapq.heappop(hq)
for j in range(ind,N):
#if f==0:
#print(i,j,lab[j][0])
if lab[j][0]==i+1:
heapq.heappush(hq,-lab[j][1])#
else:
ind=j
#j=N-1#ใใใใกใๆใใใใฆใใชใ
break
#c+=1
#if hq:
# ans-=heapq.heappop(hq)
#print(hq)
#print(c)
if hq:
ans-=heapq.heappop(hq)
print(ans)
#for i in range(3):
# i=3
# print(12345)
| import heapq
import sys
input=sys.stdin.readline
N,M=list(map(int,input().split()))
lab=[]
for i in range(N):
llab=list(map(int,input().split()))
lab.append(llab)
lab.sort(key=lambda ab:ab[0])
hq=[]
ind=0
ans=0
for i in range(M):
for j in range(ind,N):
if lab[j][0]==i+1:
heapq.heappush(hq,-lab[j][1])
else:
ind=j
break
if hq:
ans-=heapq.heappop(hq)
print(ans)
| 37 | 22 | 738 | 456 | import heapq
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
lab = []
for i in range(N):
llab = list(map(int, input().split()))
lab.append(llab)
lab.sort(key=lambda ab: ab[0])
hq = []
ind = 0
ans = 0
# print(lab)
# c=0
for i in range(M):
if hq:
ans -= heapq.heappop(hq)
for j in range(ind, N):
# if f==0:
# print(i,j,lab[j][0])
if lab[j][0] == i + 1:
heapq.heappush(hq, -lab[j][1]) #
else:
ind = j
# j=N-1#ใใใใกใๆใใใใฆใใชใ
break
# c+=1
# if hq:
# ans-=heapq.heappop(hq)
# print(hq)
# print(c)
if hq:
ans -= heapq.heappop(hq)
print(ans)
# for i in range(3):
# i=3
# print(12345)
| import heapq
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
lab = []
for i in range(N):
llab = list(map(int, input().split()))
lab.append(llab)
lab.sort(key=lambda ab: ab[0])
hq = []
ind = 0
ans = 0
for i in range(M):
for j in range(ind, N):
if lab[j][0] == i + 1:
heapq.heappush(hq, -lab[j][1])
else:
ind = j
break
if hq:
ans -= heapq.heappop(hq)
print(ans)
| false | 40.540541 | [
"-# print(lab)",
"-# c=0",
"+ for j in range(ind, N):",
"+ if lab[j][0] == i + 1:",
"+ heapq.heappush(hq, -lab[j][1])",
"+ else:",
"+ ind = j",
"+ break",
"- for j in range(ind, N):",
"- # if f==0:",
"- # print(i,j,lab[j][0])",
"- if lab[j][0] == i + 1:",
"- heapq.heappush(hq, -lab[j][1]) #",
"- else:",
"- ind = j",
"- # j=N-1#ใใใใกใๆใใใใฆใใชใ",
"- break",
"- # c+=1",
"- # if hq:",
"- # ans-=heapq.heappop(hq)",
"- # print(hq)",
"-# print(c)",
"-if hq:",
"- ans -= heapq.heappop(hq)",
"-# for i in range(3):",
"-# i=3",
"-# print(12345)"
] | false | 0.106299 | 0.042766 | 2.485602 | [
"s842844815",
"s132504131"
] |
u396495667 | p03693 | python | s359041640 | s510520780 | 167 | 17 | 38,324 | 2,940 | Accepted | Accepted | 89.82 | r,g,b=list(map(int, input().split()))
a = 100*r + 10*g + b
if a%4 ==0:
print('YES')
else:
print('NO') | r,g,b= list(map(int, input().split()))
a = r*100+g*10+b
print(('YES' if a %4==0 else 'NO')) | 7 | 3 | 106 | 85 | r, g, b = list(map(int, input().split()))
a = 100 * r + 10 * g + b
if a % 4 == 0:
print("YES")
else:
print("NO")
| r, g, b = list(map(int, input().split()))
a = r * 100 + g * 10 + b
print(("YES" if a % 4 == 0 else "NO"))
| false | 57.142857 | [
"-a = 100 * r + 10 * g + b",
"-if a % 4 == 0:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+a = r * 100 + g * 10 + b",
"+print((\"YES\" if a % 4 == 0 else \"NO\"))"
] | false | 0.043243 | 0.034477 | 1.254237 | [
"s359041640",
"s510520780"
] |
u814986259 | p03761 | python | s446670737 | s328291410 | 22 | 18 | 3,316 | 3,060 | Accepted | Accepted | 18.18 | import collections
n = int(eval(input()))
S = [list(eval(input())) for i in range(n)]
S.sort(key=lambda x: len(x))
table = collections.defaultdict(int)
len_s = len(S[0])
for i in range(1, n):
for x in S[0]:
if x in S[i]:
S[i].pop(S[i].index(x))
else:
S[0].pop(S[0].index(x))
S[0].sort()
print(("".join(S[0])))
| n = int(eval(input()))
S = [eval(input()) for i in range(n)]
alpha = "abcdefghijklmnopqrstuvwxyz"
count = [50]*26
for i, x in enumerate(alpha):
for s in S:
count[i] = min(count[i], s.count(x))
ans = []
for i, x in zip(count, alpha):
ans.append(x*i)
print(("".join(ans)))
| 17 | 13 | 359 | 287 | import collections
n = int(eval(input()))
S = [list(eval(input())) for i in range(n)]
S.sort(key=lambda x: len(x))
table = collections.defaultdict(int)
len_s = len(S[0])
for i in range(1, n):
for x in S[0]:
if x in S[i]:
S[i].pop(S[i].index(x))
else:
S[0].pop(S[0].index(x))
S[0].sort()
print(("".join(S[0])))
| n = int(eval(input()))
S = [eval(input()) for i in range(n)]
alpha = "abcdefghijklmnopqrstuvwxyz"
count = [50] * 26
for i, x in enumerate(alpha):
for s in S:
count[i] = min(count[i], s.count(x))
ans = []
for i, x in zip(count, alpha):
ans.append(x * i)
print(("".join(ans)))
| false | 23.529412 | [
"-import collections",
"-",
"-S = [list(eval(input())) for i in range(n)]",
"-S.sort(key=lambda x: len(x))",
"-table = collections.defaultdict(int)",
"-len_s = len(S[0])",
"-for i in range(1, n):",
"- for x in S[0]:",
"- if x in S[i]:",
"- S[i].pop(S[i].index(x))",
"- else:",
"- S[0].pop(S[0].index(x))",
"-S[0].sort()",
"-print((\"\".join(S[0])))",
"+S = [eval(input()) for i in range(n)]",
"+alpha = \"abcdefghijklmnopqrstuvwxyz\"",
"+count = [50] * 26",
"+for i, x in enumerate(alpha):",
"+ for s in S:",
"+ count[i] = min(count[i], s.count(x))",
"+ans = []",
"+for i, x in zip(count, alpha):",
"+ ans.append(x * i)",
"+print((\"\".join(ans)))"
] | false | 0.035691 | 0.034525 | 1.033757 | [
"s446670737",
"s328291410"
] |
u821588465 | p02613 | python | s676186445 | s082712161 | 159 | 145 | 16,108 | 15,936 | Accepted | Accepted | 8.81 | N = int(eval(input()))
S = list(str(eval(input())) for _ in range(N))
AC = 0
WA = 0
TLE = 0
RE = 0
for s in S:
if s =='AC':
AC +=1
elif s == 'WA':
WA +=1
elif s == 'TLE':
TLE += 1
elif s == 'RE':
RE +=1
print(('AC x {}'.format(str(AC))))
print(('WA x {}'.format(str(WA))))
print(('TLE x {}'.format(str(TLE))))
print(('RE x {}'.format(str(RE)))) | from collections import Counter
n = int(eval(input()))
a = list(eval(input()) for _ in range(n))
c = Counter(a)
print(('AC x '+str(c['AC'])))
print(('WA x '+str(c['WA'])))
print(('TLE x '+str(c['TLE'])))
print(('RE x '+str(c['RE'])))
| 21 | 9 | 395 | 223 | N = int(eval(input()))
S = list(str(eval(input())) for _ in range(N))
AC = 0
WA = 0
TLE = 0
RE = 0
for s in S:
if s == "AC":
AC += 1
elif s == "WA":
WA += 1
elif s == "TLE":
TLE += 1
elif s == "RE":
RE += 1
print(("AC x {}".format(str(AC))))
print(("WA x {}".format(str(WA))))
print(("TLE x {}".format(str(TLE))))
print(("RE x {}".format(str(RE))))
| from collections import Counter
n = int(eval(input()))
a = list(eval(input()) for _ in range(n))
c = Counter(a)
print(("AC x " + str(c["AC"])))
print(("WA x " + str(c["WA"])))
print(("TLE x " + str(c["TLE"])))
print(("RE x " + str(c["RE"])))
| false | 57.142857 | [
"-N = int(eval(input()))",
"-S = list(str(eval(input())) for _ in range(N))",
"-AC = 0",
"-WA = 0",
"-TLE = 0",
"-RE = 0",
"-for s in S:",
"- if s == \"AC\":",
"- AC += 1",
"- elif s == \"WA\":",
"- WA += 1",
"- elif s == \"TLE\":",
"- TLE += 1",
"- elif s == \"RE\":",
"- RE += 1",
"-print((\"AC x {}\".format(str(AC))))",
"-print((\"WA x {}\".format(str(WA))))",
"-print((\"TLE x {}\".format(str(TLE))))",
"-print((\"RE x {}\".format(str(RE))))",
"+from collections import Counter",
"+",
"+n = int(eval(input()))",
"+a = list(eval(input()) for _ in range(n))",
"+c = Counter(a)",
"+print((\"AC x \" + str(c[\"AC\"])))",
"+print((\"WA x \" + str(c[\"WA\"])))",
"+print((\"TLE x \" + str(c[\"TLE\"])))",
"+print((\"RE x \" + str(c[\"RE\"])))"
] | false | 0.048832 | 0.122038 | 0.400134 | [
"s676186445",
"s082712161"
] |
u941047297 | p02835 | python | s633807286 | s699084804 | 62 | 29 | 61,880 | 9,160 | Accepted | Accepted | 53.23 | a = list(map(int, input().split()))
if sum(a) >= 22:
print('bust')
else:
print('win') | def main():
A = list(map(int, input().split()))
print(('win' if sum(A) <= 21 else 'bust'))
if __name__ == '__main__':
main()
| 5 | 7 | 97 | 143 | a = list(map(int, input().split()))
if sum(a) >= 22:
print("bust")
else:
print("win")
| def main():
A = list(map(int, input().split()))
print(("win" if sum(A) <= 21 else "bust"))
if __name__ == "__main__":
main()
| false | 28.571429 | [
"-a = list(map(int, input().split()))",
"-if sum(a) >= 22:",
"- print(\"bust\")",
"-else:",
"- print(\"win\")",
"+def main():",
"+ A = list(map(int, input().split()))",
"+ print((\"win\" if sum(A) <= 21 else \"bust\"))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.046814 | 0.046437 | 1.008124 | [
"s633807286",
"s699084804"
] |
u380524497 | p03608 | python | s361156355 | s831152331 | 829 | 692 | 28,740 | 22,272 | Accepted | Accepted | 16.53 | import itertools
import sys
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline
n, m, r = list(map(int, input().split()))
visiting_town = list(map(int, input().split()))
edges = [[float('INF')]*n for _ in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
edges[a-1][b-1] = c
G = csgraph_from_dense(edges, null_value=float('INF'))
comp_dist = floyd_warshall(G, directed=False)
candidates = []
for route in itertools.permutations(visiting_town):
result = 0
for _from, to in zip(route[:-1], route[1:]):
dist = comp_dist[_from-1][to-1]
result += dist
candidates.append(result)
print((int(min(candidates))))
| import itertools
import sys
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import dijkstra
input = sys.stdin.readline
n, m, r = list(map(int, input().split()))
visiting_town = list(map(int, input().split()))
edges = [[float('INF')]*n for _ in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
edges[a-1][b-1] = c
G = csgraph_from_dense(edges, null_value=float('INF'))
comp_dist = dijkstra(G, directed=False)
candidates = []
for route in itertools.permutations(visiting_town):
result = 0
for _from, to in zip(route[:-1], route[1:]):
dist = comp_dist[_from-1][to-1]
result += dist
candidates.append(result)
print((int(min(candidates))))
| 27 | 27 | 753 | 741 | import itertools
import sys
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline
n, m, r = list(map(int, input().split()))
visiting_town = list(map(int, input().split()))
edges = [[float("INF")] * n for _ in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
edges[a - 1][b - 1] = c
G = csgraph_from_dense(edges, null_value=float("INF"))
comp_dist = floyd_warshall(G, directed=False)
candidates = []
for route in itertools.permutations(visiting_town):
result = 0
for _from, to in zip(route[:-1], route[1:]):
dist = comp_dist[_from - 1][to - 1]
result += dist
candidates.append(result)
print((int(min(candidates))))
| import itertools
import sys
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import dijkstra
input = sys.stdin.readline
n, m, r = list(map(int, input().split()))
visiting_town = list(map(int, input().split()))
edges = [[float("INF")] * n for _ in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
edges[a - 1][b - 1] = c
G = csgraph_from_dense(edges, null_value=float("INF"))
comp_dist = dijkstra(G, directed=False)
candidates = []
for route in itertools.permutations(visiting_town):
result = 0
for _from, to in zip(route[:-1], route[1:]):
dist = comp_dist[_from - 1][to - 1]
result += dist
candidates.append(result)
print((int(min(candidates))))
| false | 0 | [
"-from scipy.sparse.csgraph import floyd_warshall",
"+from scipy.sparse.csgraph import dijkstra",
"-comp_dist = floyd_warshall(G, directed=False)",
"+comp_dist = dijkstra(G, directed=False)"
] | false | 0.521407 | 0.239188 | 2.17991 | [
"s361156355",
"s831152331"
] |
u129459452 | p02898 | python | s813605240 | s085664577 | 48 | 44 | 11,912 | 11,912 | Accepted | Accepted | 8.33 | N, K=list(map(int, input().split()))
H = list(map(int, input().split()))
c = 0
for h in H:
if h >=K:
c += 1
print(c) | n,k=list(map(int,input().split()))
h=list(map(int,input().split()))
print((len([i for i in h if i>=k]))) | 7 | 3 | 128 | 98 | N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
c = 0
for h in H:
if h >= K:
c += 1
print(c)
| n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
print((len([i for i in h if i >= k])))
| false | 57.142857 | [
"-N, K = list(map(int, input().split()))",
"-H = list(map(int, input().split()))",
"-c = 0",
"-for h in H:",
"- if h >= K:",
"- c += 1",
"-print(c)",
"+n, k = list(map(int, input().split()))",
"+h = list(map(int, input().split()))",
"+print((len([i for i in h if i >= k])))"
] | false | 0.042616 | 0.049022 | 0.869332 | [
"s813605240",
"s085664577"
] |
u254871849 | p02722 | python | s094964684 | s149459365 | 273 | 210 | 3,064 | 3,952 | Accepted | Accepted | 23.08 | import sys
from math import sqrt, floor
def divisors(n):
res = set()
for i in range(1, floor(sqrt(n)) + 1):
if n % i == 0:
res.add(i)
res.add(n // i)
return res
n = int(sys.stdin.readline().rstrip())
def main():
res = divisors(n - 1)
cnt = len(res) - 1 + 1
for i in range(2, floor(sqrt(n)) + 1):
if i in res: continue
m = n
while m % i == 0:
m //= i
if (m - 1) % i == 0:
cnt += 1
print(cnt)
if __name__ == '__main__':
main() | import sys
from math import sqrt, floor
def divisors(n):
res = set()
for i in range(1, floor(sqrt(n)) + 1):
if n % i == 0:
res.add(i)
res.add(n // i)
return res - set([1])
n = int(sys.stdin.readline().rstrip())
def main():
res = divisors(n - 1)
cnt = len(res)
for i in divisors(n):
if i in res: continue
m = n
while m % i == 0:
m //= i
if (m - 1) % i == 0:
cnt += 1
print(cnt)
if __name__ == '__main__':
main() | 27 | 27 | 583 | 562 | import sys
from math import sqrt, floor
def divisors(n):
res = set()
for i in range(1, floor(sqrt(n)) + 1):
if n % i == 0:
res.add(i)
res.add(n // i)
return res
n = int(sys.stdin.readline().rstrip())
def main():
res = divisors(n - 1)
cnt = len(res) - 1 + 1
for i in range(2, floor(sqrt(n)) + 1):
if i in res:
continue
m = n
while m % i == 0:
m //= i
if (m - 1) % i == 0:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| import sys
from math import sqrt, floor
def divisors(n):
res = set()
for i in range(1, floor(sqrt(n)) + 1):
if n % i == 0:
res.add(i)
res.add(n // i)
return res - set([1])
n = int(sys.stdin.readline().rstrip())
def main():
res = divisors(n - 1)
cnt = len(res)
for i in divisors(n):
if i in res:
continue
m = n
while m % i == 0:
m //= i
if (m - 1) % i == 0:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| false | 0 | [
"- return res",
"+ return res - set([1])",
"- cnt = len(res) - 1 + 1",
"- for i in range(2, floor(sqrt(n)) + 1):",
"+ cnt = len(res)",
"+ for i in divisors(n):",
"- if (m - 1) % i == 0:",
"- cnt += 1",
"+ if (m - 1) % i == 0:",
"+ cnt += 1"
] | false | 0.1989 | 0.05589 | 3.558769 | [
"s094964684",
"s149459365"
] |
u945181840 | p03816 | python | s380915349 | s135477683 | 106 | 66 | 14,452 | 18,648 | Accepted | Accepted | 37.74 | from itertools import groupby
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
a = []
for i, j in groupby(A):
a.append(len(list(j)))
def f(x):
while x >= 3:
x = x // 3 + x % 3
return x
a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)
if two % 2 == 0:
print((one + two))
else:
print((one + two - 1)) | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
a = list(Counter(A).values())
def f(x):
while x >= 3:
x = x // 3 + x % 3
return x
a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)
if two % 2 == 0:
print((one + two))
else:
print((one + two - 1)) | 24 | 20 | 371 | 331 | from itertools import groupby
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
a = []
for i, j in groupby(A):
a.append(len(list(j)))
def f(x):
while x >= 3:
x = x // 3 + x % 3
return x
a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)
if two % 2 == 0:
print((one + two))
else:
print((one + two - 1))
| from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
a = list(Counter(A).values())
def f(x):
while x >= 3:
x = x // 3 + x % 3
return x
a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)
if two % 2 == 0:
print((one + two))
else:
print((one + two - 1))
| false | 16.666667 | [
"-from itertools import groupby",
"+from collections import Counter",
"-A.sort()",
"-a = []",
"-for i, j in groupby(A):",
"- a.append(len(list(j)))",
"+a = list(Counter(A).values())"
] | false | 0.036665 | 0.036681 | 0.999563 | [
"s380915349",
"s135477683"
] |
u133936772 | p02695 | python | s507393483 | s149238792 | 1,072 | 547 | 9,100 | 9,128 | Accepted | Accepted | 48.97 | f=lambda:list(map(int,input().split()))
n,m,q=f()
lq=[tuple(f()) for _ in range(q)]
ans=0
from itertools import *
for t in combinations_with_replacement(list(range(m)),n):
s=0
for a,b,c,d in lq:
if t[b-1]-t[a-1]==c: s+=d
ans=max(ans,s)
print(ans) | f=lambda:list(map(int,input().split()))
n,m,q=f()
Q=[list(f())for _ in range(q)]
from itertools import*
print((max(sum(d for a,b,c,d in Q if l[b-1]-l[a-1]==c)for l in combinations_with_replacement(list(range(m)),n)))) | 11 | 5 | 254 | 207 | f = lambda: list(map(int, input().split()))
n, m, q = f()
lq = [tuple(f()) for _ in range(q)]
ans = 0
from itertools import *
for t in combinations_with_replacement(list(range(m)), n):
s = 0
for a, b, c, d in lq:
if t[b - 1] - t[a - 1] == c:
s += d
ans = max(ans, s)
print(ans)
| f = lambda: list(map(int, input().split()))
n, m, q = f()
Q = [list(f()) for _ in range(q)]
from itertools import *
print(
(
max(
sum(d for a, b, c, d in Q if l[b - 1] - l[a - 1] == c)
for l in combinations_with_replacement(list(range(m)), n)
)
)
)
| false | 54.545455 | [
"-lq = [tuple(f()) for _ in range(q)]",
"-ans = 0",
"+Q = [list(f()) for _ in range(q)]",
"-for t in combinations_with_replacement(list(range(m)), n):",
"- s = 0",
"- for a, b, c, d in lq:",
"- if t[b - 1] - t[a - 1] == c:",
"- s += d",
"- ans = max(ans, s)",
"-print(ans)",
"+print(",
"+ (",
"+ max(",
"+ sum(d for a, b, c, d in Q if l[b - 1] - l[a - 1] == c)",
"+ for l in combinations_with_replacement(list(range(m)), n)",
"+ )",
"+ )",
"+)"
] | false | 0.053641 | 0.051375 | 1.044125 | [
"s507393483",
"s149238792"
] |
u327466606 | p02560 | python | s851134290 | s201578295 | 412 | 302 | 70,984 | 98,892 | Accepted | Accepted | 26.7 | def floor_linear_sum(n,m,a,b):
res = 0
while True:
if a >= m:
res += (n-1)*n*(a//m)//2
a %= m
if b >= m:
res += n * (b//m)
b %= m
y_max = (a*n+b)//m
if y_max == 0:
return res
x_max = y_max*m-b
res += (n - (x_max + a - 1)//a)*y_max
n,m,a,b = y_max, a, m, (a-x_max)%a
T = int(eval(input()))
for _ in range(T):
print((floor_linear_sum(*list(map(int,input().split())))))
| def floor_linear_sum(n,m,a,b):
"""
returns sum((a*i+b)//m for i in range(n))
"""
res = 0
while True:
if a >= m:
res += (n-1)*n*(a//m)//2
a %= m
if b >= m:
res += n * (b//m)
b %= m
y_max = (a*n+b)//m
if y_max == 0:
return res
nx_max = b - y_max*m
res += (n + nx_max//a)*y_max
n,m,a,b = y_max, a, m, nx_max%a
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
T = int(readline())
m = list(map(int,read().split()))
for t in zip(m,m,m,m):
print((floor_linear_sum(*t)))
| 20 | 28 | 502 | 653 | def floor_linear_sum(n, m, a, b):
res = 0
while True:
if a >= m:
res += (n - 1) * n * (a // m) // 2
a %= m
if b >= m:
res += n * (b // m)
b %= m
y_max = (a * n + b) // m
if y_max == 0:
return res
x_max = y_max * m - b
res += (n - (x_max + a - 1) // a) * y_max
n, m, a, b = y_max, a, m, (a - x_max) % a
T = int(eval(input()))
for _ in range(T):
print((floor_linear_sum(*list(map(int, input().split())))))
| def floor_linear_sum(n, m, a, b):
"""
returns sum((a*i+b)//m for i in range(n))
"""
res = 0
while True:
if a >= m:
res += (n - 1) * n * (a // m) // 2
a %= m
if b >= m:
res += n * (b // m)
b %= m
y_max = (a * n + b) // m
if y_max == 0:
return res
nx_max = b - y_max * m
res += (n + nx_max // a) * y_max
n, m, a, b = y_max, a, m, nx_max % a
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
T = int(readline())
m = list(map(int, read().split()))
for t in zip(m, m, m, m):
print((floor_linear_sum(*t)))
| false | 28.571429 | [
"+ \"\"\"",
"+ returns sum((a*i+b)//m for i in range(n))",
"+ \"\"\"",
"- x_max = y_max * m - b",
"- res += (n - (x_max + a - 1) // a) * y_max",
"- n, m, a, b = y_max, a, m, (a - x_max) % a",
"+ nx_max = b - y_max * m",
"+ res += (n + nx_max // a) * y_max",
"+ n, m, a, b = y_max, a, m, nx_max % a",
"-T = int(eval(input()))",
"-for _ in range(T):",
"- print((floor_linear_sum(*list(map(int, input().split())))))",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+T = int(readline())",
"+m = list(map(int, read().split()))",
"+for t in zip(m, m, m, m):",
"+ print((floor_linear_sum(*t)))"
] | false | 0.037387 | 0.037254 | 1.003577 | [
"s851134290",
"s201578295"
] |
u512212329 | p02585 | python | s445348238 | s620877963 | 901 | 828 | 83,356 | 84,428 | Accepted | Accepted | 8.1 | from itertools import accumulate
def main():
cells, moves = [int(x) for x in input().split()]
jumps_from = [int(x) - 1 for x in input().split()]
score_on = [int(x) for x in input().split()]
ans = - 10**10
for start in range(cells):
route = []
route_append = route.append
position = start
while True:
route_append(score_on[position])
position = jumps_from[position]
if position == start: # Looped
break
length = len(route)
total = sum(route)
accum_tmp = 0
for i, score in enumerate(route):
accum_tmp += score
if i + 1 > moves:
break
accum = accum_tmp
if total > 0:
accum += total * ((moves - (i + 1)) // length)
ans = max(ans, accum)
# if total > 0:
# q, mod = divmod(moves, length)
# if mod == 0:
# candidate = total * q
# else:
# candidate = max(list(accumulate(route))[:mod]) + total * q
# else:
# candidate = max(list(accumulate(route))[:min(moves, length)])
# ans = max(ans, candidate)
return ans
if __name__ == '__main__':
ans = main()
print(ans)
| def main():
cells, can_jump = [int(x) for x in input().split()]
jumps_from = [int(x) - 1 for x in input().split()]
score_on = [int(x) for x in input().split()]
ans = - 10**10
for start in range(cells):
route = []
position = start
while True:
route.append(score_on[position])
position = jumps_from[position]
if position == start: # Looped
break
length = len(route)
total = sum(route)
accum_tmp = 0
for jumping, score in enumerate(route):
accum_tmp += score
if jumping + 1 > can_jump:
break
accum = accum_tmp
if total > 0:
accum += total * ((can_jump - (jumping + 1)) // length)
ans = max(ans, accum)
return ans
if __name__ == '__main__':
ans = main()
print(ans)
| 46 | 32 | 1,349 | 929 | from itertools import accumulate
def main():
cells, moves = [int(x) for x in input().split()]
jumps_from = [int(x) - 1 for x in input().split()]
score_on = [int(x) for x in input().split()]
ans = -(10**10)
for start in range(cells):
route = []
route_append = route.append
position = start
while True:
route_append(score_on[position])
position = jumps_from[position]
if position == start: # Looped
break
length = len(route)
total = sum(route)
accum_tmp = 0
for i, score in enumerate(route):
accum_tmp += score
if i + 1 > moves:
break
accum = accum_tmp
if total > 0:
accum += total * ((moves - (i + 1)) // length)
ans = max(ans, accum)
# if total > 0:
# q, mod = divmod(moves, length)
# if mod == 0:
# candidate = total * q
# else:
# candidate = max(list(accumulate(route))[:mod]) + total * q
# else:
# candidate = max(list(accumulate(route))[:min(moves, length)])
# ans = max(ans, candidate)
return ans
if __name__ == "__main__":
ans = main()
print(ans)
| def main():
cells, can_jump = [int(x) for x in input().split()]
jumps_from = [int(x) - 1 for x in input().split()]
score_on = [int(x) for x in input().split()]
ans = -(10**10)
for start in range(cells):
route = []
position = start
while True:
route.append(score_on[position])
position = jumps_from[position]
if position == start: # Looped
break
length = len(route)
total = sum(route)
accum_tmp = 0
for jumping, score in enumerate(route):
accum_tmp += score
if jumping + 1 > can_jump:
break
accum = accum_tmp
if total > 0:
accum += total * ((can_jump - (jumping + 1)) // length)
ans = max(ans, accum)
return ans
if __name__ == "__main__":
ans = main()
print(ans)
| false | 30.434783 | [
"-from itertools import accumulate",
"-",
"-",
"- cells, moves = [int(x) for x in input().split()]",
"+ cells, can_jump = [int(x) for x in input().split()]",
"- route_append = route.append",
"- route_append(score_on[position])",
"+ route.append(score_on[position])",
"- for i, score in enumerate(route):",
"+ for jumping, score in enumerate(route):",
"- if i + 1 > moves:",
"+ if jumping + 1 > can_jump:",
"- accum += total * ((moves - (i + 1)) // length)",
"+ accum += total * ((can_jump - (jumping + 1)) // length)",
"- # if total > 0:",
"- # q, mod = divmod(moves, length)",
"- # if mod == 0:",
"- # candidate = total * q",
"- # else:",
"- # candidate = max(list(accumulate(route))[:mod]) + total * q",
"- # else:",
"- # candidate = max(list(accumulate(route))[:min(moves, length)])",
"- # ans = max(ans, candidate)"
] | false | 0.042885 | 0.082136 | 0.522121 | [
"s445348238",
"s620877963"
] |
u471214054 | p02720 | python | s584307683 | s928266805 | 239 | 181 | 45,404 | 40,560 | Accepted | Accepted | 24.27 | import sys
def is_lunlun(x):
x_str = str(x)
for i in range(len(x_str)-1):
if abs(int(x_str[i]) - int(x_str[i+1])) > 1:
return False
return True
def main():
k = int(eval(input()))
lunlun_map = {
0: [0, 1],
1: [0, 1, 2],
2: [1, 2, 3],
3: [2, 3, 4],
4: [3, 4, 5],
5: [4, 5, 6],
6: [5, 6, 7],
7: [6, 7, 8],
8: [7, 8, 9],
9: [8, 9]
}
if k < 10:
print(k)
sys.exit()
count = 9
all_lunluns = [list(range(1, 10))]
i = 0
while True:
for lunlun in all_lunluns[i]:
least = int(str(lunlun)[-1])
lunluns = []
for j in lunlun_map[least]:
new_lunlun = int(str(lunlun) + str(j))
lunluns.append(new_lunlun)
count += 1
if count == k:
print(new_lunlun)
sys.exit(0)
all_lunluns.append(lunluns)
i += 1
if __name__ == "__main__":
main() | # Assumed solution
from collections import deque
def main():
k = int(eval(input()))
queue = deque()
for i in range(1, 10):
queue.append(i)
l = 0
for _ in range(k):
l = queue.popleft()
r = l % 10
if r != 0:
queue.append(l * 10 + r - 1)
queue.append(l * 10 + r)
if r != 9:
queue.append(l * 10 + r + 1)
print(l)
if __name__ == "__main__":
main()
| 48 | 26 | 1,092 | 469 | import sys
def is_lunlun(x):
x_str = str(x)
for i in range(len(x_str) - 1):
if abs(int(x_str[i]) - int(x_str[i + 1])) > 1:
return False
return True
def main():
k = int(eval(input()))
lunlun_map = {
0: [0, 1],
1: [0, 1, 2],
2: [1, 2, 3],
3: [2, 3, 4],
4: [3, 4, 5],
5: [4, 5, 6],
6: [5, 6, 7],
7: [6, 7, 8],
8: [7, 8, 9],
9: [8, 9],
}
if k < 10:
print(k)
sys.exit()
count = 9
all_lunluns = [list(range(1, 10))]
i = 0
while True:
for lunlun in all_lunluns[i]:
least = int(str(lunlun)[-1])
lunluns = []
for j in lunlun_map[least]:
new_lunlun = int(str(lunlun) + str(j))
lunluns.append(new_lunlun)
count += 1
if count == k:
print(new_lunlun)
sys.exit(0)
all_lunluns.append(lunluns)
i += 1
if __name__ == "__main__":
main()
| # Assumed solution
from collections import deque
def main():
k = int(eval(input()))
queue = deque()
for i in range(1, 10):
queue.append(i)
l = 0
for _ in range(k):
l = queue.popleft()
r = l % 10
if r != 0:
queue.append(l * 10 + r - 1)
queue.append(l * 10 + r)
if r != 9:
queue.append(l * 10 + r + 1)
print(l)
if __name__ == "__main__":
main()
| false | 45.833333 | [
"-import sys",
"-",
"-",
"-def is_lunlun(x):",
"- x_str = str(x)",
"- for i in range(len(x_str) - 1):",
"- if abs(int(x_str[i]) - int(x_str[i + 1])) > 1:",
"- return False",
"- return True",
"+# Assumed solution",
"+from collections import deque",
"- lunlun_map = {",
"- 0: [0, 1],",
"- 1: [0, 1, 2],",
"- 2: [1, 2, 3],",
"- 3: [2, 3, 4],",
"- 4: [3, 4, 5],",
"- 5: [4, 5, 6],",
"- 6: [5, 6, 7],",
"- 7: [6, 7, 8],",
"- 8: [7, 8, 9],",
"- 9: [8, 9],",
"- }",
"- if k < 10:",
"- print(k)",
"- sys.exit()",
"- count = 9",
"- all_lunluns = [list(range(1, 10))]",
"- i = 0",
"- while True:",
"- for lunlun in all_lunluns[i]:",
"- least = int(str(lunlun)[-1])",
"- lunluns = []",
"- for j in lunlun_map[least]:",
"- new_lunlun = int(str(lunlun) + str(j))",
"- lunluns.append(new_lunlun)",
"- count += 1",
"- if count == k:",
"- print(new_lunlun)",
"- sys.exit(0)",
"- all_lunluns.append(lunluns)",
"- i += 1",
"+ queue = deque()",
"+ for i in range(1, 10):",
"+ queue.append(i)",
"+ l = 0",
"+ for _ in range(k):",
"+ l = queue.popleft()",
"+ r = l % 10",
"+ if r != 0:",
"+ queue.append(l * 10 + r - 1)",
"+ queue.append(l * 10 + r)",
"+ if r != 9:",
"+ queue.append(l * 10 + r + 1)",
"+ print(l)"
] | false | 0.062212 | 0.050325 | 1.236213 | [
"s584307683",
"s928266805"
] |
u932719058 | p03289 | python | s584627980 | s198470880 | 22 | 17 | 3,444 | 2,940 | Accepted | Accepted | 22.73 | import copy
s = list(eval(input()))
Ccnt = 0
if s[0] == 'A' :
for i in copy.copy(s[2:-1]) :
if i == 'C' :
Ccnt += 1
s.remove(i)
s.remove(s[0])
if Ccnt == 1 and ''.join(s) == ''.join(s).lower() :
print('AC')
exit()
print('WA') | s = eval(input())
Ccnt = 0
if s[0] == 'A' and s[2:-1].count('C') == 1 and s[1:].replace('C', '').islower():
print('AC')
exit()
print('WA') | 13 | 6 | 246 | 169 | import copy
s = list(eval(input()))
Ccnt = 0
if s[0] == "A":
for i in copy.copy(s[2:-1]):
if i == "C":
Ccnt += 1
s.remove(i)
s.remove(s[0])
if Ccnt == 1 and "".join(s) == "".join(s).lower():
print("AC")
exit()
print("WA")
| s = eval(input())
Ccnt = 0
if s[0] == "A" and s[2:-1].count("C") == 1 and s[1:].replace("C", "").islower():
print("AC")
exit()
print("WA")
| false | 53.846154 | [
"-import copy",
"-",
"-s = list(eval(input()))",
"+s = eval(input())",
"-if s[0] == \"A\":",
"- for i in copy.copy(s[2:-1]):",
"- if i == \"C\":",
"- Ccnt += 1",
"- s.remove(i)",
"- s.remove(s[0])",
"- if Ccnt == 1 and \"\".join(s) == \"\".join(s).lower():",
"- print(\"AC\")",
"- exit()",
"+if s[0] == \"A\" and s[2:-1].count(\"C\") == 1 and s[1:].replace(\"C\", \"\").islower():",
"+ print(\"AC\")",
"+ exit()"
] | false | 0.046164 | 0.126985 | 0.363541 | [
"s584627980",
"s198470880"
] |
u581187895 | p03161 | python | s814474089 | s253337167 | 1,911 | 1,718 | 22,804 | 21,268 | Accepted | Accepted | 10.1 | import sys
input = sys.stdin.readline
import numpy as np
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = np.zeros(N, dtype=int)
h = np.array(h)
for i in range(1, N):
start = max(0, i-K)
dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[N-1])) | import numpy as np
N, K = list(map(int, input().split()))
h = np.array(input().split(), dtype='int32')
dp = np.zeros(N, dtype='int32')
for i in range(1, N):
start = 0 if i < K else i-K
dp[i] = np.min(dp[start:i] + np.abs(h[i]-h[start:i]))
print((dp[-1])) | 15 | 10 | 305 | 263 | import sys
input = sys.stdin.readline
import numpy as np
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = np.zeros(N, dtype=int)
h = np.array(h)
for i in range(1, N):
start = max(0, i - K)
dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[N - 1]))
| import numpy as np
N, K = list(map(int, input().split()))
h = np.array(input().split(), dtype="int32")
dp = np.zeros(N, dtype="int32")
for i in range(1, N):
start = 0 if i < K else i - K
dp[i] = np.min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[-1]))
| false | 33.333333 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-h = list(map(int, input().split()))",
"-dp = np.zeros(N, dtype=int)",
"-h = np.array(h)",
"+h = np.array(input().split(), dtype=\"int32\")",
"+dp = np.zeros(N, dtype=\"int32\")",
"- start = max(0, i - K)",
"- dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))",
"-print((dp[N - 1]))",
"+ start = 0 if i < K else i - K",
"+ dp[i] = np.min(dp[start:i] + np.abs(h[i] - h[start:i]))",
"+print((dp[-1]))"
] | false | 0.203154 | 0.32916 | 0.617189 | [
"s814474089",
"s253337167"
] |
u633068244 | p01268 | python | s286473016 | s678766805 | 240 | 200 | 9,024 | 9,028 | Accepted | Accepted | 16.67 | import itertools
r = 110000
s = int(r*0.5)
p = [1] * r
p[0] = 0
for i in range(1,s):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
while 1:
N,P = list(map(int,input().split()))
if N == -1: break
i = N + 1
prime = [0]*22
j = 0
while j < 22:
if p[i-1] == 1:
prime[j] = i
j += 1
i += 1
wa = sorted([sum(comb) for comb in itertools.combinations(prime,2)] + [2*a for a in prime])
print(wa[P-1]) | import itertools
r = 110000
s = int(r*0.5)
p = [1] * r
p[0] = 0
for i in range(1,s):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
while 1:
N,P = list(map(int,input().split()))
if N == -1: break
i = N + 1
prime = [0]*(13 + P/10)
j = 0
while j < (13 + P/10):
if p[i-1] == 1:
prime[j] = i
j += 1
i += 1
wa = sorted([sum(comb) for comb in itertools.combinations(prime,2)] + [2*a for a in prime])
print(wa[P-1]) | 22 | 22 | 442 | 460 | import itertools
r = 110000
s = int(r * 0.5)
p = [1] * r
p[0] = 0
for i in range(1, s):
if p[i]:
p[2 * i + 1 :: i + 1] = [0 for x in range(2 * i + 1, r, i + 1)]
while 1:
N, P = list(map(int, input().split()))
if N == -1:
break
i = N + 1
prime = [0] * 22
j = 0
while j < 22:
if p[i - 1] == 1:
prime[j] = i
j += 1
i += 1
wa = sorted(
[sum(comb) for comb in itertools.combinations(prime, 2)]
+ [2 * a for a in prime]
)
print(wa[P - 1])
| import itertools
r = 110000
s = int(r * 0.5)
p = [1] * r
p[0] = 0
for i in range(1, s):
if p[i]:
p[2 * i + 1 :: i + 1] = [0 for x in range(2 * i + 1, r, i + 1)]
while 1:
N, P = list(map(int, input().split()))
if N == -1:
break
i = N + 1
prime = [0] * (13 + P / 10)
j = 0
while j < (13 + P / 10):
if p[i - 1] == 1:
prime[j] = i
j += 1
i += 1
wa = sorted(
[sum(comb) for comb in itertools.combinations(prime, 2)]
+ [2 * a for a in prime]
)
print(wa[P - 1])
| false | 0 | [
"- prime = [0] * 22",
"+ prime = [0] * (13 + P / 10)",
"- while j < 22:",
"+ while j < (13 + P / 10):"
] | false | 0.090259 | 0.088138 | 1.024064 | [
"s286473016",
"s678766805"
] |
u887207211 | p03779 | python | s632335997 | s048813475 | 27 | 22 | 3,060 | 3,060 | Accepted | Accepted | 18.52 | import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
na = lambda : list(map(int, stdin.readline().split()))
ni = lambda : int(ns())
def main():
n = ni()
f = lambda x: (x * (x+1)) // 2
for i in range(1, n+1):
if (f(i) >= n):
print(i)
return
main() | import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
def main():
n = ni()
t = 0
for i in range(1, n + 1):
t += i
if t >= n:
print(i)
return
main() | 15 | 17 | 294 | 286 | import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))
ni = lambda: int(ns())
def main():
n = ni()
f = lambda x: (x * (x + 1)) // 2
for i in range(1, n + 1):
if f(i) >= n:
print(i)
return
main()
| import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
def main():
n = ni()
t = 0
for i in range(1, n + 1):
t += i
if t >= n:
print(i)
return
main()
| false | 11.764706 | [
"+ni = lambda: int(ns())",
"-ni = lambda: int(ns())",
"- f = lambda x: (x * (x + 1)) // 2",
"+ t = 0",
"- if f(i) >= n:",
"+ t += i",
"+ if t >= n:"
] | false | 0.180077 | 0.172661 | 1.04295 | [
"s632335997",
"s048813475"
] |
u252828980 | p02623 | python | s849690297 | s720569804 | 315 | 280 | 40,616 | 40,444 | Accepted | Accepted | 11.11 | n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
a[i] += a[i-1]
for i in range(1,m):
b[i] += b[i-1]
a = [0]+a
b = [0]+b
ans = 0
ALL = 0
from bisect import bisect
for i in range(n+1):
ALL = a[i]
if ALL > k:
continue
else:
idx = bisect(b,k-ALL)
#print(i,ALL,idx)
ans = max(ans,i+idx-1)
print(ans) | n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
a[i] += a[i-1]
for i in range(1,m):
b[i] += b[i-1]
a = [0]+a
b = [0]+b
ans = 0
ALL = 0
j = m
for i in range(n+1):
if a[i] > k:
continue
else:
while k-a[i] < b[j] :
j -=1
ans = max(ans,i+j)
print(ans) | 22 | 22 | 439 | 394 | n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(1, n):
a[i] += a[i - 1]
for i in range(1, m):
b[i] += b[i - 1]
a = [0] + a
b = [0] + b
ans = 0
ALL = 0
from bisect import bisect
for i in range(n + 1):
ALL = a[i]
if ALL > k:
continue
else:
idx = bisect(b, k - ALL)
# print(i,ALL,idx)
ans = max(ans, i + idx - 1)
print(ans)
| n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(1, n):
a[i] += a[i - 1]
for i in range(1, m):
b[i] += b[i - 1]
a = [0] + a
b = [0] + b
ans = 0
ALL = 0
j = m
for i in range(n + 1):
if a[i] > k:
continue
else:
while k - a[i] < b[j]:
j -= 1
ans = max(ans, i + j)
print(ans)
| false | 0 | [
"-from bisect import bisect",
"-",
"+j = m",
"- ALL = a[i]",
"- if ALL > k:",
"+ if a[i] > k:",
"- idx = bisect(b, k - ALL)",
"- # print(i,ALL,idx)",
"- ans = max(ans, i + idx - 1)",
"+ while k - a[i] < b[j]:",
"+ j -= 1",
"+ ans = max(ans, i + j)"
] | false | 0.040271 | 0.04325 | 0.931122 | [
"s849690297",
"s720569804"
] |
u305366205 | p02779 | python | s054400134 | s736241603 | 122 | 109 | 26,804 | 25,324 | Accepted | Accepted | 10.66 | n = int(eval(input()))
a = list(map(int, input().split()))
now = set([])
for i in a:
if i in now:
print('NO')
exit()
now.add(i)
print('YES') | n = int(eval(input()))
a = list(map(int, input().split()))
now = set()
for i in a:
now.add(i)
if len(now) == n:
print('YES')
else:
print('NO') | 9 | 9 | 166 | 156 | n = int(eval(input()))
a = list(map(int, input().split()))
now = set([])
for i in a:
if i in now:
print("NO")
exit()
now.add(i)
print("YES")
| n = int(eval(input()))
a = list(map(int, input().split()))
now = set()
for i in a:
now.add(i)
if len(now) == n:
print("YES")
else:
print("NO")
| false | 0 | [
"-now = set([])",
"+now = set()",
"- if i in now:",
"- print(\"NO\")",
"- exit()",
"-print(\"YES\")",
"+if len(now) == n:",
"+ print(\"YES\")",
"+else:",
"+ print(\"NO\")"
] | false | 0.101422 | 0.100975 | 1.004429 | [
"s054400134",
"s736241603"
] |
u225388820 | p02588 | python | s729023651 | s230230903 | 714 | 617 | 88,204 | 94,348 | Accepted | Accepted | 13.59 | class BIT:
def __init__(self, n):
#A1 ... AnใฎBIT(1-indexed)
self.BIT = [0] * (n + 1)
self.n = n
#A1 ~ Aiใพใงใฎๅ O(logN)
def query(self, idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx & (-idx)
return res_sum
#Ai += x O(logN)
def add(self, idx, x):
while idx <= self.n:
self.BIT[idx] += x
idx += idx&(-idx)
return
def get_int(f):
if "." not in f:
return int(f),0
return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(eval(input()))
p = []
for i in range(n):
a, b = get_int(eval(input()))
c, d = 0, 0
while a % 2 == 0:
c += 1
a //= 2
while a % 5 == 0:
d += 1
a //= 5
c -= b
d -= b
p.append((c, d))
p.sort()
now = n - 1
t = BIT(200)
ans = 0
for i in range(n):
for j in range(now, i, -1):
if p[i][0] + p[j][0] >= 0:
t.add(-p[j][1] + 100, 1)
now -= 1
else:
break
if now < i:
t.add(-p[i][1] + 100, -1)
ans += max(0, t.query(100 + p[i][1]))
print(ans) | class BIT:
def __init__(self, n):
#A1 ... AnใฎBIT(1-indexed)
self.BIT = [0] * (n + 1)
self.n = n
#A1 ~ Aiใพใงใฎๅ O(logN)
def query(self, idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx & (-idx)
return res_sum
#Ai += x O(logN)
def add(self, idx, x):
while idx <= self.n:
self.BIT[idx] += x
idx += idx&(-idx)
return
def get_int(f):
if "." not in f:
return int(f),0
return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(eval(input()))
p = []
for i in range(n):
a, b = get_int(eval(input()))
c, d = 0, 0
while a % 2 == 0:
c += 1
a //= 2
while a % 5 == 0:
d += 1
a //= 5
c -= b
d -= b
p.append((c, d))
p.sort()
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
for j in range(now, i, -1):
if p[i][0] + p[j][0] >= 0:
t.add(-p[j][1] + 25, 1)
now -= 1
else:
break
if now < i:
t.add(-p[i][1] + 25, -1)
ans += max(0, t.query(25 + p[i][1]))
print(ans) | 54 | 54 | 1,192 | 1,188 | class BIT:
def __init__(self, n):
# A1 ... AnใฎBIT(1-indexed)
self.BIT = [0] * (n + 1)
self.n = n
# A1 ~ Aiใพใงใฎๅ O(logN)
def query(self, idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx & (-idx)
return res_sum
# Ai += x O(logN)
def add(self, idx, x):
while idx <= self.n:
self.BIT[idx] += x
idx += idx & (-idx)
return
def get_int(f):
if "." not in f:
return int(f), 0
return int(f.replace(".", "")), len(f) - f.index(".") - 1
n = int(eval(input()))
p = []
for i in range(n):
a, b = get_int(eval(input()))
c, d = 0, 0
while a % 2 == 0:
c += 1
a //= 2
while a % 5 == 0:
d += 1
a //= 5
c -= b
d -= b
p.append((c, d))
p.sort()
now = n - 1
t = BIT(200)
ans = 0
for i in range(n):
for j in range(now, i, -1):
if p[i][0] + p[j][0] >= 0:
t.add(-p[j][1] + 100, 1)
now -= 1
else:
break
if now < i:
t.add(-p[i][1] + 100, -1)
ans += max(0, t.query(100 + p[i][1]))
print(ans)
| class BIT:
def __init__(self, n):
# A1 ... AnใฎBIT(1-indexed)
self.BIT = [0] * (n + 1)
self.n = n
# A1 ~ Aiใพใงใฎๅ O(logN)
def query(self, idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx & (-idx)
return res_sum
# Ai += x O(logN)
def add(self, idx, x):
while idx <= self.n:
self.BIT[idx] += x
idx += idx & (-idx)
return
def get_int(f):
if "." not in f:
return int(f), 0
return int(f.replace(".", "")), len(f) - f.index(".") - 1
n = int(eval(input()))
p = []
for i in range(n):
a, b = get_int(eval(input()))
c, d = 0, 0
while a % 2 == 0:
c += 1
a //= 2
while a % 5 == 0:
d += 1
a //= 5
c -= b
d -= b
p.append((c, d))
p.sort()
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
for j in range(now, i, -1):
if p[i][0] + p[j][0] >= 0:
t.add(-p[j][1] + 25, 1)
now -= 1
else:
break
if now < i:
t.add(-p[i][1] + 25, -1)
ans += max(0, t.query(25 + p[i][1]))
print(ans)
| false | 0 | [
"-t = BIT(200)",
"+t = BIT(50)",
"- t.add(-p[j][1] + 100, 1)",
"+ t.add(-p[j][1] + 25, 1)",
"- t.add(-p[i][1] + 100, -1)",
"- ans += max(0, t.query(100 + p[i][1]))",
"+ t.add(-p[i][1] + 25, -1)",
"+ ans += max(0, t.query(25 + p[i][1]))"
] | false | 0.045045 | 0.041517 | 1.084966 | [
"s729023651",
"s230230903"
] |
u941438707 | p02873 | python | s287693768 | s927299254 | 369 | 333 | 23,336 | 23,336 | Accepted | Accepted | 9.76 | s=eval(input())
n=len(s)
a=[0]*(n+1)
for i in range(n):
if s[i]=="<":
a[i+1]=a[i]+1
for i in reversed(list(range(n))):
if s[i]==">":
a[i]=max(a[i+1]+1,a[i])
print((sum(a))) | s=eval(input())
n=len(s)
a=[0]*(n+1)
for i in range(n):
if s[i]=="<":
a[i+1]=a[i]+1
for i in range(n)[::-1]:
if s[i]==">":
a[i]=max(a[i+1]+1,a[i])
print((sum(a))) | 10 | 10 | 192 | 187 | s = eval(input())
n = len(s)
a = [0] * (n + 1)
for i in range(n):
if s[i] == "<":
a[i + 1] = a[i] + 1
for i in reversed(list(range(n))):
if s[i] == ">":
a[i] = max(a[i + 1] + 1, a[i])
print((sum(a)))
| s = eval(input())
n = len(s)
a = [0] * (n + 1)
for i in range(n):
if s[i] == "<":
a[i + 1] = a[i] + 1
for i in range(n)[::-1]:
if s[i] == ">":
a[i] = max(a[i + 1] + 1, a[i])
print((sum(a)))
| false | 0 | [
"-for i in reversed(list(range(n))):",
"+for i in range(n)[::-1]:"
] | false | 0.035198 | 0.039202 | 0.897855 | [
"s287693768",
"s927299254"
] |
u970197315 | p02972 | python | s732695327 | s915325390 | 737 | 556 | 14,032 | 17,628 | Accepted | Accepted | 24.56 | n=int(eval(input()))
a=[0]+list(map(int,input().split()))
b=[]
c=[0]*(n+1)
for i in range(n,0,-1):
cnt=0
t=i
while t<=n:
cnt+=c[t]
t+=i
if cnt%2!=a[i]:
c[i]=1
b.append(i)
b.sort()
if len(b)>0:
print((len(b)))
print((*b))
else:
print((0))
| n=int(eval(input()))
a=[0]+list(map(int,input().split()))
b=[0]*(n+1)
for i in range(n,0,-1):
s=0
t=i
while t<=n:
s+=b[t]
t+=i
if s%2==a[i]:
pass
else:
b[i]=1
ans=0
c=[]
for i,bb in enumerate(b):
if bb>0:
ans+=bb
c.append(i)
if ans>0:
print(ans)
print((*c))
else:
print((0)) | 20 | 24 | 278 | 329 | n = int(eval(input()))
a = [0] + list(map(int, input().split()))
b = []
c = [0] * (n + 1)
for i in range(n, 0, -1):
cnt = 0
t = i
while t <= n:
cnt += c[t]
t += i
if cnt % 2 != a[i]:
c[i] = 1
b.append(i)
b.sort()
if len(b) > 0:
print((len(b)))
print((*b))
else:
print((0))
| n = int(eval(input()))
a = [0] + list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(n, 0, -1):
s = 0
t = i
while t <= n:
s += b[t]
t += i
if s % 2 == a[i]:
pass
else:
b[i] = 1
ans = 0
c = []
for i, bb in enumerate(b):
if bb > 0:
ans += bb
c.append(i)
if ans > 0:
print(ans)
print((*c))
else:
print((0))
| false | 16.666667 | [
"-b = []",
"-c = [0] * (n + 1)",
"+b = [0] * (n + 1)",
"- cnt = 0",
"+ s = 0",
"- cnt += c[t]",
"+ s += b[t]",
"- if cnt % 2 != a[i]:",
"- c[i] = 1",
"- b.append(i)",
"-b.sort()",
"-if len(b) > 0:",
"- print((len(b)))",
"- print((*b))",
"+ if s % 2 == a[i]:",
"+ pass",
"+ else:",
"+ b[i] = 1",
"+ans = 0",
"+c = []",
"+for i, bb in enumerate(b):",
"+ if bb > 0:",
"+ ans += bb",
"+ c.append(i)",
"+if ans > 0:",
"+ print(ans)",
"+ print((*c))"
] | false | 0.046157 | 0.04632 | 0.996469 | [
"s732695327",
"s915325390"
] |
u254871849 | p03078 | python | s518440189 | s785699428 | 1,496 | 419 | 162,524 | 67,256 | Accepted | Accepted | 71.99 | import sys
from heapq import heappush, heappop
x, y, z, k = map(int ,sys.stdin.readline().split())
a, b, c = (sorted(map(int, sys.stdin.readline().split())) for _ in range(3))
def main():
res = []
for i in range(x):
for j in range(y):
heappush(res, -(a[i] + b[j]))
res2 = []
for i in range(min(k, x * y)):
ab = -heappop(res)
for j in range(z):
heappush(res2, -(ab + c[j]))
for i in range(k):
yield -heappop(res2)
if __name__ == '__main__':
ans = main()
print(*ans, sep='\n')
| import sys
import numpy as np
x, y, z, k = map(int, sys.stdin.readline().split())
a, b, c = (np.array(sys.stdin.readline().split(), dtype=np.int64) for _ in range(3))
def main():
res = np.sort(np.ravel(a[:, None] + b))[::-1]
res = np.sort(np.ravel(c[:, None] + res[:min(k, x*y)]))[::-1]
return res[:k]
if __name__ == '__main__':
ans = main()
print(*ans, sep='\n')
| 24 | 14 | 594 | 399 | import sys
from heapq import heappush, heappop
x, y, z, k = map(int, sys.stdin.readline().split())
a, b, c = (sorted(map(int, sys.stdin.readline().split())) for _ in range(3))
def main():
res = []
for i in range(x):
for j in range(y):
heappush(res, -(a[i] + b[j]))
res2 = []
for i in range(min(k, x * y)):
ab = -heappop(res)
for j in range(z):
heappush(res2, -(ab + c[j]))
for i in range(k):
yield -heappop(res2)
if __name__ == "__main__":
ans = main()
print(*ans, sep="\n")
| import sys
import numpy as np
x, y, z, k = map(int, sys.stdin.readline().split())
a, b, c = (np.array(sys.stdin.readline().split(), dtype=np.int64) for _ in range(3))
def main():
res = np.sort(np.ravel(a[:, None] + b))[::-1]
res = np.sort(np.ravel(c[:, None] + res[: min(k, x * y)]))[::-1]
return res[:k]
if __name__ == "__main__":
ans = main()
print(*ans, sep="\n")
| false | 41.666667 | [
"-from heapq import heappush, heappop",
"+import numpy as np",
"-a, b, c = (sorted(map(int, sys.stdin.readline().split())) for _ in range(3))",
"+a, b, c = (np.array(sys.stdin.readline().split(), dtype=np.int64) for _ in range(3))",
"- res = []",
"- for i in range(x):",
"- for j in range(y):",
"- heappush(res, -(a[i] + b[j]))",
"- res2 = []",
"- for i in range(min(k, x * y)):",
"- ab = -heappop(res)",
"- for j in range(z):",
"- heappush(res2, -(ab + c[j]))",
"- for i in range(k):",
"- yield -heappop(res2)",
"+ res = np.sort(np.ravel(a[:, None] + b))[::-1]",
"+ res = np.sort(np.ravel(c[:, None] + res[: min(k, x * y)]))[::-1]",
"+ return res[:k]"
] | false | 0.00709 | 0.221974 | 0.031941 | [
"s518440189",
"s785699428"
] |
u363610900 | p04029 | python | s302042253 | s887916909 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | N = int(eval(input()))
result = N * (1 + N) // 2
print(result) | N = int(eval(input()))
print((N*(1+N)//2)) | 3 | 2 | 58 | 35 | N = int(eval(input()))
result = N * (1 + N) // 2
print(result)
| N = int(eval(input()))
print((N * (1 + N) // 2))
| false | 33.333333 | [
"-result = N * (1 + N) // 2",
"-print(result)",
"+print((N * (1 + N) // 2))"
] | false | 0.038521 | 0.041094 | 0.937384 | [
"s302042253",
"s887916909"
] |
u644972721 | p02572 | python | s712469104 | s106137971 | 127 | 116 | 104,236 | 94,276 | Accepted | Accepted | 8.66 | n = int(eval(input()))
a = list(map(int, input().split()))
s = sum(a)
ans = 0
mod = pow(10, 9) + 7
for i in a:
s -= i
ans = (ans + s * i) % mod
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
mod = pow(10, 9) + 7
s = sum(a) % mod
ans = s * s % mod
for i in a:
ans -= i * i
ans %= mod
ans = ans * pow(2, mod - 2, mod) % mod
print(ans) | 9 | 10 | 164 | 211 | n = int(eval(input()))
a = list(map(int, input().split()))
s = sum(a)
ans = 0
mod = pow(10, 9) + 7
for i in a:
s -= i
ans = (ans + s * i) % mod
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
mod = pow(10, 9) + 7
s = sum(a) % mod
ans = s * s % mod
for i in a:
ans -= i * i
ans %= mod
ans = ans * pow(2, mod - 2, mod) % mod
print(ans)
| false | 10 | [
"-s = sum(a)",
"-ans = 0",
"+s = sum(a) % mod",
"+ans = s * s % mod",
"- s -= i",
"- ans = (ans + s * i) % mod",
"+ ans -= i * i",
"+ ans %= mod",
"+ans = ans * pow(2, mod - 2, mod) % mod"
] | false | 0.074096 | 0.036935 | 2.006135 | [
"s712469104",
"s106137971"
] |
u358254559 | p02727 | python | s767133961 | s025734884 | 1,448 | 355 | 128,100 | 110,444 | Accepted | Accepted | 75.48 | x,y,a,b,c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
apples=[]
for i in range(a):
apples.append([p[i],0])
for i in range(b):
apples.append([q[i],1])
for i in range(c):
apples.append([r[i],2])
apples.sort(reverse=True)
mx_cnt=[x,y,float('inf')]
cnt=[0,0,0]
ans=0
for app in apples:
deli=app[0]
clr = app[1]
if cnt[clr] < mx_cnt[clr]:
ans+=deli
cnt[clr]+=1
if sum(cnt)>=x+y:
break
print(ans) | x,y,a,b,c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
apples=[]
apples.extend(p[:x])
apples.extend(q[:y])
apples.extend(r)
apples.sort(reverse=True)
print((sum(apples[:x+y]))) | 29 | 16 | 567 | 326 | x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
apples = []
for i in range(a):
apples.append([p[i], 0])
for i in range(b):
apples.append([q[i], 1])
for i in range(c):
apples.append([r[i], 2])
apples.sort(reverse=True)
mx_cnt = [x, y, float("inf")]
cnt = [0, 0, 0]
ans = 0
for app in apples:
deli = app[0]
clr = app[1]
if cnt[clr] < mx_cnt[clr]:
ans += deli
cnt[clr] += 1
if sum(cnt) >= x + y:
break
print(ans)
| x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
apples = []
apples.extend(p[:x])
apples.extend(q[:y])
apples.extend(r)
apples.sort(reverse=True)
print((sum(apples[: x + y])))
| false | 44.827586 | [
"+p.sort(reverse=True)",
"+q.sort(reverse=True)",
"-for i in range(a):",
"- apples.append([p[i], 0])",
"-for i in range(b):",
"- apples.append([q[i], 1])",
"-for i in range(c):",
"- apples.append([r[i], 2])",
"+apples.extend(p[:x])",
"+apples.extend(q[:y])",
"+apples.extend(r)",
"-mx_cnt = [x, y, float(\"inf\")]",
"-cnt = [0, 0, 0]",
"-ans = 0",
"-for app in apples:",
"- deli = app[0]",
"- clr = app[1]",
"- if cnt[clr] < mx_cnt[clr]:",
"- ans += deli",
"- cnt[clr] += 1",
"- if sum(cnt) >= x + y:",
"- break",
"-print(ans)",
"+print((sum(apples[: x + y])))"
] | false | 0.041015 | 0.04014 | 1.021808 | [
"s767133961",
"s025734884"
] |
u156896646 | p03478 | python | s444523839 | s511552364 | 37 | 32 | 3,060 | 3,060 | Accepted | Accepted | 13.51 | N, A, B = list(map(int, input().split()))
tot = 0
for i in range(1, N+1):
s = 0
for c in list(str(i)):
s += int(c)
if A<= s <=B:
tot += i
print(tot) | N, A, B = list(map(int, input().split()))
tot = 0
for i in range(1, N+1):
q = i
s = 0
while q > 0:
q, r = divmod(q, 10) #;print(i, q, r, s)
s += r
if A<= s <=B:
tot += i #;print(i)
print(tot) | 10 | 13 | 180 | 262 | N, A, B = list(map(int, input().split()))
tot = 0
for i in range(1, N + 1):
s = 0
for c in list(str(i)):
s += int(c)
if A <= s <= B:
tot += i
print(tot)
| N, A, B = list(map(int, input().split()))
tot = 0
for i in range(1, N + 1):
q = i
s = 0
while q > 0:
q, r = divmod(q, 10) # ;print(i, q, r, s)
s += r
if A <= s <= B:
tot += i # ;print(i)
print(tot)
| false | 23.076923 | [
"+ q = i",
"- for c in list(str(i)):",
"- s += int(c)",
"+ while q > 0:",
"+ q, r = divmod(q, 10) # ;print(i, q, r, s)",
"+ s += r",
"- tot += i",
"+ tot += i # ;print(i)"
] | false | 0.080701 | 0.108504 | 0.743759 | [
"s444523839",
"s511552364"
] |
u271934630 | p03805 | python | s614563316 | s205951903 | 180 | 27 | 39,920 | 3,064 | Accepted | Accepted | 85 | import itertools
n, m = list(map(int, input().split()))
path = [[False] * n for i in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
path[a][b] = True
path[b][a] = True
ans = 0
for i in itertools.permutations(list(range(n)), n):
# ้ ็น1ใๅง็น
if i[0] == 0:
for j in range(n):
if j == n - 1:
ans += 1
break
if not path[i[j]][i[j + 1]]:
break
print(ans)
| def main():
N, M = list(map(int, input().split()))
matrix = [[0] * N for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
matrix[a-1][b-1] = 1
matrix[b-1][a-1] = 1
def dfs(v, used):
if False not in used:
return 1
ans = 0
for i in range(N):
if not matrix[v][i]:
continue
if used[i]:
continue
used[i] = True
ans += dfs(i, used)
used[i] = False
return ans
used = [False] * N
used[0] = True
print((dfs(0, used)))
if __name__ == '__main__':
main()
| 25 | 34 | 504 | 687 | import itertools
n, m = list(map(int, input().split()))
path = [[False] * n for i in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
path[a][b] = True
path[b][a] = True
ans = 0
for i in itertools.permutations(list(range(n)), n):
# ้ ็น1ใๅง็น
if i[0] == 0:
for j in range(n):
if j == n - 1:
ans += 1
break
if not path[i[j]][i[j + 1]]:
break
print(ans)
| def main():
N, M = list(map(int, input().split()))
matrix = [[0] * N for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
matrix[a - 1][b - 1] = 1
matrix[b - 1][a - 1] = 1
def dfs(v, used):
if False not in used:
return 1
ans = 0
for i in range(N):
if not matrix[v][i]:
continue
if used[i]:
continue
used[i] = True
ans += dfs(i, used)
used[i] = False
return ans
used = [False] * N
used[0] = True
print((dfs(0, used)))
if __name__ == "__main__":
main()
| false | 26.470588 | [
"-import itertools",
"+def main():",
"+ N, M = list(map(int, input().split()))",
"+ matrix = [[0] * N for _ in range(N)]",
"+ for _ in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ matrix[a - 1][b - 1] = 1",
"+ matrix[b - 1][a - 1] = 1",
"-n, m = list(map(int, input().split()))",
"-path = [[False] * n for i in range(n)]",
"-for i in range(m):",
"- a, b = list(map(int, input().split()))",
"- a -= 1",
"- b -= 1",
"- path[a][b] = True",
"- path[b][a] = True",
"- ans = 0",
"-for i in itertools.permutations(list(range(n)), n):",
"- # ้ ็น1ใๅง็น",
"- if i[0] == 0:",
"- for j in range(n):",
"- if j == n - 1:",
"- ans += 1",
"- break",
"- if not path[i[j]][i[j + 1]]:",
"- break",
"-print(ans)",
"+ def dfs(v, used):",
"+ if False not in used:",
"+ return 1",
"+ ans = 0",
"+ for i in range(N):",
"+ if not matrix[v][i]:",
"+ continue",
"+ if used[i]:",
"+ continue",
"+ used[i] = True",
"+ ans += dfs(i, used)",
"+ used[i] = False",
"+ return ans",
"+",
"+ used = [False] * N",
"+ used[0] = True",
"+ print((dfs(0, used)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.068618 | 0.036579 | 1.875902 | [
"s614563316",
"s205951903"
] |
u171065106 | p03612 | python | s373697115 | s688807068 | 66 | 61 | 20,536 | 20,584 | Accepted | Accepted | 7.58 | n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
increased = False
for i in range(n):
if increased:
increased = False
continue
if p[i] == i+1:
cnt += 1
i += 1
increased = True
print(cnt) | n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
increased = False
for i in range(n):
if increased:
increased = False
elif p[i] == i+1:
cnt += 1
increased = True
print(cnt)
| 16 | 15 | 264 | 235 | n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
increased = False
for i in range(n):
if increased:
increased = False
continue
if p[i] == i + 1:
cnt += 1
i += 1
increased = True
print(cnt)
| n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
increased = False
for i in range(n):
if increased:
increased = False
elif p[i] == i + 1:
cnt += 1
increased = True
print(cnt)
| false | 6.25 | [
"- continue",
"- if p[i] == i + 1:",
"+ elif p[i] == i + 1:",
"- i += 1"
] | false | 0.068979 | 0.091103 | 0.757149 | [
"s373697115",
"s688807068"
] |
u698868214 | p03031 | python | s695081449 | s292153437 | 143 | 49 | 73,072 | 9,056 | Accepted | Accepted | 65.73 | N,M = list(map(int,input().split()))
S = [list(map(int,input().split())) for _ in range(M)]
P = list(map(int,input().split()))
ans = 0
for i in range(2**N):
count = 0
on_or_off = [0]*M
for j in range(N):
if (i>>j)&1:
for k in range(M):
if j+1 in S[k][1:]:
on_or_off[k] += 1
for l in range(M):
if on_or_off[l]%2 == P[l]:
count += 1
if count == M:
ans += 1
print(ans) | N,M = list(map(int,input().split()))
ks = [list(map(int,input().split())) for _ in range(M)]
P = list(map(int,input().split()))
ans = 0
for i in range(2**N):
on_or_off = [0]*M
for j in range(N):
if (i>>j)&1:
for k in range(M):
if j+1 in ks[k][1:]:
on_or_off[k] += 1
cnt = 0
for l in range(M):
if on_or_off[l]%2 == P[l]:
cnt += 1
if cnt == M:
ans += 1
print(ans) | 18 | 19 | 428 | 426 | N, M = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
count = 0
on_or_off = [0] * M
for j in range(N):
if (i >> j) & 1:
for k in range(M):
if j + 1 in S[k][1:]:
on_or_off[k] += 1
for l in range(M):
if on_or_off[l] % 2 == P[l]:
count += 1
if count == M:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
on_or_off = [0] * M
for j in range(N):
if (i >> j) & 1:
for k in range(M):
if j + 1 in ks[k][1:]:
on_or_off[k] += 1
cnt = 0
for l in range(M):
if on_or_off[l] % 2 == P[l]:
cnt += 1
if cnt == M:
ans += 1
print(ans)
| false | 5.263158 | [
"-S = [list(map(int, input().split())) for _ in range(M)]",
"+ks = [list(map(int, input().split())) for _ in range(M)]",
"- count = 0",
"- if j + 1 in S[k][1:]:",
"+ if j + 1 in ks[k][1:]:",
"+ cnt = 0",
"- count += 1",
"- if count == M:",
"+ cnt += 1",
"+ if cnt == M:"
] | false | 0.041231 | 0.039992 | 1.030985 | [
"s695081449",
"s292153437"
] |
u077291787 | p03162 | python | s313934139 | s813752799 | 380 | 211 | 71,516 | 35,636 | Accepted | Accepted | 44.47 | # dpC
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
dp = [[0] * 3 for _ in range(n)]
dp[0] = A[0]
for i in range(1, n): # i-th day
for j in range(3): # today
for k in range(3): # yesterday
if j != k:
dp[i][j] = max(dp[i][j], dp[i - 1][k] + A[i][j])
print((max(dp[-1])))
if __name__ == "__main__":
main() | # C - Vacation
def main():
N, *ABC = list(map(int, open(0).read().split()))
prev = ABC[:3]
for a, b, c in zip(*[iter(ABC[3:])] * 3):
cur = [0] * 3
cur[0] = max(prev[1:]) + a
cur[1] = max(prev[0], prev[2]) + b
cur[2] = max(prev[:2]) + c
prev = cur
print((max(prev)))
if __name__ == "__main__":
main()
| 19 | 15 | 501 | 368 | # dpC
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
dp = [[0] * 3 for _ in range(n)]
dp[0] = A[0]
for i in range(1, n): # i-th day
for j in range(3): # today
for k in range(3): # yesterday
if j != k:
dp[i][j] = max(dp[i][j], dp[i - 1][k] + A[i][j])
print((max(dp[-1])))
if __name__ == "__main__":
main()
| # C - Vacation
def main():
N, *ABC = list(map(int, open(0).read().split()))
prev = ABC[:3]
for a, b, c in zip(*[iter(ABC[3:])] * 3):
cur = [0] * 3
cur[0] = max(prev[1:]) + a
cur[1] = max(prev[0], prev[2]) + b
cur[2] = max(prev[:2]) + c
prev = cur
print((max(prev)))
if __name__ == "__main__":
main()
| false | 21.052632 | [
"-# dpC",
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"+# C - Vacation",
"- n = int(eval(input()))",
"- A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))",
"- dp = [[0] * 3 for _ in range(n)]",
"- dp[0] = A[0]",
"- for i in range(1, n): # i-th day",
"- for j in range(3): # today",
"- for k in range(3): # yesterday",
"- if j != k:",
"- dp[i][j] = max(dp[i][j], dp[i - 1][k] + A[i][j])",
"- print((max(dp[-1])))",
"+ N, *ABC = list(map(int, open(0).read().split()))",
"+ prev = ABC[:3]",
"+ for a, b, c in zip(*[iter(ABC[3:])] * 3):",
"+ cur = [0] * 3",
"+ cur[0] = max(prev[1:]) + a",
"+ cur[1] = max(prev[0], prev[2]) + b",
"+ cur[2] = max(prev[:2]) + c",
"+ prev = cur",
"+ print((max(prev)))"
] | false | 0.040925 | 0.046315 | 0.883634 | [
"s313934139",
"s813752799"
] |
u227082700 | p03618 | python | s468329123 | s601707906 | 41 | 32 | 3,500 | 5,096 | Accepted | Accepted | 21.95 | s=eval(input())
l=len(s)
t="abcdefghijklmnopqrstuvwxyz"
d={}
for i in t:d[i]=0
for i in s:d[i]+=1
a=l*(l-1)//2
for i in t:a-=d[i]*(d[i]-1)//2
print((a+1)) | a=eval(input())
n=len(a)
ans=n*(n-1)//2
from collections import Counter
d=Counter(list(a))
for i in d:ans-=d[i]*(d[i]-1)//2
print((ans+1)) | 9 | 7 | 154 | 136 | s = eval(input())
l = len(s)
t = "abcdefghijklmnopqrstuvwxyz"
d = {}
for i in t:
d[i] = 0
for i in s:
d[i] += 1
a = l * (l - 1) // 2
for i in t:
a -= d[i] * (d[i] - 1) // 2
print((a + 1))
| a = eval(input())
n = len(a)
ans = n * (n - 1) // 2
from collections import Counter
d = Counter(list(a))
for i in d:
ans -= d[i] * (d[i] - 1) // 2
print((ans + 1))
| false | 22.222222 | [
"-s = eval(input())",
"-l = len(s)",
"-t = \"abcdefghijklmnopqrstuvwxyz\"",
"-d = {}",
"-for i in t:",
"- d[i] = 0",
"-for i in s:",
"- d[i] += 1",
"-a = l * (l - 1) // 2",
"-for i in t:",
"- a -= d[i] * (d[i] - 1) // 2",
"-print((a + 1))",
"+a = eval(input())",
"+n = len(a)",
"+ans = n * (n - 1) // 2",
"+from collections import Counter",
"+",
"+d = Counter(list(a))",
"+for i in d:",
"+ ans -= d[i] * (d[i] - 1) // 2",
"+print((ans + 1))"
] | false | 0.041294 | 0.099447 | 0.415233 | [
"s468329123",
"s601707906"
] |
u677121387 | p02695 | python | s172926483 | s018849507 | 1,195 | 604 | 9,200 | 9,220 | Accepted | Accepted | 49.46 | from itertools import combinations_with_replacement as comb
n,m,q = list(map(int,input().split()))
ans = 0
query = [[int(i) for i in input().split()] for _ in range(q)]
for A in comb(list(range(1,m+1)),n):
cnt = 0
for i in range(q):
a,b,c,d = query[i]
if A[b-1]-A[a-1] == c: cnt += d
ans = max(cnt,ans)
print(ans)
| import sys
sys.setrecursionlimit(10**9)
n,m,q = list(map(int,input().split()))
query = [[int(i) for i in input().split()] for _ in range(q)]
def f(A):
if len(A) == n+1:
# print(A)
cnt = 0
for i in range(q):
a,b,c,d = query[i]
if A[b]-A[a] == c: cnt += d
return cnt
res = 0
for i in range(A[-1],m+1):
res = max(res,f(A+[i]))
return res
print((f([1]))) | 11 | 19 | 340 | 442 | from itertools import combinations_with_replacement as comb
n, m, q = list(map(int, input().split()))
ans = 0
query = [[int(i) for i in input().split()] for _ in range(q)]
for A in comb(list(range(1, m + 1)), n):
cnt = 0
for i in range(q):
a, b, c, d = query[i]
if A[b - 1] - A[a - 1] == c:
cnt += d
ans = max(cnt, ans)
print(ans)
| import sys
sys.setrecursionlimit(10**9)
n, m, q = list(map(int, input().split()))
query = [[int(i) for i in input().split()] for _ in range(q)]
def f(A):
if len(A) == n + 1:
# print(A)
cnt = 0
for i in range(q):
a, b, c, d = query[i]
if A[b] - A[a] == c:
cnt += d
return cnt
res = 0
for i in range(A[-1], m + 1):
res = max(res, f(A + [i]))
return res
print((f([1])))
| false | 42.105263 | [
"-from itertools import combinations_with_replacement as comb",
"+import sys",
"+sys.setrecursionlimit(10**9)",
"-ans = 0",
"-for A in comb(list(range(1, m + 1)), n):",
"- cnt = 0",
"- for i in range(q):",
"- a, b, c, d = query[i]",
"- if A[b - 1] - A[a - 1] == c:",
"- cnt += d",
"- ans = max(cnt, ans)",
"-print(ans)",
"+",
"+",
"+def f(A):",
"+ if len(A) == n + 1:",
"+ # print(A)",
"+ cnt = 0",
"+ for i in range(q):",
"+ a, b, c, d = query[i]",
"+ if A[b] - A[a] == c:",
"+ cnt += d",
"+ return cnt",
"+ res = 0",
"+ for i in range(A[-1], m + 1):",
"+ res = max(res, f(A + [i]))",
"+ return res",
"+",
"+",
"+print((f([1])))"
] | false | 0.04753 | 0.053214 | 0.893179 | [
"s172926483",
"s018849507"
] |
u836737505 | p03457 | python | s348024658 | s892950450 | 605 | 393 | 46,228 | 3,064 | Accepted | Accepted | 35.04 | n = int(eval(input()))
a0 = [0,0,0]
ans = "Yes"
for i in range(n):
ai = list(map(int,input().split()))
t = ai[0] - a0[0]
d = abs(ai[1] - a0[1])+ abs(ai[2] - a0[2])
if t < d or t%2 != d%2:
ans = "No"
a0 = ai
print(ans) | n = int(eval(input()))
t0,x0,y0 = 0,0,0
for i in range(n):
t,x,y = list(map(int, input().split()))
if abs(t0-t)%2 != (abs(x0-x)+abs(y0-y))%2 or (abs(x0-x)+abs(y0-y)) > abs(t0-t):
print("No")
exit()
t0,x0,y0, = t,x,y
else:
print("Yes") | 11 | 10 | 249 | 263 | n = int(eval(input()))
a0 = [0, 0, 0]
ans = "Yes"
for i in range(n):
ai = list(map(int, input().split()))
t = ai[0] - a0[0]
d = abs(ai[1] - a0[1]) + abs(ai[2] - a0[2])
if t < d or t % 2 != d % 2:
ans = "No"
a0 = ai
print(ans)
| n = int(eval(input()))
t0, x0, y0 = 0, 0, 0
for i in range(n):
t, x, y = list(map(int, input().split()))
if abs(t0 - t) % 2 != (abs(x0 - x) + abs(y0 - y)) % 2 or (
abs(x0 - x) + abs(y0 - y)
) > abs(t0 - t):
print("No")
exit()
t0, x0, y0, = (
t,
x,
y,
)
else:
print("Yes")
| false | 9.090909 | [
"-a0 = [0, 0, 0]",
"-ans = \"Yes\"",
"+t0, x0, y0 = 0, 0, 0",
"- ai = list(map(int, input().split()))",
"- t = ai[0] - a0[0]",
"- d = abs(ai[1] - a0[1]) + abs(ai[2] - a0[2])",
"- if t < d or t % 2 != d % 2:",
"- ans = \"No\"",
"- a0 = ai",
"-print(ans)",
"+ t, x, y = list(map(int, input().split()))",
"+ if abs(t0 - t) % 2 != (abs(x0 - x) + abs(y0 - y)) % 2 or (",
"+ abs(x0 - x) + abs(y0 - y)",
"+ ) > abs(t0 - t):",
"+ print(\"No\")",
"+ exit()",
"+ t0, x0, y0, = (",
"+ t,",
"+ x,",
"+ y,",
"+ )",
"+else:",
"+ print(\"Yes\")"
] | false | 0.036392 | 0.038714 | 0.940038 | [
"s348024658",
"s892950450"
] |
u600402037 | p02835 | python | s181380279 | s360675930 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | import sys
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
a, b, c = rl()
answer = a + b + c
print(('bust' if answer >= 22 else 'win'))
| import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
total = sum(lr())
print(('bust' if total >= 22 else 'win'))
# 44 | 13 | 9 | 264 | 191 | import sys
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
a, b, c = rl()
answer = a + b + c
print(("bust" if answer >= 22 else "win"))
| import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
total = sum(lr())
print(("bust" if total >= 22 else "win"))
# 44
| false | 30.769231 | [
"-stdin = sys.stdin",
"-ri = lambda: int(rs())",
"-rl = lambda: list(map(int, stdin.readline().split()))",
"-rs = lambda: stdin.readline().rstrip() # ignore trailing spaces",
"-a, b, c = rl()",
"-answer = a + b + c",
"-print((\"bust\" if answer >= 22 else \"win\"))",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lambda: int(sr())",
"+lr = lambda: list(map(int, sr().split()))",
"+total = sum(lr())",
"+print((\"bust\" if total >= 22 else \"win\"))",
"+# 44"
] | false | 0.038574 | 0.037723 | 1.022556 | [
"s181380279",
"s360675930"
] |
u225388820 | p02629 | python | s452923978 | s230142246 | 77 | 31 | 61,872 | 9,172 | Accepted | Accepted | 59.74 | al = ["Q"] + [chr(ord('a') + i) for i in range(26)]
n = int(eval(input()))
s = ""
while n:
if n % 26:
a = n % 26
n //= 26
else:
a = 26
n //= 26
n -= 1
s += al[a]
print((s[::-1])) | al = [chr(ord('a') + i) for i in range(26)]
n = int(eval(input()))
s = ""
while n:
s += al[n % 26 - 1]
n = (n - 1) // 26
print((s[::-1])) | 13 | 7 | 234 | 143 | al = ["Q"] + [chr(ord("a") + i) for i in range(26)]
n = int(eval(input()))
s = ""
while n:
if n % 26:
a = n % 26
n //= 26
else:
a = 26
n //= 26
n -= 1
s += al[a]
print((s[::-1]))
| al = [chr(ord("a") + i) for i in range(26)]
n = int(eval(input()))
s = ""
while n:
s += al[n % 26 - 1]
n = (n - 1) // 26
print((s[::-1]))
| false | 46.153846 | [
"-al = [\"Q\"] + [chr(ord(\"a\") + i) for i in range(26)]",
"+al = [chr(ord(\"a\") + i) for i in range(26)]",
"- if n % 26:",
"- a = n % 26",
"- n //= 26",
"- else:",
"- a = 26",
"- n //= 26",
"- n -= 1",
"- s += al[a]",
"+ s += al[n % 26 - 1]",
"+ n = (n - 1) // 26"
] | false | 0.058321 | 0.058385 | 0.998906 | [
"s452923978",
"s230142246"
] |
u625046108 | p03575 | python | s897169111 | s245929470 | 269 | 92 | 73,824 | 67,108 | Accepted | Accepted | 65.8 | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
rlt = 0
for i in range(M):
uf = UnionFind(N+1)
for j in range(M):
if i == j:
continue
e = edges[j]
uf.union(e[0],e[1])
if min(uf.parents) > -N:
rlt += 1
print(rlt) | from collections import deque
N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
od = [-1]*(N+1)
low = [-1]*(N+1)
pa = [0]*(N+1)
od[1] = 0
low[1] = 0
pa[1] = 1
ni = {i:[] for i in range(1,N+1)}
for i in range(M):
ni[edges[i][0]].append(edges[i][1])
ni[edges[i][1]].append(edges[i][0])
rlt = 0
h = deque([])
for i in ni[1]:
h.append([1,i])
i = 0
while h:
a = h.pop()
if od[a[1]] > -1:
if od[a[1]] < od[a[0]]:
low[a[0]] = od[a[1]]
c = a[0]
while low[pa[c]] > od[a[1]]:
low[pa[c]] = od[a[1]]
c = pa[c]
else:
i += 1
od[a[1]] = i
low[a[1]] = i
pa[a[1]] = a[0]
for b in ni[a[1]]:
if b == a[0]:
continue
h.append([a[1],b])
for i in range(2,N+1):
if od[pa[i]] < low[i]:
rlt += 1
print(rlt)
| 64 | 47 | 1,380 | 883 | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
rlt = 0
for i in range(M):
uf = UnionFind(N + 1)
for j in range(M):
if i == j:
continue
e = edges[j]
uf.union(e[0], e[1])
if min(uf.parents) > -N:
rlt += 1
print(rlt)
| from collections import deque
N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
od = [-1] * (N + 1)
low = [-1] * (N + 1)
pa = [0] * (N + 1)
od[1] = 0
low[1] = 0
pa[1] = 1
ni = {i: [] for i in range(1, N + 1)}
for i in range(M):
ni[edges[i][0]].append(edges[i][1])
ni[edges[i][1]].append(edges[i][0])
rlt = 0
h = deque([])
for i in ni[1]:
h.append([1, i])
i = 0
while h:
a = h.pop()
if od[a[1]] > -1:
if od[a[1]] < od[a[0]]:
low[a[0]] = od[a[1]]
c = a[0]
while low[pa[c]] > od[a[1]]:
low[pa[c]] = od[a[1]]
c = pa[c]
else:
i += 1
od[a[1]] = i
low[a[1]] = i
pa[a[1]] = a[0]
for b in ni[a[1]]:
if b == a[0]:
continue
h.append([a[1], b])
for i in range(2, N + 1):
if od[pa[i]] < low[i]:
rlt += 1
print(rlt)
| false | 26.5625 | [
"-class UnionFind:",
"- def __init__(self, n):",
"- self.n = n",
"- self.parents = [-1] * n",
"-",
"- def find(self, x):",
"- if self.parents[x] < 0:",
"- return x",
"- else:",
"- self.parents[x] = self.find(self.parents[x])",
"- return self.parents[x]",
"-",
"- def union(self, x, y):",
"- x = self.find(x)",
"- y = self.find(y)",
"- if x == y:",
"- return",
"- if self.parents[x] > self.parents[y]:",
"- x, y = y, x",
"- self.parents[x] += self.parents[y]",
"- self.parents[y] = x",
"-",
"- def size(self, x):",
"- return -self.parents[self.find(x)]",
"-",
"- def same(self, x, y):",
"- return self.find(x) == self.find(y)",
"-",
"- def members(self, x):",
"- root = self.find(x)",
"- return [i for i in range(self.n) if self.find(i) == root]",
"-",
"- def roots(self):",
"- return [i for i, x in enumerate(self.parents) if x < 0]",
"-",
"- def group_count(self):",
"- return len(self.roots())",
"-",
"- def all_group_members(self):",
"- return {r: self.members(r) for r in self.roots()}",
"-",
"- def __str__(self):",
"- return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())",
"-",
"+from collections import deque",
"+od = [-1] * (N + 1)",
"+low = [-1] * (N + 1)",
"+pa = [0] * (N + 1)",
"+od[1] = 0",
"+low[1] = 0",
"+pa[1] = 1",
"+ni = {i: [] for i in range(1, N + 1)}",
"+for i in range(M):",
"+ ni[edges[i][0]].append(edges[i][1])",
"+ ni[edges[i][1]].append(edges[i][0])",
"-for i in range(M):",
"- uf = UnionFind(N + 1)",
"- for j in range(M):",
"- if i == j:",
"- continue",
"- e = edges[j]",
"- uf.union(e[0], e[1])",
"- if min(uf.parents) > -N:",
"+h = deque([])",
"+for i in ni[1]:",
"+ h.append([1, i])",
"+i = 0",
"+while h:",
"+ a = h.pop()",
"+ if od[a[1]] > -1:",
"+ if od[a[1]] < od[a[0]]:",
"+ low[a[0]] = od[a[1]]",
"+ c = a[0]",
"+ while low[pa[c]] > od[a[1]]:",
"+ low[pa[c]] = od[a[1]]",
"+ c = pa[c]",
"+ else:",
"+ i += 1",
"+ od[a[1]] = i",
"+ low[a[1]] = i",
"+ pa[a[1]] = a[0]",
"+ for b in ni[a[1]]:",
"+ if b == a[0]:",
"+ continue",
"+ h.append([a[1], b])",
"+for i in range(2, N + 1):",
"+ if od[pa[i]] < low[i]:"
] | false | 0.090962 | 0.113898 | 0.798621 | [
"s897169111",
"s245929470"
] |
u812576525 | p03243 | python | s665044018 | s232661114 | 21 | 17 | 2,940 | 2,940 | Accepted | Accepted | 19.05 | N= int(eval(input()))
A = [111, 222, 333, 444, 555, 666, 777, 888, 999]
for i in A:
if N==i:
print(i)
break
elif N > i:
continue
elif N <= i:
print(i)
break
| n=int(eval(input()))
for i in range(n,1000):
if str(i)[0] == str(i)[1] == str(i)[2]:
print(i)
exit() | 14 | 5 | 230 | 118 | N = int(eval(input()))
A = [111, 222, 333, 444, 555, 666, 777, 888, 999]
for i in A:
if N == i:
print(i)
break
elif N > i:
continue
elif N <= i:
print(i)
break
| n = int(eval(input()))
for i in range(n, 1000):
if str(i)[0] == str(i)[1] == str(i)[2]:
print(i)
exit()
| false | 64.285714 | [
"-N = int(eval(input()))",
"-A = [111, 222, 333, 444, 555, 666, 777, 888, 999]",
"-for i in A:",
"- if N == i:",
"+n = int(eval(input()))",
"+for i in range(n, 1000):",
"+ if str(i)[0] == str(i)[1] == str(i)[2]:",
"- break",
"- elif N > i:",
"- continue",
"- elif N <= i:",
"- print(i)",
"- break",
"+ exit()"
] | false | 0.042238 | 0.04147 | 1.018522 | [
"s665044018",
"s232661114"
] |
u624475441 | p03680 | python | s612449846 | s584922747 | 180 | 56 | 7,852 | 7,068 | Accepted | Accepted | 68.89 | N = int(eval(input()))
a = [int(eval(input())) - 1 for _ in [0]*N]
cur = 0
cnt = -1
for i in range(N):
cur = a[cur]
if cur == 1:
cnt = i + 1
break
print(cnt) | import sys
e = list(map(int,sys.stdin))
cur = e[1]
for i in range(e[0]):
if cur == 2:
print((i + 1))
break
cur = e[cur]
else:
print((-1)) | 10 | 10 | 178 | 170 | N = int(eval(input()))
a = [int(eval(input())) - 1 for _ in [0] * N]
cur = 0
cnt = -1
for i in range(N):
cur = a[cur]
if cur == 1:
cnt = i + 1
break
print(cnt)
| import sys
e = list(map(int, sys.stdin))
cur = e[1]
for i in range(e[0]):
if cur == 2:
print((i + 1))
break
cur = e[cur]
else:
print((-1))
| false | 0 | [
"-N = int(eval(input()))",
"-a = [int(eval(input())) - 1 for _ in [0] * N]",
"-cur = 0",
"-cnt = -1",
"-for i in range(N):",
"- cur = a[cur]",
"- if cur == 1:",
"- cnt = i + 1",
"+import sys",
"+",
"+e = list(map(int, sys.stdin))",
"+cur = e[1]",
"+for i in range(e[0]):",
"+ if cur == 2:",
"+ print((i + 1))",
"-print(cnt)",
"+ cur = e[cur]",
"+else:",
"+ print((-1))"
] | false | 0.052569 | 0.03439 | 1.528624 | [
"s612449846",
"s584922747"
] |
u285891772 | p03821 | python | s485302921 | s215119867 | 330 | 286 | 31,300 | 30,228 | Accepted | Accepted | 13.33 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
N = INT()
AB = [LIST() for _ in range(N)]
A, B = [], []
for a, b in AB:
A.append(a)
B.append(b)
cnt = 0
for i in range(N-1, -1, -1):
if (A[i]+cnt)%B[i] == 0:
continue
else:
cnt += B[i] - (A[i]+cnt)%B[i]
print(cnt)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
N = INT()
AB = [LIST() for _ in range(N)]
cnt = 0
for A, B in AB[::-1]:
if (A+cnt)%B != 0:
cnt += B - (A+cnt)%B
print(cnt)
| 38 | 32 | 1,169 | 1,067 | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
) # , log2, log
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *
N = INT()
AB = [LIST() for _ in range(N)]
A, B = [], []
for a, b in AB:
A.append(a)
B.append(b)
cnt = 0
for i in range(N - 1, -1, -1):
if (A[i] + cnt) % B[i] == 0:
continue
else:
cnt += B[i] - (A[i] + cnt) % B[i]
print(cnt)
| import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
) # , log2, log
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *
N = INT()
AB = [LIST() for _ in range(N)]
cnt = 0
for A, B in AB[::-1]:
if (A + cnt) % B != 0:
cnt += B - (A + cnt) % B
print(cnt)
| false | 15.789474 | [
"-A, B = [], []",
"-for a, b in AB:",
"- A.append(a)",
"- B.append(b)",
"-for i in range(N - 1, -1, -1):",
"- if (A[i] + cnt) % B[i] == 0:",
"- continue",
"- else:",
"- cnt += B[i] - (A[i] + cnt) % B[i]",
"+for A, B in AB[::-1]:",
"+ if (A + cnt) % B != 0:",
"+ cnt += B - (A + cnt) % B"
] | false | 0.04646 | 0.04723 | 0.983692 | [
"s485302921",
"s215119867"
] |
u002539468 | p03435 | python | s846848593 | s016882670 | 224 | 18 | 3,064 | 3,064 | Accepted | Accepted | 91.96 | c11, c12, c13 = list(map(int, input().split()))
c21, c22, c23 = list(map(int, input().split()))
c31, c32, c33 = list(map(int, input().split()))
def correct():
if a1 + b2 != c12:
return False
if a1 + b3 != c13:
return False
if a2 + b1 != c21:
return False
if a2 + b3 != c23:
return False
if a3 + b1 != c31:
return False
if a3 + b2 != c32:
return False
return True
for i in range(c11 + 1):
for j in range(c22 + 1):
for k in range(c33 + 1):
a1 = i
b1 = c11 - i
a2 = j
b2 = c22 - j
a3 = k
b3 = c33 - k
if correct():
print('Yes')
exit(0)
print('No')
| c11, c12, c13 = list(map(int, input().split()))
c21, c22, c23 = list(map(int, input().split()))
c31, c32, c33 = list(map(int, input().split()))
def correct(a1, a2, a3, b1, b2, b3):
if a1 + b1 != c11:
return False
if a2 + b2 != c22:
return False
if a3 + b3 != c33:
return False
if a1 + b2 != c12:
return False
if a1 + b3 != c13:
return False
if a2 + b1 != c21:
return False
if a2 + b3 != c23:
return False
if a3 + b1 != c31:
return False
if a3 + b2 != c32:
return False
return True
for i in range(c11 + 1):
a1 = i
b1 = c11 - i
a2 = a1 - c11 + c21
a3 = a1 - c11 + c31
b2 = b1 - c11 + c12
b3 = b1 - c11 + c13
# print(a1, a2, a3, b1, b2, b3)
if correct(a1, a2, a3, b1, b2, b3):
print('Yes')
exit(0)
# for i in range(c11 + 1):
# for j in range(c22 + 1):
# for k in range(c33 + 1):
# a1 = i
# b1 = c11 - i
# a2 = j
# b2 = c22 - j
# a3 = k
# b3 = c33 - k
# if correct(a1, a2, a3, b1, b2, b3):
# print('Yes')
# exit(0)
print('No')
| 33 | 51 | 664 | 1,103 | c11, c12, c13 = list(map(int, input().split()))
c21, c22, c23 = list(map(int, input().split()))
c31, c32, c33 = list(map(int, input().split()))
def correct():
if a1 + b2 != c12:
return False
if a1 + b3 != c13:
return False
if a2 + b1 != c21:
return False
if a2 + b3 != c23:
return False
if a3 + b1 != c31:
return False
if a3 + b2 != c32:
return False
return True
for i in range(c11 + 1):
for j in range(c22 + 1):
for k in range(c33 + 1):
a1 = i
b1 = c11 - i
a2 = j
b2 = c22 - j
a3 = k
b3 = c33 - k
if correct():
print("Yes")
exit(0)
print("No")
| c11, c12, c13 = list(map(int, input().split()))
c21, c22, c23 = list(map(int, input().split()))
c31, c32, c33 = list(map(int, input().split()))
def correct(a1, a2, a3, b1, b2, b3):
if a1 + b1 != c11:
return False
if a2 + b2 != c22:
return False
if a3 + b3 != c33:
return False
if a1 + b2 != c12:
return False
if a1 + b3 != c13:
return False
if a2 + b1 != c21:
return False
if a2 + b3 != c23:
return False
if a3 + b1 != c31:
return False
if a3 + b2 != c32:
return False
return True
for i in range(c11 + 1):
a1 = i
b1 = c11 - i
a2 = a1 - c11 + c21
a3 = a1 - c11 + c31
b2 = b1 - c11 + c12
b3 = b1 - c11 + c13
# print(a1, a2, a3, b1, b2, b3)
if correct(a1, a2, a3, b1, b2, b3):
print("Yes")
exit(0)
# for i in range(c11 + 1):
# for j in range(c22 + 1):
# for k in range(c33 + 1):
# a1 = i
# b1 = c11 - i
# a2 = j
# b2 = c22 - j
# a3 = k
# b3 = c33 - k
# if correct(a1, a2, a3, b1, b2, b3):
# print('Yes')
# exit(0)
print("No")
| false | 35.294118 | [
"-def correct():",
"+def correct(a1, a2, a3, b1, b2, b3):",
"+ if a1 + b1 != c11:",
"+ return False",
"+ if a2 + b2 != c22:",
"+ return False",
"+ if a3 + b3 != c33:",
"+ return False",
"- for j in range(c22 + 1):",
"- for k in range(c33 + 1):",
"- a1 = i",
"- b1 = c11 - i",
"- a2 = j",
"- b2 = c22 - j",
"- a3 = k",
"- b3 = c33 - k",
"- if correct():",
"- print(\"Yes\")",
"- exit(0)",
"+ a1 = i",
"+ b1 = c11 - i",
"+ a2 = a1 - c11 + c21",
"+ a3 = a1 - c11 + c31",
"+ b2 = b1 - c11 + c12",
"+ b3 = b1 - c11 + c13",
"+ # print(a1, a2, a3, b1, b2, b3)",
"+ if correct(a1, a2, a3, b1, b2, b3):",
"+ print(\"Yes\")",
"+ exit(0)",
"+# for i in range(c11 + 1):",
"+# for j in range(c22 + 1):",
"+# for k in range(c33 + 1):",
"+# a1 = i",
"+# b1 = c11 - i",
"+# a2 = j",
"+# b2 = c22 - j",
"+# a3 = k",
"+# b3 = c33 - k",
"+# if correct(a1, a2, a3, b1, b2, b3):",
"+# print('Yes')",
"+# exit(0)"
] | false | 0.065607 | 0.064208 | 1.021796 | [
"s846848593",
"s016882670"
] |
u952708174 | p02639 | python | s161497993 | s054171099 | 21 | 19 | 9,156 | 9,160 | Accepted | Accepted | 9.52 | X = [int(i) for i in input().split()]
print((X.index(0) + 1)) | print((15-sum([int(i) for i in input().split()]))) | 2 | 1 | 60 | 48 | X = [int(i) for i in input().split()]
print((X.index(0) + 1))
| print((15 - sum([int(i) for i in input().split()])))
| false | 50 | [
"-X = [int(i) for i in input().split()]",
"-print((X.index(0) + 1))",
"+print((15 - sum([int(i) for i in input().split()])))"
] | false | 0.040978 | 0.04173 | 0.981971 | [
"s161497993",
"s054171099"
] |
u394731058 | p03126 | python | s696307609 | s035432848 | 20 | 18 | 3,316 | 3,060 | Accepted | Accepted | 10 | import sys
import collections as c
input = sys.stdin.readline
def main():
ans = 0
N, M = list(map(int, input().split()))
a = []
for _ in range(N):
a += list(map(int, input().split()))[1:]
co = c.Counter(a)
for k, v in list(co.items()):
if v == N:
ans += 1
print(ans)
if __name__ == '__main__':
main() | import sys
input = sys.stdin.readline
def main():
ans = 0
N, M = list(map(int, input().split()))
f = set(range(1,M+1))
for _ in range(N):
a = set(list(map(int, input().split()))[1:])
f.intersection_update(a)
print((len(f)))
if __name__ == '__main__':
main() | 19 | 15 | 369 | 306 | import sys
import collections as c
input = sys.stdin.readline
def main():
ans = 0
N, M = list(map(int, input().split()))
a = []
for _ in range(N):
a += list(map(int, input().split()))[1:]
co = c.Counter(a)
for k, v in list(co.items()):
if v == N:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
ans = 0
N, M = list(map(int, input().split()))
f = set(range(1, M + 1))
for _ in range(N):
a = set(list(map(int, input().split()))[1:])
f.intersection_update(a)
print((len(f)))
if __name__ == "__main__":
main()
| false | 21.052632 | [
"-import collections as c",
"- a = []",
"+ f = set(range(1, M + 1))",
"- a += list(map(int, input().split()))[1:]",
"- co = c.Counter(a)",
"- for k, v in list(co.items()):",
"- if v == N:",
"- ans += 1",
"- print(ans)",
"+ a = set(list(map(int, input().split()))[1:])",
"+ f.intersection_update(a)",
"+ print((len(f)))"
] | false | 0.03593 | 0.037207 | 0.965653 | [
"s696307609",
"s035432848"
] |
u298297089 | p03308 | python | s942583960 | s880315184 | 177 | 18 | 38,768 | 3,060 | Accepted | Accepted | 89.83 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i+1,n):
if abs(a[i]- a[j]) > ans:
ans = abs(a[i]- a[j])
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
mx = 0
for i in range(n):
for j in range(i+1,n):
if mx < abs(a[i] - a[j]):
mx = abs(a[i] - a[j])
print(mx) | 8 | 8 | 192 | 178 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i + 1, n):
if abs(a[i] - a[j]) > ans:
ans = abs(a[i] - a[j])
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
mx = 0
for i in range(n):
for j in range(i + 1, n):
if mx < abs(a[i] - a[j]):
mx = abs(a[i] - a[j])
print(mx)
| false | 0 | [
"-ans = 0",
"+mx = 0",
"- if abs(a[i] - a[j]) > ans:",
"- ans = abs(a[i] - a[j])",
"-print(ans)",
"+ if mx < abs(a[i] - a[j]):",
"+ mx = abs(a[i] - a[j])",
"+print(mx)"
] | false | 0.042701 | 0.043078 | 0.991231 | [
"s942583960",
"s880315184"
] |
u486448566 | p03160 | python | s692484210 | s378941153 | 134 | 105 | 13,928 | 13,588 | Accepted | Accepted | 21.64 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
# +1
temp1 = abs(h[i]-h[i-1])+dp[i-1]
# +2
temp2 = abs(h[i]-h[i-2])+dp[i-2]
dp[i] = min(temp1, temp2)
print((dp[n-1])) | INF = float("inf")
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
input_int = lambda:int(eval(input()))
input_ints = lambda:list(map(int,input().split()))
input_ints_list = lambda:list(input_ints())
input_str = lambda:eval(input())
input_strs = lambda:input().split()
input_lines = lambda n,input_func:[input_func() for _ in range(n)]
import importlib
import_module = lambda module_name:importlib.import_module(module_name)
init_array_1dim = lambda value,n:[value]*n # 1ๆฌกๅ
้
ๅใ็ๆ
init_array_2dim = lambda value,n,m:[init_array_1dim(value,n) for _ in range(m)] # 2ๆฌกๅ
้
ๅใ็ๆ
gcd_base = lambda value1,value2:import_module('fractions').gcd(value1,value2) # ๆๅคงๅ
ฌ็ดๆฐ๏ผ2ๅค)
gcd = lambda lst:import_module('functools').reduce(gcd_base,lst) # ๆๅคงๅ
ฌ็ดๆฐ๏ผใชในใ๏ผ
lcm_base = lambda value1,value2:(value1*value2)//gcd_base(value1,value2) # ๆๅฐๅ
ฌๅๆฐ(2ๅค)
lcm = lambda lst:import_module('functools').reduce(lcm_base,lst,1) # ๆๅฐๅ
ฌๅๆฐ(ใชในใ)
permutations = lambda lst,n:import_module('itertools').permutations(lst,n) # ้ ๅ
combinations = lambda lst,n:import_module('itertools').combinations(lst,n) # ็ตใฟๅใใ
product = lambda lst1,lst2:import_module('itertools').product(lst1,lst2) # ไบใคใฎใชในใใฎ็ด็ฉ
round = lambda value:round(value) # ๅๆจไบๅ
ฅ
ceil = lambda value:import_module('math').ceil(value) # ๅใไธใ
floor = lambda value:import_module('math').floor(value) # ๅใๆจใฆ
# ใญใฅใผ
init_q = lambda lst: import_module('collections').deque(lst)
q_pop = lambda q: q.popleft() # ๅ
้ ญใใๅใๅบใ
q_push = lambda q,value:q.appendleft(value) # ๅ
้ ญใซ่ฟฝๅ ๏ผๅค๏ผ
q_pushlist = lambda q,lst:q.extendleft(lst) # ๅ
้ ญใซ่ฟฝๅ ๏ผใชในใ๏ผ
q_append = lambda q,value:q.append(value) # ๆซๅฐพใซ่ฟฝๅ ๏ผๅค๏ผ
q_appendlist = lambda q,lst:q.extend(lst) # ๆซๅฐพใซ่ฟฝๅ ๏ผใชในใ๏ผ
# ใใฉใคใชใชใใฃใญใฅใผ
init_heap = lambda a:import_module('heapq').heapify(a)
heap_push = lambda a,v:import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # ๆๅฐๅคใๅใๅบใ
def solution():
# ใใใซๅฎ่ฃ
N = input_int()
h = input_ints_list()
dp = init_array_1dim(0,N)
for i in range(N):
if i == 0:continue
elif i == 1:dp[1] = abs(h[1]-h[0])
else:
dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print((dp[N-1]))
if __name__ == '__main__':
solution() | 15 | 59 | 263 | 2,257 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
# +1
temp1 = abs(h[i] - h[i - 1]) + dp[i - 1]
# +2
temp2 = abs(h[i] - h[i - 2]) + dp[i - 2]
dp[i] = min(temp1, temp2)
print((dp[n - 1]))
| INF = float("inf")
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
input_int = lambda: int(eval(input()))
input_ints = lambda: list(map(int, input().split()))
input_ints_list = lambda: list(input_ints())
input_str = lambda: eval(input())
input_strs = lambda: input().split()
input_lines = lambda n, input_func: [input_func() for _ in range(n)]
import importlib
import_module = lambda module_name: importlib.import_module(module_name)
init_array_1dim = lambda value, n: [value] * n # 1ๆฌกๅ
้
ๅใ็ๆ
init_array_2dim = lambda value, n, m: [
init_array_1dim(value, n) for _ in range(m)
] # 2ๆฌกๅ
้
ๅใ็ๆ
gcd_base = lambda value1, value2: import_module("fractions").gcd(
value1, value2
) # ๆๅคงๅ
ฌ็ดๆฐ๏ผ2ๅค)
gcd = lambda lst: import_module("functools").reduce(gcd_base, lst) # ๆๅคงๅ
ฌ็ดๆฐ๏ผใชในใ๏ผ
lcm_base = lambda value1, value2: (value1 * value2) // gcd_base(
value1, value2
) # ๆๅฐๅ
ฌๅๆฐ(2ๅค)
lcm = lambda lst: import_module("functools").reduce(lcm_base, lst, 1) # ๆๅฐๅ
ฌๅๆฐ(ใชในใ)
permutations = lambda lst, n: import_module("itertools").permutations(lst, n) # ้ ๅ
combinations = lambda lst, n: import_module("itertools").combinations(lst, n) # ็ตใฟๅใใ
product = lambda lst1, lst2: import_module("itertools").product(lst1, lst2) # ไบใคใฎใชในใใฎ็ด็ฉ
round = lambda value: round(value) # ๅๆจไบๅ
ฅ
ceil = lambda value: import_module("math").ceil(value) # ๅใไธใ
floor = lambda value: import_module("math").floor(value) # ๅใๆจใฆ
# ใญใฅใผ
init_q = lambda lst: import_module("collections").deque(lst)
q_pop = lambda q: q.popleft() # ๅ
้ ญใใๅใๅบใ
q_push = lambda q, value: q.appendleft(value) # ๅ
้ ญใซ่ฟฝๅ ๏ผๅค๏ผ
q_pushlist = lambda q, lst: q.extendleft(lst) # ๅ
้ ญใซ่ฟฝๅ ๏ผใชในใ๏ผ
q_append = lambda q, value: q.append(value) # ๆซๅฐพใซ่ฟฝๅ ๏ผๅค๏ผ
q_appendlist = lambda q, lst: q.extend(lst) # ๆซๅฐพใซ่ฟฝๅ ๏ผใชในใ๏ผ
# ใใฉใคใชใชใใฃใญใฅใผ
init_heap = lambda a: import_module("heapq").heapify(a)
heap_push = lambda a, v: import_module("heapq").heappush(a, v)
heap_pop = lambda a: import_module("heapq").heappop(a) # ๆๅฐๅคใๅใๅบใ
def solution():
# ใใใซๅฎ่ฃ
N = input_int()
h = input_ints_list()
dp = init_array_1dim(0, N)
for i in range(N):
if i == 0:
continue
elif i == 1:
dp[1] = abs(h[1] - h[0])
else:
dp[i] = min(
dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])
)
print((dp[N - 1]))
if __name__ == "__main__":
solution()
| false | 74.576271 | [
"-n = int(eval(input()))",
"-h = list(map(int, input().split()))",
"-dp = [0] * n",
"-dp[1] = abs(h[1] - h[0])",
"-for i in range(2, n):",
"- # +1",
"- temp1 = abs(h[i] - h[i - 1]) + dp[i - 1]",
"- # +2",
"- temp2 = abs(h[i] - h[i - 2]) + dp[i - 2]",
"- dp[i] = min(temp1, temp2)",
"-print((dp[n - 1]))",
"+INF = float(\"inf\")",
"+import sys",
"+",
"+sys.setrecursionlimit(10**9)",
"+input = sys.stdin.readline",
"+input_int = lambda: int(eval(input()))",
"+input_ints = lambda: list(map(int, input().split()))",
"+input_ints_list = lambda: list(input_ints())",
"+input_str = lambda: eval(input())",
"+input_strs = lambda: input().split()",
"+input_lines = lambda n, input_func: [input_func() for _ in range(n)]",
"+import importlib",
"+",
"+import_module = lambda module_name: importlib.import_module(module_name)",
"+init_array_1dim = lambda value, n: [value] * n # 1ๆฌกๅ
้
ๅใ็ๆ",
"+init_array_2dim = lambda value, n, m: [",
"+ init_array_1dim(value, n) for _ in range(m)",
"+] # 2ๆฌกๅ
้
ๅใ็ๆ",
"+gcd_base = lambda value1, value2: import_module(\"fractions\").gcd(",
"+ value1, value2",
"+) # ๆๅคงๅ
ฌ็ดๆฐ๏ผ2ๅค)",
"+gcd = lambda lst: import_module(\"functools\").reduce(gcd_base, lst) # ๆๅคงๅ
ฌ็ดๆฐ๏ผใชในใ๏ผ",
"+lcm_base = lambda value1, value2: (value1 * value2) // gcd_base(",
"+ value1, value2",
"+) # ๆๅฐๅ
ฌๅๆฐ(2ๅค)",
"+lcm = lambda lst: import_module(\"functools\").reduce(lcm_base, lst, 1) # ๆๅฐๅ
ฌๅๆฐ(ใชในใ)",
"+permutations = lambda lst, n: import_module(\"itertools\").permutations(lst, n) # ้ ๅ",
"+combinations = lambda lst, n: import_module(\"itertools\").combinations(lst, n) # ็ตใฟๅใใ",
"+product = lambda lst1, lst2: import_module(\"itertools\").product(lst1, lst2) # ไบใคใฎใชในใใฎ็ด็ฉ",
"+round = lambda value: round(value) # ๅๆจไบๅ
ฅ",
"+ceil = lambda value: import_module(\"math\").ceil(value) # ๅใไธใ",
"+floor = lambda value: import_module(\"math\").floor(value) # ๅใๆจใฆ",
"+# ใญใฅใผ",
"+init_q = lambda lst: import_module(\"collections\").deque(lst)",
"+q_pop = lambda q: q.popleft() # ๅ
้ ญใใๅใๅบใ",
"+q_push = lambda q, value: q.appendleft(value) # ๅ
้ ญใซ่ฟฝๅ ๏ผๅค๏ผ",
"+q_pushlist = lambda q, lst: q.extendleft(lst) # ๅ
้ ญใซ่ฟฝๅ ๏ผใชในใ๏ผ",
"+q_append = lambda q, value: q.append(value) # ๆซๅฐพใซ่ฟฝๅ ๏ผๅค๏ผ",
"+q_appendlist = lambda q, lst: q.extend(lst) # ๆซๅฐพใซ่ฟฝๅ ๏ผใชในใ๏ผ",
"+# ใใฉใคใชใชใใฃใญใฅใผ",
"+init_heap = lambda a: import_module(\"heapq\").heapify(a)",
"+heap_push = lambda a, v: import_module(\"heapq\").heappush(a, v)",
"+heap_pop = lambda a: import_module(\"heapq\").heappop(a) # ๆๅฐๅคใๅใๅบใ",
"+",
"+",
"+def solution():",
"+ # ใใใซๅฎ่ฃ
",
"+ N = input_int()",
"+ h = input_ints_list()",
"+ dp = init_array_1dim(0, N)",
"+ for i in range(N):",
"+ if i == 0:",
"+ continue",
"+ elif i == 1:",
"+ dp[1] = abs(h[1] - h[0])",
"+ else:",
"+ dp[i] = min(",
"+ dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])",
"+ )",
"+ print((dp[N - 1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solution()"
] | false | 0.047803 | 0.050335 | 0.949695 | [
"s692484210",
"s378941153"
] |
u947883560 | p03212 | python | s954790841 | s440485449 | 64 | 36 | 3,064 | 3,572 | Accepted | Accepted | 43.75 | N = int(eval(input()))
import math
INF = 10**9
def dfs(s):
if int(s) > N:
return 0
elif s.count('3') == 0 or s.count('5') == 0 or s.count('7') == 0:
return 0 + dfs(s + "3") + dfs(s + "5") + dfs(s + "7")
else:
# print(s)
return 1 + dfs(s + "3") + dfs(s + "5") + dfs(s + "7")
print((dfs("0"))) | #!/usr/bin/env python3
import sys
import functools
import itertools
INF = float("inf")
@functools.lru_cache(maxsize=None)
def pow(b, n):
return b**n
def f(n):
# nๆกใฎ753ๆฐ
if n < 3:
return 0
return pow(3, n) - 3*pow(2, n) + 3
def solve(N: int):
ketamax = len(str(N))
ans = 0
# ๆก
for i in range(3, ketamax):
ans += f(i)
# print(ans)
# ๆๅคงๆกๆฐใฎๅ ดๅใ ใใใซใใ(O(N))
for item in itertools.product(["3", "5", "7"], repeat=ketamax):
if "3" not in item or "5" not in item or "7" not in item:
continue
elif int("".join(item)) > N:
continue
else:
ans += 1
print(ans)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == '__main__':
main()
| 16 | 53 | 346 | 1,000 | N = int(eval(input()))
import math
INF = 10**9
def dfs(s):
if int(s) > N:
return 0
elif s.count("3") == 0 or s.count("5") == 0 or s.count("7") == 0:
return 0 + dfs(s + "3") + dfs(s + "5") + dfs(s + "7")
else:
# print(s)
return 1 + dfs(s + "3") + dfs(s + "5") + dfs(s + "7")
print((dfs("0")))
| #!/usr/bin/env python3
import sys
import functools
import itertools
INF = float("inf")
@functools.lru_cache(maxsize=None)
def pow(b, n):
return b**n
def f(n):
# nๆกใฎ753ๆฐ
if n < 3:
return 0
return pow(3, n) - 3 * pow(2, n) + 3
def solve(N: int):
ketamax = len(str(N))
ans = 0
# ๆก
for i in range(3, ketamax):
ans += f(i)
# print(ans)
# ๆๅคงๆกๆฐใฎๅ ดๅใ ใใใซใใ(O(N))
for item in itertools.product(["3", "5", "7"], repeat=ketamax):
if "3" not in item or "5" not in item or "7" not in item:
continue
elif int("".join(item)) > N:
continue
else:
ans += 1
print(ans)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == "__main__":
main()
| false | 69.811321 | [
"-N = int(eval(input()))",
"-import math",
"+#!/usr/bin/env python3",
"+import sys",
"+import functools",
"+import itertools",
"-INF = 10**9",
"+INF = float(\"inf\")",
"-def dfs(s):",
"- if int(s) > N:",
"- return 0",
"- elif s.count(\"3\") == 0 or s.count(\"5\") == 0 or s.count(\"7\") == 0:",
"- return 0 + dfs(s + \"3\") + dfs(s + \"5\") + dfs(s + \"7\")",
"- else:",
"- # print(s)",
"- return 1 + dfs(s + \"3\") + dfs(s + \"5\") + dfs(s + \"7\")",
"+@functools.lru_cache(maxsize=None)",
"+def pow(b, n):",
"+ return b**n",
"-print((dfs(\"0\")))",
"+def f(n):",
"+ # nๆกใฎ753ๆฐ",
"+ if n < 3:",
"+ return 0",
"+ return pow(3, n) - 3 * pow(2, n) + 3",
"+",
"+",
"+def solve(N: int):",
"+ ketamax = len(str(N))",
"+ ans = 0",
"+ # ๆก",
"+ for i in range(3, ketamax):",
"+ ans += f(i)",
"+ # print(ans)",
"+ # ๆๅคงๆกๆฐใฎๅ ดๅใ ใใใซใใ(O(N))",
"+ for item in itertools.product([\"3\", \"5\", \"7\"], repeat=ketamax):",
"+ if \"3\" not in item or \"5\" not in item or \"7\" not in item:",
"+ continue",
"+ elif int(\"\".join(item)) > N:",
"+ continue",
"+ else:",
"+ ans += 1",
"+ print(ans)",
"+ return",
"+",
"+",
"+def main():",
"+ def iterate_tokens():",
"+ for line in sys.stdin:",
"+ for word in line.split():",
"+ yield word",
"+",
"+ tokens = iterate_tokens()",
"+ N = int(next(tokens)) # type: int",
"+ solve(N)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.046019 | 0.041701 | 1.103556 | [
"s954790841",
"s440485449"
] |
u391819434 | p03328 | python | s556008736 | s832166733 | 516 | 17 | 38,768 | 3,060 | Accepted | Accepted | 96.71 | A,B=list(map(int,input().split()))
H=[0]*1000
i=1
while i<=999:
H[i]=i+H[i-1]
i+=1
ans=0
while True:
if (A+ans in H)and(B+ans==H[H.index(A+ans)+1] in H):
break
else:
ans+=1
print(ans) | A,B=list(map(int,input().split()))
H=[0]*1000
i=1
while i<=999:
H[i]=i+H[i-1]
i+=1
print((H[B-A]-B)) | 16 | 9 | 231 | 110 | A, B = list(map(int, input().split()))
H = [0] * 1000
i = 1
while i <= 999:
H[i] = i + H[i - 1]
i += 1
ans = 0
while True:
if (A + ans in H) and (B + ans == H[H.index(A + ans) + 1] in H):
break
else:
ans += 1
print(ans)
| A, B = list(map(int, input().split()))
H = [0] * 1000
i = 1
while i <= 999:
H[i] = i + H[i - 1]
i += 1
print((H[B - A] - B))
| false | 43.75 | [
"-ans = 0",
"-while True:",
"- if (A + ans in H) and (B + ans == H[H.index(A + ans) + 1] in H):",
"- break",
"- else:",
"- ans += 1",
"-print(ans)",
"+print((H[B - A] - B))"
] | false | 0.120506 | 0.036196 | 3.329259 | [
"s556008736",
"s832166733"
] |
u350997995 | p03575 | python | s229749074 | s380061430 | 409 | 25 | 3,064 | 3,064 | Accepted | Accepted | 93.89 | N,M = list(map(int,input().split()))
T = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
a,b = list(map(int,input().split()))
T[a][b] = 1
T[b][a] = 1
ans = 0
def f(v,x,y):
global N,M,T,a
a[v] = 1
for i in range(N+1):
if (v==x and i==y) or (v==y and i==x):
continue
elif T[v][i]==0 or a[i]==1:
continue
f(i,x,y)
for i in range(1,N+1):
for j in range(i,N+1):
a = [0 for _ in range(N+1)]
f(1,i,j)
if sum(a)!=N:
ans += 1
print(ans) | N,M = list(map(int,input().split()))
T = [[0]*N for i in range(N)]
G = []
for i in range(M):
a,b = [int(x)-1 for x in input().split()]
T[a][b] = 1
T[b][a] = 1
G.append((a,b))
def check(N,T):
A = [0]*N
Q = [0]
while Q:
q = Q.pop()
if A[q]:continue
A[q] = 1
for c in range(N):
if T[q][c]:
Q.append(c)
return sum(A)!=N
ans = 0
for g in G:
a,b = g[0],g[1]
T[a][b] = 0
T[b][a] = 0
if check(N,T):
ans += 1
T[a][b] = 1
T[b][a] = 1
print(ans) | 23 | 31 | 566 | 587 | N, M = list(map(int, input().split()))
T = [[0 for i in range(N + 1)] for j in range(N + 1)]
for i in range(M):
a, b = list(map(int, input().split()))
T[a][b] = 1
T[b][a] = 1
ans = 0
def f(v, x, y):
global N, M, T, a
a[v] = 1
for i in range(N + 1):
if (v == x and i == y) or (v == y and i == x):
continue
elif T[v][i] == 0 or a[i] == 1:
continue
f(i, x, y)
for i in range(1, N + 1):
for j in range(i, N + 1):
a = [0 for _ in range(N + 1)]
f(1, i, j)
if sum(a) != N:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
T = [[0] * N for i in range(N)]
G = []
for i in range(M):
a, b = [int(x) - 1 for x in input().split()]
T[a][b] = 1
T[b][a] = 1
G.append((a, b))
def check(N, T):
A = [0] * N
Q = [0]
while Q:
q = Q.pop()
if A[q]:
continue
A[q] = 1
for c in range(N):
if T[q][c]:
Q.append(c)
return sum(A) != N
ans = 0
for g in G:
a, b = g[0], g[1]
T[a][b] = 0
T[b][a] = 0
if check(N, T):
ans += 1
T[a][b] = 1
T[b][a] = 1
print(ans)
| false | 25.806452 | [
"-T = [[0 for i in range(N + 1)] for j in range(N + 1)]",
"+T = [[0] * N for i in range(N)]",
"+G = []",
"- a, b = list(map(int, input().split()))",
"+ a, b = [int(x) - 1 for x in input().split()]",
"-ans = 0",
"+ G.append((a, b))",
"-def f(v, x, y):",
"- global N, M, T, a",
"- a[v] = 1",
"- for i in range(N + 1):",
"- if (v == x and i == y) or (v == y and i == x):",
"+def check(N, T):",
"+ A = [0] * N",
"+ Q = [0]",
"+ while Q:",
"+ q = Q.pop()",
"+ if A[q]:",
"- elif T[v][i] == 0 or a[i] == 1:",
"- continue",
"- f(i, x, y)",
"+ A[q] = 1",
"+ for c in range(N):",
"+ if T[q][c]:",
"+ Q.append(c)",
"+ return sum(A) != N",
"-for i in range(1, N + 1):",
"- for j in range(i, N + 1):",
"- a = [0 for _ in range(N + 1)]",
"- f(1, i, j)",
"- if sum(a) != N:",
"- ans += 1",
"+ans = 0",
"+for g in G:",
"+ a, b = g[0], g[1]",
"+ T[a][b] = 0",
"+ T[b][a] = 0",
"+ if check(N, T):",
"+ ans += 1",
"+ T[a][b] = 1",
"+ T[b][a] = 1"
] | false | 0.042087 | 0.037268 | 1.129303 | [
"s229749074",
"s380061430"
] |
u366963613 | p02912 | python | s648930695 | s983790374 | 633 | 310 | 23,132 | 53,752 | Accepted | Accepted | 51.03 | # -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import heapq
import collections
import itertools
import bisect
mod = 10 ** 9 + 7
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = list(np.array(A)*-1)
heap_tree = heapq.heapify(A)
for i in range(M):
max_value = heapq.heappop(A)*-1
max_value = (max_value//2)*-1
heapq.heappush(A, max_value)
ans = 0
for a in A:
ans -= a
print(ans)
| # -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)
def zz():
return list(map(int, sys.stdin.readline().split()))
def z():
return int(sys.stdin.readline())
def S():
return sys.stdin.readline()[:-1]
def C(line):
return [sys.stdin.readline() for _ in range(line)]
N, M = zz()
A = zz()
A = [-a for a in A]
heapq.heapify(A)
for i in range(M):
money = heapq.heappop(A)
money *= -1
money //= 2
money *= -1
heapq.heappush(A, money)
print((sum(A)*-1))
| 20 | 42 | 468 | 733 | # -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import heapq
import collections
import itertools
import bisect
mod = 10**9 + 7
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = list(np.array(A) * -1)
heap_tree = heapq.heapify(A)
for i in range(M):
max_value = heapq.heappop(A) * -1
max_value = (max_value // 2) * -1
heapq.heappush(A, max_value)
ans = 0
for a in A:
ans -= a
print(ans)
| # -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)
def zz():
return list(map(int, sys.stdin.readline().split()))
def z():
return int(sys.stdin.readline())
def S():
return sys.stdin.readline()[:-1]
def C(line):
return [sys.stdin.readline() for _ in range(line)]
N, M = zz()
A = zz()
A = [-a for a in A]
heapq.heapify(A)
for i in range(M):
money = heapq.heappop(A)
money *= -1
money //= 2
money *= -1
heapq.heappush(A, money)
print((sum(A) * -1))
| false | 52.380952 | [
"+import sys",
"+from collections import defaultdict",
"+from scipy.special import comb",
"+import copy",
"-mod = 10**9 + 7",
"-N, M = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-A = list(np.array(A) * -1)",
"-heap_tree = heapq.heapify(A)",
"+sys.setrecursionlimit(10**6)",
"+",
"+",
"+def zz():",
"+ return list(map(int, sys.stdin.readline().split()))",
"+",
"+",
"+def z():",
"+ return int(sys.stdin.readline())",
"+",
"+",
"+def S():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+",
"+def C(line):",
"+ return [sys.stdin.readline() for _ in range(line)]",
"+",
"+",
"+N, M = zz()",
"+A = zz()",
"+A = [-a for a in A]",
"+heapq.heapify(A)",
"- max_value = heapq.heappop(A) * -1",
"- max_value = (max_value // 2) * -1",
"- heapq.heappush(A, max_value)",
"-ans = 0",
"-for a in A:",
"- ans -= a",
"-print(ans)",
"+ money = heapq.heappop(A)",
"+ money *= -1",
"+ money //= 2",
"+ money *= -1",
"+ heapq.heappush(A, money)",
"+print((sum(A) * -1))"
] | false | 0.323939 | 0.046864 | 6.912346 | [
"s648930695",
"s983790374"
] |
u693566873 | p02555 | python | s594957914 | s968004723 | 338 | 188 | 9,184 | 63,600 | Accepted | Accepted | 44.38 | s = int(eval(input()))
mod = 10**9+7
ans = 0
for n in range(1, s//3 + 1):
left = s - n * 3
# left -> n
# left + n - 1 choose n-1
count = 1
for i in range(1, n):
count *= left + i
count %= mod
for i in range(1, n):
count *= pow(i, -1, mod)
count %= mod
ans += count
ans %= mod
print(ans)
| S = int(eval(input()))
f = [0] * (S+1)
f[0] = 1
cumsum = 1
mod = 10**9+7
for i in range(3, S+1):
f[i] = cumsum - f[i-1] - f[i - 2]
f[i] %= mod
cumsum += f[i]
print((f[-1])) | 19 | 10 | 336 | 179 | s = int(eval(input()))
mod = 10**9 + 7
ans = 0
for n in range(1, s // 3 + 1):
left = s - n * 3
# left -> n
# left + n - 1 choose n-1
count = 1
for i in range(1, n):
count *= left + i
count %= mod
for i in range(1, n):
count *= pow(i, -1, mod)
count %= mod
ans += count
ans %= mod
print(ans)
| S = int(eval(input()))
f = [0] * (S + 1)
f[0] = 1
cumsum = 1
mod = 10**9 + 7
for i in range(3, S + 1):
f[i] = cumsum - f[i - 1] - f[i - 2]
f[i] %= mod
cumsum += f[i]
print((f[-1]))
| false | 47.368421 | [
"-s = int(eval(input()))",
"+S = int(eval(input()))",
"+f = [0] * (S + 1)",
"+f[0] = 1",
"+cumsum = 1",
"-ans = 0",
"-for n in range(1, s // 3 + 1):",
"- left = s - n * 3",
"- # left -> n",
"- # left + n - 1 choose n-1",
"- count = 1",
"- for i in range(1, n):",
"- count *= left + i",
"- count %= mod",
"- for i in range(1, n):",
"- count *= pow(i, -1, mod)",
"- count %= mod",
"- ans += count",
"- ans %= mod",
"-print(ans)",
"+for i in range(3, S + 1):",
"+ f[i] = cumsum - f[i - 1] - f[i - 2]",
"+ f[i] %= mod",
"+ cumsum += f[i]",
"+print((f[-1]))"
] | false | 0.086433 | 0.037082 | 2.330869 | [
"s594957914",
"s968004723"
] |
u531220228 | p03109 | python | s839701759 | s943865109 | 34 | 19 | 4,464 | 3,060 | Accepted | Accepted | 44.12 | import datetime as dt
s = dt.datetime.strptime(eval(input()), '%Y/%m/%d')
lastD = dt.datetime.strptime('2019/4/30', '%Y/%m/%d')
if s <= lastD:
print('Heisei')
else:
print('TBD') | y,m,d = list(map(int, input().split('/')))
ans = ''
if y<2019:
ans = 'Heisei'
elif y==2019:
if m<4 or (m==4 and d<=30):
ans = 'Heisei'
else:
ans = 'TBD'
else:
ans = 'TBD'
print(ans) | 8 | 13 | 183 | 204 | import datetime as dt
s = dt.datetime.strptime(eval(input()), "%Y/%m/%d")
lastD = dt.datetime.strptime("2019/4/30", "%Y/%m/%d")
if s <= lastD:
print("Heisei")
else:
print("TBD")
| y, m, d = list(map(int, input().split("/")))
ans = ""
if y < 2019:
ans = "Heisei"
elif y == 2019:
if m < 4 or (m == 4 and d <= 30):
ans = "Heisei"
else:
ans = "TBD"
else:
ans = "TBD"
print(ans)
| false | 38.461538 | [
"-import datetime as dt",
"-",
"-s = dt.datetime.strptime(eval(input()), \"%Y/%m/%d\")",
"-lastD = dt.datetime.strptime(\"2019/4/30\", \"%Y/%m/%d\")",
"-if s <= lastD:",
"- print(\"Heisei\")",
"+y, m, d = list(map(int, input().split(\"/\")))",
"+ans = \"\"",
"+if y < 2019:",
"+ ans = \"Heisei\"",
"+elif y == 2019:",
"+ if m < 4 or (m == 4 and d <= 30):",
"+ ans = \"Heisei\"",
"+ else:",
"+ ans = \"TBD\"",
"- print(\"TBD\")",
"+ ans = \"TBD\"",
"+print(ans)"
] | false | 0.039194 | 0.040156 | 0.976034 | [
"s839701759",
"s943865109"
] |
u188827677 | p03425 | python | s892792032 | s604858820 | 160 | 146 | 9,240 | 10,080 | Accepted | Accepted | 8.75 | n = int(eval(input()))
march = ("M","A","R","C","H")
prefix = []
d = {}
for _ in range(n):
pre = input()[0]
if pre in march:
if pre not in prefix:
prefix.append(pre)
d[pre] = 1
else:
d[pre] += 1
t = len(prefix)
if t < 3:
print((0))
exit()
ans = 0
for i in range(t-2):
for j in range(i+1, t-1):
for k in range(j+1,t):
ans += d[prefix[i]]*d[prefix[j]]*d[prefix[k]]
print(ans) | from collections import Counter
from itertools import combinations
n = int(eval(input()))
s = []
for _ in range(n):
t = input()[0]
if t in {"M","A","R","C","H"}:
s.append(t)
count = Counter(s)
if len(count) < 3:
print((0))
exit()
nums = []
for i in list(count.values()):nums.append(i)
ans = 0
for i in combinations(nums, 3):
ans += i[0]*i[1]*i[2]
print(ans) | 25 | 21 | 444 | 380 | n = int(eval(input()))
march = ("M", "A", "R", "C", "H")
prefix = []
d = {}
for _ in range(n):
pre = input()[0]
if pre in march:
if pre not in prefix:
prefix.append(pre)
d[pre] = 1
else:
d[pre] += 1
t = len(prefix)
if t < 3:
print((0))
exit()
ans = 0
for i in range(t - 2):
for j in range(i + 1, t - 1):
for k in range(j + 1, t):
ans += d[prefix[i]] * d[prefix[j]] * d[prefix[k]]
print(ans)
| from collections import Counter
from itertools import combinations
n = int(eval(input()))
s = []
for _ in range(n):
t = input()[0]
if t in {"M", "A", "R", "C", "H"}:
s.append(t)
count = Counter(s)
if len(count) < 3:
print((0))
exit()
nums = []
for i in list(count.values()):
nums.append(i)
ans = 0
for i in combinations(nums, 3):
ans += i[0] * i[1] * i[2]
print(ans)
| false | 16 | [
"+from collections import Counter",
"+from itertools import combinations",
"+",
"-march = (\"M\", \"A\", \"R\", \"C\", \"H\")",
"-prefix = []",
"-d = {}",
"+s = []",
"- pre = input()[0]",
"- if pre in march:",
"- if pre not in prefix:",
"- prefix.append(pre)",
"- d[pre] = 1",
"- else:",
"- d[pre] += 1",
"-t = len(prefix)",
"-if t < 3:",
"+ t = input()[0]",
"+ if t in {\"M\", \"A\", \"R\", \"C\", \"H\"}:",
"+ s.append(t)",
"+count = Counter(s)",
"+if len(count) < 3:",
"+nums = []",
"+for i in list(count.values()):",
"+ nums.append(i)",
"-for i in range(t - 2):",
"- for j in range(i + 1, t - 1):",
"- for k in range(j + 1, t):",
"- ans += d[prefix[i]] * d[prefix[j]] * d[prefix[k]]",
"+for i in combinations(nums, 3):",
"+ ans += i[0] * i[1] * i[2]"
] | false | 0.03836 | 0.041604 | 0.92203 | [
"s892792032",
"s604858820"
] |
u057993957 | p03361 | python | s385795093 | s052196718 | 215 | 22 | 12,448 | 3,064 | Accepted | Accepted | 89.77 | import numpy as np
h, w = list(map(int, input().split()))
s = np.array([list(eval(input())) for i in range(h)])
infer = []
for i in range(h):
for j in range(w):
if s[i][j] == "#":
pts = set([
(max(0, i-1), j),
(i, max(0, j-1)),
(min(h-1, i+1), j),
(i, min(w-1, j+1))
])
check = np.array([ s[ix][iy] for ix, iy in list(pts - set([(i, j)])) ])
infer.append((check == "#").sum())
print(("No" if 0 in infer else "Yes"))
| h, w = list(map(int, input().split()))
maps = [list(eval(input())) for i in range(h)]
def search(i, j):
pts = set([ (max(0, i-1), j), (i, max(0, j-1)),
(min(h-1, i+1), j), (i, min(w-1, j+1))])
for dh, dw in list(pts):
if maps[dh][dw] == "#":
return True
return False
flag = True
for i in range(h):
for j in range(w):
if maps[i][j] == "#":
if not search(i, j):
flag = False
break
print(("Yes" if flag else "No")) | 23 | 21 | 521 | 491 | import numpy as np
h, w = list(map(int, input().split()))
s = np.array([list(eval(input())) for i in range(h)])
infer = []
for i in range(h):
for j in range(w):
if s[i][j] == "#":
pts = set(
[
(max(0, i - 1), j),
(i, max(0, j - 1)),
(min(h - 1, i + 1), j),
(i, min(w - 1, j + 1)),
]
)
check = np.array([s[ix][iy] for ix, iy in list(pts - set([(i, j)]))])
infer.append((check == "#").sum())
print(("No" if 0 in infer else "Yes"))
| h, w = list(map(int, input().split()))
maps = [list(eval(input())) for i in range(h)]
def search(i, j):
pts = set(
[
(max(0, i - 1), j),
(i, max(0, j - 1)),
(min(h - 1, i + 1), j),
(i, min(w - 1, j + 1)),
]
)
for dh, dw in list(pts):
if maps[dh][dw] == "#":
return True
return False
flag = True
for i in range(h):
for j in range(w):
if maps[i][j] == "#":
if not search(i, j):
flag = False
break
print(("Yes" if flag else "No"))
| false | 8.695652 | [
"-import numpy as np",
"+h, w = list(map(int, input().split()))",
"+maps = [list(eval(input())) for i in range(h)]",
"-h, w = list(map(int, input().split()))",
"-s = np.array([list(eval(input())) for i in range(h)])",
"-infer = []",
"+",
"+def search(i, j):",
"+ pts = set(",
"+ [",
"+ (max(0, i - 1), j),",
"+ (i, max(0, j - 1)),",
"+ (min(h - 1, i + 1), j),",
"+ (i, min(w - 1, j + 1)),",
"+ ]",
"+ )",
"+ for dh, dw in list(pts):",
"+ if maps[dh][dw] == \"#\":",
"+ return True",
"+ return False",
"+",
"+",
"+flag = True",
"- if s[i][j] == \"#\":",
"- pts = set(",
"- [",
"- (max(0, i - 1), j),",
"- (i, max(0, j - 1)),",
"- (min(h - 1, i + 1), j),",
"- (i, min(w - 1, j + 1)),",
"- ]",
"- )",
"- check = np.array([s[ix][iy] for ix, iy in list(pts - set([(i, j)]))])",
"- infer.append((check == \"#\").sum())",
"-print((\"No\" if 0 in infer else \"Yes\"))",
"+ if maps[i][j] == \"#\":",
"+ if not search(i, j):",
"+ flag = False",
"+ break",
"+print((\"Yes\" if flag else \"No\"))"
] | false | 0.773575 | 0.044039 | 17.565842 | [
"s385795093",
"s052196718"
] |
u883048396 | p03252 | python | s182467740 | s688190942 | 123 | 28 | 6,704 | 3,632 | Accepted | Accepted | 77.24 | sS = input().rstrip()
sT = input().rstrip()
def fConv2B(sA):
iL = len(sA)
dA = {}
for s in "abcdefghijklmnopqrstuvwxyz":
dA[s] = 0
iCounter = 1
for i in range(iL):
s = sA[i]
if s in dA:
if dA[sA[i]] == 0:
dA[sA[i]] = iCounter
iCounter += 1
if iCounter == 27 :
break
aR = [0]*iL
for i in range(iL):
aR[i] = dA[sA[i]]
# print(aR)
return aR
if fConv2B(sS) == fConv2B(sT) :
print("Yes")
else:
print("No")
| sS = input().rstrip()
sT = input().rstrip()
aS = [0] * 26
aT = [0] * 26
sABC = "abcdefghijklmnopqrstuvwxyz"
for i in range(26):
aS[i]=sS.count(sABC[i])
aT[i]=sT.count(sABC[i])
aS.sort()
aT.sort()
if aS == aT:
print ("Yes")
else:
print ("No")
| 33 | 15 | 581 | 273 | sS = input().rstrip()
sT = input().rstrip()
def fConv2B(sA):
iL = len(sA)
dA = {}
for s in "abcdefghijklmnopqrstuvwxyz":
dA[s] = 0
iCounter = 1
for i in range(iL):
s = sA[i]
if s in dA:
if dA[sA[i]] == 0:
dA[sA[i]] = iCounter
iCounter += 1
if iCounter == 27:
break
aR = [0] * iL
for i in range(iL):
aR[i] = dA[sA[i]]
# print(aR)
return aR
if fConv2B(sS) == fConv2B(sT):
print("Yes")
else:
print("No")
| sS = input().rstrip()
sT = input().rstrip()
aS = [0] * 26
aT = [0] * 26
sABC = "abcdefghijklmnopqrstuvwxyz"
for i in range(26):
aS[i] = sS.count(sABC[i])
aT[i] = sT.count(sABC[i])
aS.sort()
aT.sort()
if aS == aT:
print("Yes")
else:
print("No")
| false | 54.545455 | [
"-",
"-",
"-def fConv2B(sA):",
"- iL = len(sA)",
"- dA = {}",
"- for s in \"abcdefghijklmnopqrstuvwxyz\":",
"- dA[s] = 0",
"- iCounter = 1",
"- for i in range(iL):",
"- s = sA[i]",
"- if s in dA:",
"- if dA[sA[i]] == 0:",
"- dA[sA[i]] = iCounter",
"- iCounter += 1",
"- if iCounter == 27:",
"- break",
"- aR = [0] * iL",
"- for i in range(iL):",
"- aR[i] = dA[sA[i]]",
"- # print(aR)",
"- return aR",
"-",
"-",
"-if fConv2B(sS) == fConv2B(sT):",
"+aS = [0] * 26",
"+aT = [0] * 26",
"+sABC = \"abcdefghijklmnopqrstuvwxyz\"",
"+for i in range(26):",
"+ aS[i] = sS.count(sABC[i])",
"+ aT[i] = sT.count(sABC[i])",
"+aS.sort()",
"+aT.sort()",
"+if aS == aT:"
] | false | 0.045496 | 0.037551 | 1.211571 | [
"s182467740",
"s688190942"
] |
u827202523 | p02845 | python | s986339485 | s870902994 | 250 | 103 | 57,200 | 86,584 | Accepted | Accepted | 58.8 | import sys
# input = sys.stdin.buffer.readline
def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getlist():
return list(map(int, input().split()))
import heapq
import bisect
import copy
# import math
def warshall_floyd(d, N):
for k in range(N):
for i in range(N):
for j in range(N):
d[i * N +j] = min(d[i * N +j], d[i * N + k] + d[k * N + j])
return d
MOD = 10**9 + 7
def main():
n = getN()
nums = getlist()
ans = 1
bc, bv, bb = -1, -1, -1
for num in nums:
tmp = 0
added = 0
if num == bc + 1:
tmp += 1
if not added:
bc += 1
added = 1
if num == bv + 1:
tmp += 1
if not added:
bv += 1
added = 1
if num == bb + 1:
tmp += 1
if not added:
bb += 1
added = 1
ans *= tmp
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
| import sys
from collections import defaultdict, deque, Counter
import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def era(n):
ret = [1 for i in range(n + 2)]
for i in range(2, int(math.sqrt(n) +3)):
if ret[i] != 0:
for j in range(2, n//i + 1):
ret[i * j] = 0
rret = []
for i, r in enumerate(ret):
if r == 1 and i != 0:
rret.append(i)
return rret
def houjyo(n, m, k, kaijyo):
# kaburi ... k
# all ... n
if k == n:
return 1
else:
# kasanarierabi nck * nokorierabi (m - k)p(n-k) - houjyo(+1)
ret = nck(n,k,kaijyo) * npk(m-k, n-k, kaijyo) # - (k + 1) * houjyo(n, m, k+1, kaijyo)
# print(nck(n,k,kaijyo) , npk(m-k, n-k, kaijyo))
return ret % MOD
def nck(n, k, kaijyo):
return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
if k == 0 or k == n:
return n % MOD
return (kaijyo[n] * divide(kaijyo[n-k])) % MOD
def kaijyo(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * i)% MOD)
return ret
def solve():
n = getN()
nums = getList()
ref = [0,0,0]
ans = 1
for num in nums:
tmp = num
ref.sort()
if ref[0] == tmp:
if ref[0] == ref[1]:
if ref[0] == ref[2]:
ans *= 3
else:
ans *= 2
ref[0] += 1
elif ref[1] == tmp:
if ref[1] == ref[2]:
ans *= 2
ref[1] += 1
elif ref[2] == tmp:
ref[2] += 1
else:
print((0))
return
ans %= MOD
# print(ans)
print(ans)
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve() | 53 | 105 | 1,117 | 2,286 | import sys
# input = sys.stdin.buffer.readline
def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getlist():
return list(map(int, input().split()))
import heapq
import bisect
import copy
# import math
def warshall_floyd(d, N):
for k in range(N):
for i in range(N):
for j in range(N):
d[i * N + j] = min(d[i * N + j], d[i * N + k] + d[k * N + j])
return d
MOD = 10**9 + 7
def main():
n = getN()
nums = getlist()
ans = 1
bc, bv, bb = -1, -1, -1
for num in nums:
tmp = 0
added = 0
if num == bc + 1:
tmp += 1
if not added:
bc += 1
added = 1
if num == bv + 1:
tmp += 1
if not added:
bv += 1
added = 1
if num == bb + 1:
tmp += 1
if not added:
bb += 1
added = 1
ans *= tmp
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| import sys
from collections import defaultdict, deque, Counter
import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10**20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)
def era(n):
ret = [1 for i in range(n + 2)]
for i in range(2, int(math.sqrt(n) + 3)):
if ret[i] != 0:
for j in range(2, n // i + 1):
ret[i * j] = 0
rret = []
for i, r in enumerate(ret):
if r == 1 and i != 0:
rret.append(i)
return rret
def houjyo(n, m, k, kaijyo):
# kaburi ... k
# all ... n
if k == n:
return 1
else:
# kasanarierabi nck * nokorierabi (m - k)p(n-k) - houjyo(+1)
ret = nck(n, k, kaijyo) * npk(
m - k, n - k, kaijyo
) # - (k + 1) * houjyo(n, m, k+1, kaijyo)
# print(nck(n,k,kaijyo) , npk(m-k, n-k, kaijyo))
return ret % MOD
def nck(n, k, kaijyo):
return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
if k == 0 or k == n:
return n % MOD
return (kaijyo[n] * divide(kaijyo[n - k])) % MOD
def kaijyo(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * i) % MOD)
return ret
def solve():
n = getN()
nums = getList()
ref = [0, 0, 0]
ans = 1
for num in nums:
tmp = num
ref.sort()
if ref[0] == tmp:
if ref[0] == ref[1]:
if ref[0] == ref[2]:
ans *= 3
else:
ans *= 2
ref[0] += 1
elif ref[1] == tmp:
if ref[1] == ref[2]:
ans *= 2
ref[1] += 1
elif ref[2] == tmp:
ref[2] += 1
else:
print((0))
return
ans %= MOD
# print(ans)
print(ans)
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve()
| false | 49.52381 | [
"+from collections import defaultdict, deque, Counter",
"+import math",
"-# input = sys.stdin.buffer.readline",
"-def getN():",
"- return int(eval(input()))",
"+# import copy",
"+from bisect import bisect_left, bisect_right",
"+",
"+# import heapq",
"+# sys.setrecursionlimit(1000000)",
"+# input aliases",
"+input = sys.stdin.readline",
"+getS = lambda: input().strip()",
"+getN = lambda: int(eval(input()))",
"+getList = lambda: list(map(int, input().split()))",
"+getZList = lambda: [int(x) - 1 for x in input().split()]",
"+INF = 10**20",
"+MOD = 10**9 + 7",
"+divide = lambda x: pow(x, MOD - 2, MOD)",
"-def getNM():",
"- return list(map(int, input().split()))",
"+def era(n):",
"+ ret = [1 for i in range(n + 2)]",
"+ for i in range(2, int(math.sqrt(n) + 3)):",
"+ if ret[i] != 0:",
"+ for j in range(2, n // i + 1):",
"+ ret[i * j] = 0",
"+ rret = []",
"+ for i, r in enumerate(ret):",
"+ if r == 1 and i != 0:",
"+ rret.append(i)",
"+ return rret",
"-def getlist():",
"- return list(map(int, input().split()))",
"+def houjyo(n, m, k, kaijyo):",
"+ # kaburi ... k",
"+ # all ... n",
"+ if k == n:",
"+ return 1",
"+ else:",
"+ # kasanarierabi nck * nokorierabi (m - k)p(n-k) - houjyo(+1)",
"+ ret = nck(n, k, kaijyo) * npk(",
"+ m - k, n - k, kaijyo",
"+ ) # - (k + 1) * houjyo(n, m, k+1, kaijyo)",
"+ # print(nck(n,k,kaijyo) , npk(m-k, n-k, kaijyo))",
"+ return ret % MOD",
"-import heapq",
"-import bisect",
"-import copy",
"-",
"-# import math",
"-def warshall_floyd(d, N):",
"- for k in range(N):",
"- for i in range(N):",
"- for j in range(N):",
"- d[i * N + j] = min(d[i * N + j], d[i * N + k] + d[k * N + j])",
"- return d",
"+def nck(n, k, kaijyo):",
"+ return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD",
"-MOD = 10**9 + 7",
"+def npk(n, k, kaijyo):",
"+ if k == 0 or k == n:",
"+ return n % MOD",
"+ return (kaijyo[n] * divide(kaijyo[n - k])) % MOD",
"+",
"+",
"+def kaijyo(n):",
"+ ret = [1]",
"+ for i in range(1, n + 1):",
"+ ret.append((ret[-1] * i) % MOD)",
"+ return ret",
"+",
"+",
"+def solve():",
"+ n = getN()",
"+ nums = getList()",
"+ ref = [0, 0, 0]",
"+ ans = 1",
"+ for num in nums:",
"+ tmp = num",
"+ ref.sort()",
"+ if ref[0] == tmp:",
"+ if ref[0] == ref[1]:",
"+ if ref[0] == ref[2]:",
"+ ans *= 3",
"+ else:",
"+ ans *= 2",
"+ ref[0] += 1",
"+ elif ref[1] == tmp:",
"+ if ref[1] == ref[2]:",
"+ ans *= 2",
"+ ref[1] += 1",
"+ elif ref[2] == tmp:",
"+ ref[2] += 1",
"+ else:",
"+ print((0))",
"+ return",
"+ ans %= MOD",
"+ # print(ans)",
"+ print(ans)",
"- nums = getlist()",
"- ans = 1",
"- bc, bv, bb = -1, -1, -1",
"- for num in nums:",
"- tmp = 0",
"- added = 0",
"- if num == bc + 1:",
"- tmp += 1",
"- if not added:",
"- bc += 1",
"- added = 1",
"- if num == bv + 1:",
"- tmp += 1",
"- if not added:",
"- bv += 1",
"- added = 1",
"- if num == bb + 1:",
"- tmp += 1",
"- if not added:",
"- bb += 1",
"- added = 1",
"- ans *= tmp",
"- ans %= MOD",
"- print(ans)",
"+ for _ in range(n):",
"+ solve()",
"- main()",
"+ # main()",
"+ solve()"
] | false | 0.034991 | 0.035474 | 0.986377 | [
"s986339485",
"s870902994"
] |
u645250356 | p03387 | python | s422940188 | s467407660 | 182 | 48 | 38,764 | 5,504 | Accepted | Accepted | 73.63 | from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
a = inpl()
a.sort()
b = (a[1]-a[0]) // 2
c = a[2] - a[1]
if (a[1] - a[0]) % 2 == 0:
print((b + c))
else:
print((b + c + 2)) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,copy
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
x = inpl()
a,b,c = sorted(x)
n = c-a; m = c-b
res = n//2 + m//2
if n%2 != m%2:
res += 2
elif n%2 == 1 and n%2 == 1:
res += 1
print(res) | 17 | 18 | 526 | 472 | from collections import Counter, defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
a = inpl()
a.sort()
b = (a[1] - a[0]) // 2
c = a[2] - a[1]
if (a[1] - a[0]) % 2 == 0:
print((b + c))
else:
print((b + c + 2))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, copy
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
x = inpl()
a, b, c = sorted(x)
n = c - a
m = c - b
res = n // 2 + m // 2
if n % 2 != m % 2:
res += 2
elif n % 2 == 1 and n % 2 == 1:
res += 1
print(res)
| false | 5.555556 | [
"-import sys, heapq, bisect, math, itertools, string, queue",
"+from heapq import heappop, heappush, heapify",
"+import sys, bisect, math, itertools, fractions, copy",
"+INF = float(\"inf\")",
"-def inpl_str():",
"- return list(sys.stdin.readline().split())",
"-",
"-",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-a = inpl()",
"-a.sort()",
"-b = (a[1] - a[0]) // 2",
"-c = a[2] - a[1]",
"-if (a[1] - a[0]) % 2 == 0:",
"- print((b + c))",
"-else:",
"- print((b + c + 2))",
"+x = inpl()",
"+a, b, c = sorted(x)",
"+n = c - a",
"+m = c - b",
"+res = n // 2 + m // 2",
"+if n % 2 != m % 2:",
"+ res += 2",
"+elif n % 2 == 1 and n % 2 == 1:",
"+ res += 1",
"+print(res)"
] | false | 0.043192 | 0.0866 | 0.498746 | [
"s422940188",
"s467407660"
] |
u418149936 | p02819 | python | s265940766 | s929673919 | 46 | 42 | 9,112 | 9,180 | Accepted | Accepted | 8.7 | import math
X = int(eval(input()))
if X == 2:
print((2))
else:
is_find = False
while not is_find:
for i in range(2, X//2):
is_find = True
if math.gcd(X, i) != 1:
is_find = False
X += 1
break
rst = X
print(rst) | import math
X = int(eval(input()))
if X == 2:
print((2))
else:
is_end = False
while not is_end:
is_end = True
for i in range(1, X // 2):
if math.gcd(X, i) != 1:
is_end = False
X += 1
break
print(X) | 15 | 14 | 319 | 294 | import math
X = int(eval(input()))
if X == 2:
print((2))
else:
is_find = False
while not is_find:
for i in range(2, X // 2):
is_find = True
if math.gcd(X, i) != 1:
is_find = False
X += 1
break
rst = X
print(rst)
| import math
X = int(eval(input()))
if X == 2:
print((2))
else:
is_end = False
while not is_end:
is_end = True
for i in range(1, X // 2):
if math.gcd(X, i) != 1:
is_end = False
X += 1
break
print(X)
| false | 6.666667 | [
"- is_find = False",
"- while not is_find:",
"- for i in range(2, X // 2):",
"- is_find = True",
"+ is_end = False",
"+ while not is_end:",
"+ is_end = True",
"+ for i in range(1, X // 2):",
"- is_find = False",
"+ is_end = False",
"- rst = X",
"- print(rst)",
"+ print(X)"
] | false | 0.052756 | 0.040775 | 1.293845 | [
"s265940766",
"s929673919"
] |
u492910842 | p03416 | python | s729482166 | s448452185 | 83 | 74 | 67,868 | 67,768 | Accepted | Accepted | 10.84 | a,b = list(map(int,input().split()))
n = b - a + 1
count = 0
for i in range(n):
x = a + i
xx = list(str(x))
xx.reverse()
xx = int("".join(xx))
if x == xx:
count += 1
print(count) | a,b=input().split()
ans=0
for i in range(int(a),int(b)+1):
if str(i)==str(i)[::-1]:
ans+=1
print(ans) | 13 | 6 | 204 | 112 | a, b = list(map(int, input().split()))
n = b - a + 1
count = 0
for i in range(n):
x = a + i
xx = list(str(x))
xx.reverse()
xx = int("".join(xx))
if x == xx:
count += 1
print(count)
| a, b = input().split()
ans = 0
for i in range(int(a), int(b) + 1):
if str(i) == str(i)[::-1]:
ans += 1
print(ans)
| false | 53.846154 | [
"-a, b = list(map(int, input().split()))",
"-n = b - a + 1",
"-count = 0",
"-for i in range(n):",
"- x = a + i",
"- xx = list(str(x))",
"- xx.reverse()",
"- xx = int(\"\".join(xx))",
"- if x == xx:",
"- count += 1",
"-print(count)",
"+a, b = input().split()",
"+ans = 0",
"+for i in range(int(a), int(b) + 1):",
"+ if str(i) == str(i)[::-1]:",
"+ ans += 1",
"+print(ans)"
] | false | 0.131003 | 0.165208 | 0.792956 | [
"s729482166",
"s448452185"
] |
u498041957 | p02416 | python | s131568919 | s298562129 | 30 | 20 | 7,696 | 7,652 | Accepted | Accepted | 33.33 | while True:
data = eval(input())
if data[0] == '0':
break
print((sum([int(i) for i in data]))) | for str in iter(input, "0"):
print((sum(int(c) for c in str))) | 6 | 2 | 112 | 63 | while True:
data = eval(input())
if data[0] == "0":
break
print((sum([int(i) for i in data])))
| for str in iter(input, "0"):
print((sum(int(c) for c in str)))
| false | 66.666667 | [
"-while True:",
"- data = eval(input())",
"- if data[0] == \"0\":",
"- break",
"- print((sum([int(i) for i in data])))",
"+for str in iter(input, \"0\"):",
"+ print((sum(int(c) for c in str)))"
] | false | 0.049268 | 0.049507 | 0.995163 | [
"s131568919",
"s298562129"
] |
u025501820 | p03339 | python | s370138807 | s985185790 | 219 | 201 | 3,700 | 3,676 | Accepted | Accepted | 8.22 | N = int(eval(input()))
S = eval(input())
left = 0
right = S.count("E")
ans = False
for i in range(N):
if i > 0 and S[i - 1] == "W":
left += 1
if S[i] == "E":
right -= 1
if ans is not False:
ans = min(ans, left + right)
else:
ans = left + right
print(ans)
| N = int(eval(input()))
S = eval(input())
num = S[1:].count("E")
ans = num
for i in range(1, N):
if S[i - 1] == "W":
num += 1
if S[i] == "E":
num -= 1
ans = min(num, ans)
print(ans)
| 16 | 12 | 310 | 212 | N = int(eval(input()))
S = eval(input())
left = 0
right = S.count("E")
ans = False
for i in range(N):
if i > 0 and S[i - 1] == "W":
left += 1
if S[i] == "E":
right -= 1
if ans is not False:
ans = min(ans, left + right)
else:
ans = left + right
print(ans)
| N = int(eval(input()))
S = eval(input())
num = S[1:].count("E")
ans = num
for i in range(1, N):
if S[i - 1] == "W":
num += 1
if S[i] == "E":
num -= 1
ans = min(num, ans)
print(ans)
| false | 25 | [
"-left = 0",
"-right = S.count(\"E\")",
"-ans = False",
"-for i in range(N):",
"- if i > 0 and S[i - 1] == \"W\":",
"- left += 1",
"+num = S[1:].count(\"E\")",
"+ans = num",
"+for i in range(1, N):",
"+ if S[i - 1] == \"W\":",
"+ num += 1",
"- right -= 1",
"- if ans is not False:",
"- ans = min(ans, left + right)",
"- else:",
"- ans = left + right",
"+ num -= 1",
"+ ans = min(num, ans)"
] | false | 0.047324 | 0.050723 | 0.932984 | [
"s370138807",
"s985185790"
] |